Results 1 to 7 of 7

Thread: Reading data from text file

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    95

    Reading data from text file

    I need help, me and my friend are working on a simple game and we want it to load the character's info from the text file.

    for example:
    Private Sub Form_Load()
    CharName.Text = (Load from line 1 of text file)
    CharLevel.Text = (Load from line 2 of text file)
    If TextFile Doesn't Exist Then
    MsgBox "No character files could be loaded, you need to make a new character"
    End If
    End Sub


    and so on, also, I need to know how to save this data to a text file (for creating a new character)
    And I need it so if there's no such file, it will tell the user that he/she needs to create a character.

    Thanks,
    Kalo93

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Reading data from text file

    You may want to start in the FAQs section of the forums. Browse around and specifically play with the "Files" section.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    95

    Re: Reading data from text file

    None of them help >_>

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Reading data from text file

    None of them help? So you already know how to read and write a file?
    Then you may want to show us what you have so far and we can provide help on that.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    95

    Re: Reading data from text file

    None of them tell me how to read more than one line, all it's telling me is how to read the first line of the text file.
    I don't want that >_>

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Reading data from text file

    Quote Originally Posted by kalo93 View Post
    None of them tell me how to read more than one line, all it's telling me is how to read the first line of the text file.
    I don't want that >_>
    You may have not spent enough time in the FAQ section. Recommend looking specifically at "How to do basic manipulation of text files [Tutorial]", within the Files section of the FAQs.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    95

    Re: Reading data from text file

    I have this so far but it displays 10 in the charname

    vb Code:
    1. Private Sub Form_Load()
    2. Dim fileID As Long
    3. fileID = FreeFile()
    4. Open "char1.txt" For Input Lock Write As #fileID
    5. Dim line As String
    6. Do While (Not EOF(fileID))
    7. Line Input #fileID, line
    8. name1.Caption = line
    9. lvl1.Caption = line2
    10. Loop
    11. Close #fileID
    12. End Sub

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