Need help finding strings

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
mrfritz44
Newbie
Posts: 1
Joined: Mon Nov 21, 2005 10:37 am

Need help finding strings

Post by mrfritz44 »

I'm trying to analyze a file that represents a series of data records. Each record has 66 lines in it and I have to pull out certain data from within this 66 line block.

I basically need to say (for example), go to line 8, column 12, and read 17 characters. Assign that string a variable name and print it to another flat file. Then move onto the next field, and the next, etc. Once done with that record, move on to the next record until finished with each 66 line record.

Can anyone give me a hand with this?

Thanks,

Fred
Quibbler

Post by Quibbler »

I am assuming its not delimited (doesn't have return /LF at the end of each 66 character block). Look up how to use random access files. You will need to write B$ to a file I won't do everything for you!

Code: Select all

OPEN "r", #1, "c:\data3.dat"
i = 7
FIELD #1, 66 AS a$
WHILE EOF(1) = 0
i = i + 1
GET #1, i
b$ = MID$(a$, 12, 17)
PRINT b$
WEND
Antoni
Veteran
Posts: 132
Joined: Wed Jun 15, 2005 3:01 pm
Contact:

Post by Antoni »

He said each record had 66 LINES ....

Code: Select all

NRecordLines=66
Linetoread=8
ColToRead=12
Charstoread=17

open "MyData.txt" for input as #1
open "MyOutput.txt" for output as #2  
n=0
do
 n=n+1 
 for i=1 to NRecordlines
   line input #1,a$ 
   if i=linetoread then  print #2; n,mid$(a$,coltoread,charstoread)
 next
loop until eof(1)
close
Guest

Re: Need help finding strings

Post by Guest »

Anonymous wrote:
mrfritz44 wrote:I'm trying to analyze a file that represents a series of data records. Each record has 66 lines in it and I have to pull out certain data from within this 66 line block.

I basically need to say (for example), go to line 8, column 12, and read 17 characters. Assign that string a variable name and print it to another flat file. Then move onto the next field, and the next, etc. Once done with that record, move on to the next record until finished with each 66 line record.....
I'm having trouble with your specifications.
1) Does each record in the file contain 66 lines?

2) Are these lines fixed or variable length?

3) If the lines are fixed length, what is the length?

4) If they are variable in length then they must have some sort of delimiter. If they are variable, then what is the delimeter?

5) As per your example, "go to line 8, column 12, and read 17 characters." Let's call these "extract parameters" consisting of line, column, and number of characters. How many extract parameters apply to each record? What is the complete set of extract parameters?

6) You say "Assign that string a variable name and print it." What kind of "name" did you have in mind. If only for identifying the source of the output field, I suggest assigning a code like record number-line number-column number; i.e. RRRRR-LL-CCC.

7) Approximately how many records are in this file?

You have an interesting problem. Answer my questions and I'd be glad to help you.
*****
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

Please excuse me. :oops: Somehow I didn't get logged in correctly.

I wrote the above "guest" post having 7 questions.
*****
Last edited by moneo on Mon Nov 21, 2005 8:18 pm, edited 1 time in total.
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

moneo wrote:Please excuse me. :oops: Somehow I didn't get logged in correctly. As a result, I wrote the 2 "guest" posts above, please ignore the first one. The correct one has 7 questions.
*****
I removed the first post for you, to avoid missunderstandings/confusion, I hope that was ok?
I have left this dump.
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

Thanks, Z!re, nice to have you around to fix things --- among other contributions.
*****
Post Reply