RyanBank
asked on
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,2 0")
List1.AddItem FormatNumbers("1,12,0,1,20 0")
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,2 0")
List1.AddItem FormatNumbers("12,12,500,1 11,20")
List1.AddItem FormatNumbers("1,12,5,10,2 0")
End Sub
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,2
List1.AddItem FormatNumbers("1,12,0,1,20
List1.AddItem FormatNumbers("50,-4,2,-4,
List1.AddItem FormatNumbers("-5,-4,-2,50
List1.AddItem FormatNumbers("-5,-4,-2,-4
List1.AddItem FormatNumbers("1,1,-12,1,2
List1.AddItem FormatNumbers("12,12,500,1
List1.AddItem FormatNumbers("1,12,5,10,2
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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
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
For i = LBound(tmpAr) To UBound(tmpAr)
OutStr = OutStr & Right(Space(10) & tmpAr(i), 10)
If i <> UBound(tmpAr) Then OutStr = OutStr & ","
Next