RyanBank
asked on
compile bug
Hi,
Please assist what could be missing, when we run (F5) the code below, the alignment of the data in the listbox is perfect, sadly when we run the compile exe application, the results were different. the second element was tab way to far.
i.e.
1 2 3 4 5
5 6 5 4 3
Thanks.
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
Please assist what could be missing, when we run (F5) the code below, the alignment of the data in the listbox is perfect, sadly when we run the compile exe application, the results were different. the second element was tab way to far.
i.e.
1 2 3 4 5
5 6 5 4 3
Thanks.
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why don't you ditch the ListBox control in favour of a ListView control?
That way you'll have full control over the alignment, column widths etc. without using API calls.
Let me know if you'd like some sample code for setting it up.
Cheers
Bill