Tabbing the view in a Listbox

Discussion in 'AutoCAD' started by Kevin, Aug 26, 2004.

  1. Kevin

    Kevin Guest

    How do I get a line from a txt file to tab in the ListBox view?

    This is the line

    Input #nFile, sLayname, sDescptn, sLaycolor, sLayLtype

    The line from the file is:
    A-ANNO-DIMS,Dimensions,2,CONTINUOUS

    But I want it to display as:
    A-ANNO-DIMS Dimensions 2 CONTINUOUS

    I could do this with DCL by setting tabs but I'm new to VBA.

    Please help, desperately trying to learn.

    Kevin
     
    Kevin, Aug 26, 2004
    #1
  2. Kevin

    TomD Guest

    I'm far from a VBA expert, but I've done that type of thing with
    multi-column (property of the listbox) listboxes.

    In short, you build your data to an array, then pass it directly to the
    listbox, I think using the listbox.List property. If this makes no sense,
    let me know and I'll see if I can dig up an example.
     
    TomD, Aug 27, 2004
    #2
  3. Kevin

    Michel Guest

    Hi Kevin,

    Use the Replace-function:
    strReplaced = Replace("A-ANNO-DIMS,Dimensions,2,CONTINUOUS", ",", " ")

    Michel
     
    Michel, Aug 27, 2004
    #3
  4. Kevin

    Kevin Guest

    Tom, Thanks for the reply.

    Like I said I'm really starting to learn this stuff.
    If you have any examples of an array and columns I would greatly appreciate
    it.

    Thanks,
    Kevin
     
    Kevin, Aug 27, 2004
    #4
  5. Kevin

    Matt W Guest

    Assuming your test file will always have 4 entries per line (no more, no
    less), you can use this...

    Private Sub UserForm_Initialize()
    Dim fnum As Integer
    Dim file_line As String
    Dim Items

    ListBox1.Clear
    fnum = FreeFile
    Open "E:\Temp\Listbox.txt" For Input As fnum
    Do While Not EOF(fnum)
    Line Input #fnum, file_line
    Items = Split(file_line, ",", , vbTextCompare)
    ListBox1.AddItem Items(0) & vbTab & Items(1) & vbTab & Items(2) &
    vbTab & Items(3)
    Loop
    Close #fnum
    End Sub

    Another option would be to use a ListView control which allows for better
    control of the alignment of the columns.

    --
    Matt W

    The difference between genius and stupidity is that genius has its limits.

    | How do I get a line from a txt file to tab in the ListBox view?
    |
    | This is the line
    |
    | Input #nFile, sLayname, sDescptn, sLaycolor, sLayLtype
    |
    | The line from the file is:
    | A-ANNO-DIMS,Dimensions,2,CONTINUOUS
    |
    | But I want it to display as:
    | A-ANNO-DIMS Dimensions 2 CONTINUOUS
    |
    | I could do this with DCL by setting tabs but I'm new to VBA.
    |
    | Please help, desperately trying to learn.
    |
    | Kevin
    |
    |
     
    Matt W, Aug 27, 2004
    #5
  6. Kevin

    TomD Guest

    I'd have to defer to Matt, as I think his VBA skill are more advanced than
    my own.

    For the sake of finishing what I started, here are some snippets of my code:

    For iTmp = 0 To iCnt
    If Not Me.lbxSelected.Selected(iTmp) Then
    vNewSelLays(0, iNxt) = vSelLays(0, iTmp)
    vNewSelLays(1, iNxt) = vSelLays(1, iTmp)
    vNewSelLays(2, iNxt) = vSelLays(2, iTmp)
    iNxt = iNxt + 1
    End If
    Next
    vSelLays() = vNewSelLays()

    The abover portion is where my array is built, just to illustrate that it's
    a multi-dimensonal array.

    Private Sub UpdateSelectedLayouts()
    Me.lbxSelected.Column() = vSelLays()
    End Sub

    This part sends the array to the ListBox. I prefer building the array and
    passing it to the Column property, as shown here, mainly for the sake of my
    own sanity. Matt's example is quite possibly *better*, though I couldn't
    make a case either way.
     
    TomD, Aug 27, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.