Solved

# aligning listbox data

Posted on 2006-05-24
210 Views
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()
End Sub
0
Question by:RyanBank

LVL 3

Expert Comment

For i = LBound(tmpAr) To UBound(tmpAr)
OutStr = OutStr & Right(Space(10) & tmpAr(i), 10)
If i <> UBound(tmpAr) Then OutStr = OutStr & ","
Next
0

LVL 17

Accepted Solution

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
'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
End Sub
0

Author Comment

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

LVL 17

Expert Comment

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

### Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…