Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

aligning listbox data

Hi,

Please assist how can we align properly when negative values are present.

Thanks.


Private Function FormatNumbers(iNumbers As String) As String
Dim tmpAr() As String
Dim OutStr As String
tmpAr = Split(iNumbers, ",")

For i = LBound(tmpAr) To UBound(tmpAr)
    OutStr = OutStr & "   " & String((3 - Len(tmpAr(i))) * 2, " ") & tmpAr(i) & "   "
    If i <> UBound(tmpAr) Then OutStr = OutStr & ","
Next
FormatNumbers = OutStr
End Function

Private Sub Command1_Click()
List1.AddItem FormatNumbers("1,12,50,1,20")
List1.AddItem FormatNumbers("1,12,0,1,200")
List1.AddItem FormatNumbers("50,-4,2,-4,-3")
List1.AddItem FormatNumbers("-5,-4,-2,50,-3")
List1.AddItem FormatNumbers("-5,-4,-2,-4,3")
List1.AddItem FormatNumbers("1,1,-12,1,20")
List1.AddItem FormatNumbers("12,12,500,111,20")
List1.AddItem FormatNumbers("1,12,5,10,20")
End Sub
0
RyanBank
Asked:
RyanBank
  • 2
1 Solution
 
fullcontactCommented:
try this in your function

For i = LBound(tmpAr) To UBound(tmpAr)
    OutStr = OutStr & Right(Space(10) & tmpAr(i), 10)
    If i <> UBound(tmpAr) Then OutStr = OutStr & ","
Next
0
 
zzzzzoocCommented:
Have you tried my suggestion from the previous question? This is a simplified version.

Form1:
---------------
Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const LB_SETTABSTOPS = &H192
Private Sub Form_Load()
    'change the values below to change the tabstop positions
    Call ListInit(List1, 30, 60, 90, 120, 150)
End Sub
Private Sub Command1_Click()
    Call ListAdd(List1, 1, 12, 50, 1, 20)
    Call ListAdd(List1, -5, -4, -2, 50, -3)
    Call ListAdd(List1, 12, 12, 500, 111, 20)
End Sub
Private Sub ListInit(ByRef lst As ListBox, ParamArray tabs() As Variant)
    Call SendMessage(lst.hWnd, LB_SETTABSTOPS, (UBound(tabs) - 1), tabs(0))
End Sub
Private Sub ListAdd(ByRef lst As ListBox, ParamArray vals() As Variant)
    Dim temp As String
    Dim i As Integer
    For i = LBound(vals) To UBound(vals)
        If (i = LBound(vals)) Then
            temp = vals(i)
        Else
            temp = temp & vbTab & vals(i)
        End If
    Next
    Call lst.AddItem(temp)
End Sub
0
 
RyanBankAuthor Commented:
zzzzzooc,

I found an interesting bug that sadly I'm not sure how to fix, the code works perfectly when run, but when you compile it and run the exe it will tab so far for the first element. Please assist what could have happend


i.e.

1                         2 3 4 5
4                         4 5 6 7

Thanks.
0
 
zzzzzoocCommented:
I can't reproduce that behavior.

You can try adjusting the tabstop positions at:
Call ListInit(List1, 30, 60, 90, 120, 150)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listboxes/listboxreference/listboxmessages/lb_settabstops.asp

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now