String Search

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
Dinosaur

String Search

Post by Dinosaur »

Hi all

I am reading the Map file created after linking a project to identify the
error
line within a module.

Can somebody enlighten me as to why I cant find a string in another string
when I know that the string is there. (for example 0416:01A9)
I have done all the usual removal of spaces , printed the string to confirm
that the string was in fact retrieved from the file etc.
This is a code snippet.


'First find the file length
MF = FREEFILE
OPEN "Module02.MAP" FOR input AS #MF
FLEN = LOF(MF)
CLOSE #MF

'Next make a blank string equal to the length of the file.
A$ = STRING$(FLEN," ")

'Now get the whole string from the file.
OPEN "Module02.MAP" FOR RANDOM AS #MF LEN = FLEN
GET #MF,,A$
Close #MF

REC = INSTR(A$,Address$)
IF REC > 0 THEN
blah

blah

Regards
Dinasaur
Guest

Post by Guest »

Hi Dinosaur,

The problem comes from the second Open statement, when opening a file for random like you do here, it is expected to have a type, a fixed length. and data is somehow encrypted (binarized?) into the file. so when you get your string after teh 2nd open, the data is not plain text.

You might want to try opening the file as binary instead of random. And reading it that way.

Hope this helps.
Dinosaur

String Search

Post by Dinosaur »

Thanks for that,

Interesting that when you print the contents of the filled string to the screen, it all looks normal.
But opening AS Binary solves that.

Thanks again
Dinosaur
Post Reply