Results 1 to 4 of 4

Thread: [2005] Search and Retrive Text File

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2006
    Posts
    293

    Post [2005] Search and Retrive Text File

    Hi.

    I have a text file that looks like this. Each one on its own line

    88087761 - Box 1
    88087762 - Box 2
    88087763 - Box 3
    ...
    Etc.

    The Numbers are barcodes and the "box 1" is the description of what is inside that box.

    On my form i have a Text box, a button and list box

    my objective is to have the barcode number(88087761 etc) inputed in the text box and when the user clicks the button it brings up the description for that box in a listbox. i have looked around and can't really find anything on searching a text file and getting a line back into the form.. any help would be grateful.

    thanks

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: [2005] Search and Retrive Text File

    why use a listbox for the description?
    there are more versatile, better suited controls

  3. #3
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Search and Retrive Text File

    Storing the information like this is far from the best approach. Why not use a database? I dont see a reason to it this way, unless its some kind of school assignment.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4
    Frenzied Member Icyculyr's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    1,934

    Re: [2005] Search and Retrive Text File

    If I read the question right, it's fairly simple.
    The code below should be combined.

    vb.net Code:
    1. Dim iRetrieveLine As Integer = 0 'Line 0
    2. Dim iTempInteger As Integer = 0
    3. Dim sLine As String = ""
    4. Using sr As New StreamReader("PathToFile")
    5.     Do Until 0 > 1 'Yea I know, never ending...
    6.         If iTempInteger-1 = iRetrieveLine The
    7.            sLine = sr.ReadLine()
    8.            iTempInteger += 1
    9.            Exit Do
    10.         Else
    11.             sr.ReadLine()
    12.         End If
    13.     Loop
    14. End Using

    So now the text you want is in sLine,
    Now we format that text,
    So if the bar codes are stored as this:

    9401151 Box1 Description is here

    vb.net Code:
    1. Dim sSub As String = ""
    2. Dim sBarcode As String = ""
    3. iTempInteger = 0
    4. Do Until sSub = " "
    5.     sSub = sLine.Substring(iTempInteger, 1)
    6.     sBarcode &= sSub
    7.     iTempInteger += 1
    8. Loop

    now if you want the description too, do this:

    vb.net Code:
    1. sSub = " "
    2. Dim s
    3. iTempInteger = 0
    4. Do Until sSub = ""
    5.     sSub = sLine.Substring(iTempInteger, 1)
    6.     sBarcode &= sSub
    7.     iTempInteger += 1
    8. Loop

    That might work, but im not sure, I haven't tested it.
    Cheers

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