"Kin®sole" <ki******@NOSPAMhotmail.com> wrote in message
news:23******************************@news.teranew s.com...
Hi
I am trying to add two variables to a list box and keep everything in
line.I get the result below
Gaz £2000
Jimmy £3000
fred £4000
but would like to get this result
Gaz £2000
Jimmy £3000
fred £4000
I am using to courier font so the letter are equally spaced but don't know
how to format the spaces to take into account the different length of the
variables
Well, you have to first determine the widest acceptable size. Once this is
done, you can create a simple function such as this (this is one of the many
ways):
Function allign2Vars(v1$, v2$, colWidth)
Dim vw
vw = Len(v1$) + Len(v2$)
' trap for too small of a size
If ((colWidth \ 2) - Len(v1$)) < 1 Then
allign2Vars = v1$ & v2$
Else
allign2Vars = v1$ & String(colWidth \ 2 - Len(v1$), 32) & v2$
End If
End Function
To use it, simply pass the two vars and the limit width. Assuming you want
to not exceed 20 characters width:
a$ = "Jim": b$ = "Smith"
c$ = allign2Vars(a$, b$, 20)
List1.AddItem c$
a$ = "Susan": b$ = "Young"
c$ = allign2Vars(a$, b$, 20)
List1.AddItem c$