[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
Re: [2005] Search and Retrive Text File
why use a listbox for the description?
there are more versatile, better suited controls
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.
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:
Dim iRetrieveLine As Integer = 0 'Line 0
Dim iTempInteger As Integer = 0
Dim sLine As String = ""
Using sr As New StreamReader("PathToFile")
Do Until 0 > 1 'Yea I know, never ending...
If iTempInteger-1 = iRetrieveLine The
sLine = sr.ReadLine()
iTempInteger += 1
Exit Do
Else
sr.ReadLine()
End If
Loop
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:
Dim sSub As String = ""
Dim sBarcode As String = ""
iTempInteger = 0
Do Until sSub = " "
sSub = sLine.Substring(iTempInteger, 1)
sBarcode &= sSub
iTempInteger += 1
Loop
now if you want the description too, do this:
vb.net Code:
sSub = " "
Dim s
iTempInteger = 0
Do Until sSub = ""
sSub = sLine.Substring(iTempInteger, 1)
sBarcode &= sSub
iTempInteger += 1
Loop
That might work, but im not sure, I haven't tested it.
Cheers