Results 1 to 8 of 8

Thread: Simple question about text files [RESOLVED... finally..]

  1. #1

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Question Simple question about text files [RESOLVED... finally..]

    Fairly simple concept here: I have a text file with lots of **** written in it. 9 pages worth of data to describe 120 items, basically. So, how do I get VB to search for a particular line of text? I seem to be remembering something about a SearchLine command, but I'm not sure. Any help would be an awesome use in the making of a great game!!!
    Last edited by timeshifter; Apr 22nd, 2004 at 03:12 PM.

  2. #2
    Hyperactive Member kayos's Avatar
    Join Date
    Apr 2004
    Location
    Largo, Florida
    Posts
    306
    Here goes nothing man.
    VB Code:
    1. Set FSO = CreateObject("Scripting.FileSystemObject")
    2. Set fl = FSO.OpenTextFile(FilePath & "\" FileName, 1, False)
    3. While Not fl.AtEndOfStream
    4.      ContentsOfLine = fl.ReadLine
    5. Wend
    That should grab your file line by line


    If this post helps, please RATE MY POST!

    Using Visual Studio 2005 SE

  3. #3

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    Okay, let me define what I need a little better. I have this massive text file filled with numbers, kinda like an ini file, except the program only goes to it when it needs a value. I need it to search for something, say [Bronze] and then it'll read the values from that point for two lines, getting the values it needs. How does that work out

  4. #4
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Not sure why you want to start a new thread when all the information is already in your other one

    http://www.vbforums.com/showthread.p...hreadid=287252

    The problem is the way you are designing your .txt file. You are making it hard to retrieve the data you are searching for. Fix that problem and make your life easy.

  5. #5
    Addicted Member
    Join Date
    Jun 2002
    Posts
    211
    I agree with Brianz
    if that is not for you though, you could always pull the file into a richtext box and search that.
    Not so fast, but the larger the file, the richtext solution should start to make more sence.

    Simon

  6. #6

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    Are you saying that I should just have the target text, say [Bronze], and have only the values in the lines afterwords, with no describing text??

  7. #7

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Final Question

    I've opened the completed text file, and I know exactly where to look to get the information I need. Now, could someone please tell me how to have VB search the open text file for a string????

  8. #8

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    Problem finally solved, took me forever to figure it out, but here it is...

    VB Code:
    1. Private Sub txtEnemyName_KeyPress(KeyAscii As Integer)
    2.  
    3.     Dim temp As String
    4.  
    5.     If KeyAscii = 13 Then
    6.  
    7.         Open "S:/2005/205508/Text Documents/Crusader.sta.txt" For Input As #1
    8.             Do
    9.                 Line Input #1, temp
    10.             Loop Until temp = "[" & txtEnemyName.Text & "]"
    11.            
    12.             Line Input #1, temp
    13.             lblStrengthLevel = temp
    14.            
    15.             Line Input #1, temp
    16.             lblRangedLevel = temp
    17.            
    18.             Line Input #1, temp
    19.             lblMagicLevel = temp
    20.            
    21.             Line Input #1, temp
    22.             lblDefenseLevel = temp
    23.            
    24.             Line Input #1, temp
    25.             lblHP = temp
    26.  
    27.         Close 1
    28.     End If
    29.  
    30. End Sub

    I settled for just making the text file have the enemy name and then the numbers, no descriptions. It would appear to work better...

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