|
-
Oct 16th, 2005, 09:15 AM
#1
Thread Starter
Junior Member
Extracting from then to writing .txt
Hi,
I aim to do this in an Access 97 form as I dont have access to VB6.
Anyway, I would like some tips on how to extract info from a text file and write it to another.
I am aware of how to open,read and then write to a text file but I am unsure how I pick out the position of the info i want.
here we go...
I require to extract a ten digit number from a text file which occurs on the 5th line of every section and is five spaces in from the left margin.
example of text file:
customer 1
blah blah
blah blah
blah blah
blah:177690303 (this is the number i need)
blah blah
blah blah
blah blah
blah blah
customer 2
blah blah
blah blah
blah blah
blah:897690302 (this is the number i need)
blah blah
blah blah
blah blah
blah blah
customer 3
blah blah
blah blah
blah blah
blah:3857690334 (this is the number i need)
blah blah
blah blah
blah blah
blah blah
On the whole the positioning of the numbers stays static but if it didnt is there a way of searching for a cluster of ten numbers and extracting those?
Once extracted I then would like to save the info to another text file as tab delimited.
Any thoughts guys?
-
Oct 16th, 2005, 02:56 PM
#2
Re: Extracting from then to writing .txt
Open file.
Use SEEK to locate your record
read it into a variable
Open another file
write to other file.
Or else read the whole file into a variable and use string opreations to locate the info you want.
Pradeep
-
Oct 17th, 2005, 06:41 AM
#3
Re: Extracting from then to writing .txt
Access VBA question moved to Office Development.
-
Oct 17th, 2005, 07:49 AM
#4
Re: Extracting from then to writing .txt
I'm guessing that these are normal text files, therefore the SEEK method will return the byte position and not the text as in the Random access files..
If the position will never change then the best method would be to read in the first four lines and then concentrate on the 5th..
VB Code:
Dim strIn As String
Dim FFile As Integer
Dim i As Long
FFile = Freefile
Open "MyFile.txt" For Input As #FFile
For i = 1 to 4
Line Input #FFile, strIn
Next
'concentrate on the next line..
Line Input #FFile, strIn
'Close file as no longer needed
Close #FFile
strIn = Mid(strIn,5,10)
msgbox strIn
If however these files may change in the future then address the source of this information and request a special character around the number so it can be picked up no matter where it is placed, something like | or ¬.
Danny
Never Think Impossible
If you find my answer helpful then please add to my reputation
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
|