Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seek certain data in a file, and compare.... 1

Status
Not open for further replies.

BuddyWeiser

Programmer
Oct 20, 2003
5
US
I have a file, in which each statement reads something like:
"texthere ##-##-##-##-##-## texthere texthere ##-##-####"

What I want to do is search the file, line by line, for ##-##-##-##-##-##, each ## individualy, and have it count how many times all the different ##'s appeared, whatever their value.

I've seen the REMLINE program that comes with QBasic, and, I understand that, in that program you can say... type in a ## and it would remove that ## from the file, anywhere it may be. Instead of removing the number though, I would rather have it count how many instances of that number it finds, but, it has to search the file for 01 through 53 via a loop statement with for n% = 01 to 53...


Anyone have any ideas?

Thanks in advance, for the huge help.
 
Try this:
This is what I gather you're looking for.
This will count how many times 'bb' appears in the text string.

'---start---
test$ = "abbababbabbabbbabababbababbabbababba"
FOR i = 1 to LEN(test$)
IF MID$(test$,i,2) = "bb" then: count = count + 1
NEXT
PRINT test$
PRINT "'bb' appeared"; count; "times."
'---stop---

What that does, is it searches through the "test$" string and searches for the double letter 'bb'.
In the above example, the FOR loop is the same as:
FOR i = 1 to 36
This is because LEN(test$) = 36. (There are 36 characters in test$...at least in this example.)
Then MID$(test$,i,2), what that does, is MID$ searches test$, goes to the 'i'th character over. And searches 2 letters at a time. You can make that 1 or 3 or 4 or whatever you want. (If you want to search 4 at a time.)

Hopefully this helps and you can figure out how to modify it to fit your particular program.

Good luck!
 
Wow! This is nearly exactly what I was looking for.

I'm glad someone out there knew what I was trying to say heh.


Thanks for the tips, I think I have the idea in my head on how this will work.

Say, for the code you gave me, I could use the Record Statement to fetch the entire text string for that record position, and then have it search it, then go to the next record entry and do it all over again till EOF, then have loop 53 times so it searches from BOF to EOF for the numbers 01 - 53 and count it, using same count variable but
having if then else statements to have the count variable = a string for each individula search parameter, i.e 01-53.

Woops... rambling on again heh. Least i've got the gears turning again LOL. Thanks for the tips.

BIG help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top