|
-
Sep 20th, 2007, 04:13 PM
#1
Thread Starter
Junior Member
Read Text File
Good Day Everyone,
I need a little help with coding a loop.
I have a page that read a txt file, the file looks like this:
HDR#############SOME TEXT GOES HERE############
DTL#############SOME TEXT GOES HERE############
DTL#############SOME TEXT GOES HERE############
DTL#############SOME TEXT GOES HERE############
HDR#############SOME TEXT GOES HERE############
DTL#############SOME TEXT GOES HERE############
HDR#############SOME TEXT GOES HERE############
DTL#############SOME TEXT GOES HERE############
DTL#############SOME TEXT GOES HERE############
The initial code was made to read only for 1 Header ans as many details as the text file had, but now the file contains variable quantity of HDRs and DTLs.
How can i code a loop and output as separate readings for every HDR,
Ex.
HDR #1
DTL
DTL
DTL
HDR #2
DTL
HDR#3
DTL
DTL
This it's to later update a MS Acces table.
Thanks in advance for your help.
Leo
-
Sep 22nd, 2007, 08:36 AM
#2
Re: Read Text File
vb Code:
Set FS = CreateObject("Scripting.FileSystemObject")
Set f1 = fs.OpenTextFile("C:\Documents and Settings\peter\My Documents\basic\vbs\myhdrfile.txt", 1, False)
mystr = f1.ReadAll
f1.close
wscript.echo mystr
myarr = split(mystr, "HDR")
for i = 1 to ubound(myarr)
msgbox myarr(i)
next
this will add all the file into an array, each element starts with the HDR number followed by the data
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|