Results 1 to 9 of 9

Thread: Displaying listbox items in text1.text

  1. #1

    Thread Starter
    Hyperactive Member Animelion's Avatar
    Join Date
    Jan 2001
    Location
    Jacksonville NC
    Posts
    283

    Displaying listbox items in text1.text

    How can I make it so a user selects a directory, and then all images in that directory that are .gif, .jpeg, .jpg, and .bmp are then added to a list box.

    In the listbox I want the full directory paths of the files, not just the name of them.

    Thanks for any help anyone can give
    Last edited by Animelion; May 19th, 2002 at 05:33 PM.
    ~ Animelion

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    sample for u

    VB Code:
    1. Private Sub Command3_Click()
    2.     Dim sFile As String
    3.     Dim s As String
    4.     Dim sPath As String
    5.     Dim sArr() As String
    6.     Dim i As Integer
    7.    
    8.     sPath = "C:\TEST\"
    9.    
    10.     sFile = Dir(sPath & "*.bmp")
    11.     Do While sFile <> ""
    12.         s = s & sPath & sFile & vbCrLf
    13.         sFile = Dir
    14.     Loop
    15.    
    16.     sFile = Dir(sPath & "*.jpg")
    17.     Do While sFile <> ""
    18.         s = s & sPath & sFile & vbCrLf
    19.         sFile = Dir
    20.     Loop
    21.    
    22.     sFile = Dir(sPath & "*.gif")
    23.     Do While sFile <> ""
    24.         s = s & sPath & sFile & vbCrLf
    25.         sFile = Dir
    26.     Loop
    27.    
    28.     'get all the files found into an array
    29.     sArr = Split(s, vbCrLf)
    30.    
    31.     'fill the listbox
    32.     List1.Clear
    33.     For i = 0 To UBound(sArr())
    34.         List1.AddItem sArr(i)
    35.     Next i
    36. End Sub
    -= a peet post =-

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    a bit more "sexy"

    VB Code:
    1. Private Sub Command3_Click()
    2.     Dim sFile As String
    3.     Dim s As String
    4.     Dim sPath As String
    5.     Dim sArr() As String
    6.     Dim sFileMasks(4) As String
    7.     Dim i As Integer
    8.    
    9.     sFileMasks(0) = "*.BMP"
    10.     sFileMasks(1) = "*.JPG"
    11.     sFileMasks(2) = "*.TIF"
    12.     sFileMasks(3) = "*.JPEG"
    13.     sFileMasks(4) = "*.GIF"
    14.    
    15.     sPath = "C:\TEST\"
    16.    
    17.     For i = 0 To UBound(sFileMasks())
    18.         sFile = Dir(sPath & sFileMasks(i))
    19.         Do While sFile <> ""
    20.             s = s & sPath & sFile & vbCrLf
    21.             sFile = Dir
    22.         Loop
    23.     Next i
    24.        
    25.     'get all the files found into an array
    26.     sArr = Split(s, vbCrLf)
    27.    
    28.     'fill the listbox
    29.     List1.Clear
    30.     For i = 0 To UBound(sArr())
    31.         List1.AddItem sArr(i)
    32.     Next i
    33. End Sub
    -= a peet post =-

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    from the other post, I take it u want to use the FSO instead ?
    -= a peet post =-

  5. #5

    Thread Starter
    Hyperactive Member Animelion's Avatar
    Join Date
    Jan 2001
    Location
    Jacksonville NC
    Posts
    283

    :)

    New question, same basis.

    If I have a File List Box what code do i need to have so that a user can click a button and all files selected will be added to a listbox ?

    It is kinda like before, but I can't figure out howto adapt it.
    Thanks for any help anyone gives
    ~ Animelion

  6. #6
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    huh ... so u found the FileListBox then did u ??
    -= a peet post =-

  7. #7
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Private Sub Command4_Click()
    2.     Dim i As Integer
    3.     For i = 0 To File1.ListCount - 1
    4.         If File1.Selected(i) Then List1.AddItem File1.FileName
    5.     Next i
    6. End Sub
    -= a peet post =-

  8. #8

    Thread Starter
    Hyperactive Member Animelion's Avatar
    Join Date
    Jan 2001
    Location
    Jacksonville NC
    Posts
    283

    Another Q :)

    Ok ok, 1 more for now

    If I have a list box filled with lets say 10 items

    How can I scroll thru the listbox and have the 1st item diplayed in text1.text, then have the second item displayed in text1.text, and so on, all the way till all the items in the listbox have been displayed.

    Thanks for any help anyone can provide.
    ~ Animelion

  9. #9
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim i As Integer
    3.     Text1.Text = ""
    4.     For i = 0 To List1.ListCount - 1
    5.         Text1.Text = Text1.Text & List1.List(i) & vbCrLf
    6.     Next i
    7. End Sub
    -= a peet post =-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width