Reading text files

  • Thread starter Thread starter jonathandrott
  • Start date Start date
J

jonathandrott

I'm trying to read specific information from a text file. I need to
get stuff like invoice date, invoice number and account number
(9/18/06, 586007, 1543 respectively) i was able to use a stream reader
to display the text in a textbox for viewing, but i want to pick these
items out. I don't even know where to start.





EW1 .FW0 Invoice Date 9/18/06
Invoice No. 586007

PO#
RTL#2650000023
-1
-0
Ship-To |Bill-To
|Acct#- Rte Slm#
TO | CHARGE| 1543 0 1
| |ent: ees pck: SP
| |Driver Collect:
| |
0.00
-1
-0
Qty SUM ------------Description----------------Stock-#--- Itm -Price--
---Total---
 
Dear Mr. Drott,

The procedure would be like this:

1. Declare some string variable (e.g. x As String, InvoiceDate As
String, ...)
2. Declare 3 integer variable (e.g. posi As Integer, t As Integer,
StartData As Integer)
3. Open the file
4. Read file into a string variable
x = sr.ReadToEnd()

5. Get the position of invoice date
posi = Instr(x.ToUpper,"INVOICE DATE")

6. Go to the actual start of the date.
If posi is greater than 0 the string was found.
Then add the length of the string (12 characters)
to the position to start right after it and search for the number.
If posi>0 Then
posi=posi+12
For t = posi To x.Length
If Strings.Mid(x,t,1)<>" " Then
StartData = t
Exit For
End If
Next
End If

7. Go to the end of the date
For t = StartData To x.Length
If Strings.Mid(x,t,1)=" " then
InvoiceString = Strings.Mid(x,StartData,t-StartData)
Exit For
End If
Next

Best Regards,

HKSHK
 
thanks for all the info. let me cruch some of this and see if i can
get it working. thanks again.
 
i'm sorry this is a first for me. (not quite understanding everything)
is the code below correct? how can i output the date to a lable to
test if it worked? lblTest.text = InvoiceDate?

'Try to read in the Invoice Date
Dim InvoiceDate, x As String
Dim posi, t, StartData As Integer
myReader = New IO.StreamReader(txtReadFile.Text)
x = myReader.ReadToEnd
posi = InStr(x.ToUpper, "INVOICE DATE")
If posi > 0 Then
posi = posi + 12
For t = posi To x.Length
If Strings.Mid(x, t, 1) <> "" Then
StartData = t
Exit For
End If
Next
End If
For t = StartData To x.Length
If Strings.Mid(x, t, 1) = "" Then
InvoiceDate = Strings.Mid(x, StartData, t - StartData)

Exit For
End If
Next
 
Back
Top