Retrieving information from files

Discussion in 'Visual Basic ( VB )' started by hnaya, Dec 17, 2008.

  1. hnaya

    hnaya New Member

    Joined:
    Nov 29, 2008
    Messages:
    9
    Likes Received:
    3
    Trophy Points:
    0
    hi
    i have this code which retrive the information from file
    by write on text1
    and the information show in text 2 and text 3 and text 4


    Code:
     
    Private Sub Text1_Change()
    On Error Resume Next
    Dim f As String
    f = App.Path
    If Right(f, 1) <> "\" Then f = f + "\"
    f = f + Text1.Text
    Dim X, Y, z As String
    Open f For Input As #5
    Input #5, X, Y, z
    Text2.Text = X
    Text3.Text = Y
    Text4.Text = z
    Close #5
    End Sub
     
    

    how can i retrieve the information all files and show it in listbox
     
  2. Keithuk

    Keithuk New Member

    Joined:
    Jun 1, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Senior Motor Vehicle Technician
    Location:
    Staffordshire, England
    Home Page:
    http://www.martin2k.co.uk/forums/index.php
    It depends what the user is entering in Text1 as the filename. You may as well use a CommonDialog control or DriveListBox, DirListBox and a FileListBox.

    You are also dimensioning your variables wrong.
    Just because you add As String at the end don't assume that they will all be Strings. Only z with be a string X and Y with be Variants

    Dim X As String, Y As String, z As String

    Do you want to use 1 ListBox or 3?

    Open f For Input As #5
    Input #5, X, Y, z
    List1.AddItem X
    List2.AddItem Y
    List3.AddItem z
    Close #5

    As a general rule when you add Strings f = f + Text1.Text you use f = f & Text1.Text

    Avoid using On Error Resume Next if an error occurs then you won't spot it. Just rem it out while you are testing.

    So which part isn't working as it should? ;)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice