On Thu, 16 Oct 2003 09:19:33 +0100, "Brian Basquille"
<tb********@eircom.netSPAM> wrote:
Hello all,
I'll get to the point. Does anyone know how i go about arranging text in a
list box?
I am loading a name and number into a listbox from an array, using code
snippet below:
For s = 1 To amtOfRecords
lstSorted.AddItem (numArray(s) & " " &
nameArray(s))
Next s
I have used the series of spaces in between to seperate the name & number.
But the number field all seem out-of-line when they're printed into the
ListBox.
Can anyone help me fix this for them to be aligned?
Option Explicit
' Add one Listbox
' Add one command button
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
' ################################################## ###
'
' TabWidth(0) = Number of Tabs
' TabWidth(1 to n) = Width of Each Field in Bytes
'
Sub SetTabWidths(TabWidth() As Long)
Dim Max&, L9%
If TabWidth(0) < 1 Or TabWidth(0) > UBound(TabWidth) Then
MsgBox ("EPL - Bad TabWidth(0) in SetTabWidths")
End If
Max = TabWidth(0)
ReDim Q&(Max + 1)
For L9 = 1 To Max
Q(L9) = TabWidth(L9) * 4 ' 4 Dialog Units Per Char
Q(L9) = Q(L9 - 1) + Q(L9)
Next
Call SendMessage(List1.hWnd, LB_SETTABSTOPS, Max, Q&(1))
End Sub
Private Sub Command1_Click()
Dim L9, Q&(2)
For L9 = 1 To 20
List1.AddItem Str$(L9) + vbTab _
+ Str$(L9) + "a" + vbTab _
+ "Col3"
Next
Q(0) = 2 ' 1st Column is zero offset
Q(1) = 10
Q(2) = 10
Call Me.SetTabWidths(Q())
End Sub