Link to home
Start Free TrialLog in
Avatar of RyanBank
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,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
Avatar of fullcontact
fullcontact

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
ASKER CERTIFIED SOLUTION
Avatar of zzzzzooc
zzzzzooc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RyanBank

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 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