is it possible to apply this kind of alignment in vb6 listbox?


aaa     bbfawdawd
bbbb    adwadwa
cc      dawdawda

if it is possible. Please specify the solution. thank you

Edited 4 Months Ago by jeffersonalomia

There are components that do this (try a search engine), or you could try and write it yourself, but the better solution would be to use a ListView instead.

I started to build the application using listbox, and it is almost finish. Is it possible to align that using a space() function and use the difference of array1(0) length to array1(1) length?

len(array1(0)) = 10
len(array1(1)) = 5

10 - 5

lbx.additem wdawdawd & space(5) & dawdawdaw
lbx.additem dwadaw & space(5) & dwadwad

Edited 4 Months Ago by jeffersonalomia

Yes, that is possible, but only if you use a fixed width font.

Just create a formatted string for each line you add.

That's it. "Fixed width font"

I am confuse on constructing. Once ive try that, the output doesnt goes to what i wanted to. How do i implement that in vb6


Edited 4 Months Ago by jeffersonalomia

Public Sub display_records()
        Dim db_rec() As String
        Dim l1, l2, diff As Integer
        Set rs = cn.Execute(sql)
        i = 0
        Do While Not rs.EOF
            ReDim Preserve db_rec(i + 1)
            db_rec(i) = rs("TRIGGER_NAME")
            i = i + 1
            For j = 0 To i - 1
                l1 = Len(db_rec(j))
                l2 = Len(db_rec(j + 1))
                If l1 > l2 Then
                    diff = l1 - l2
                End If
                If l2 > l1 Then
                    diff = l2 - l1
                End If
       Form7.lst_prompt.AddItem db_rec(j) & Space(diff + 30) & txt_trigger_val(j)
        Next j
`End Sub`

Its properly much easier to work from the lefthand side of the list. You just roughly know the max length of the first string, give some space and add the second. so if x is the length of the max length string ,say 12, you do space(-x+15) & next string. This will place the second string always at pos 15,regardless of the length of the first string.
`Private Sub Form_Load()
Dim str1 As String
Dim str2 As String
Dim x As Integer
Dim x1 As Integer

str1 = "abc"
str2 = "abcdef"
x = Len(str1)
x1 = Len(str2)
List1.AddItem (str1) & Space(-x + 15) & (str1)
List1.AddItem (str2) & Space(-x1 + 15) & (str2)
End Sub Linup.jpg `