searching a file for specific data

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
Agent_Firestalker
Coder
Posts: 18
Joined: Fri Feb 11, 2005 11:51 am
Location: Lea Monde Ruins

searching a file for specific data

Post by Agent_Firestalker »

I read this on a web site, seemed feasable...

you type up a text file of say, items, for an RPG.
the format of each line in file is... Weaponname$, weapdam,weapclass,etc
i have a loop like this (i'm writing psuedocode, so don't take literally)

do
read weaponname$
if weaponname$ = "Rhomphaia" then get rest of line
else goto next line
loop until weapnclass or weapndam = something

Is this flawed?

thanx
Agent_Firestalker
"I ask you, is this a job for intelligent men?"
"Well show me one, i'll ask him?"

Val and Earl - "Tremors"
User avatar
Zamaster
Veteran
Posts: 174
Joined: Wed Jun 15, 2005 1:51 pm

Post by Zamaster »

As far as I know it works fine, except what is the "something"?
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN
Agent_Firestalker
Coder
Posts: 18
Joined: Fri Feb 11, 2005 11:51 am
Location: Lea Monde Ruins

Post by Agent_Firestalker »

Basically, if the first entry in the file is the desired weapon, in my example it's the rhomphaia (from Vagrant Story, PS1), then the program reads the next entries on that line and stores them in the appropriate variable. the loop that does all this exits when more than the first entry in a line is read (meaning the correct weapon was found).

P.S. is there a limit to how many lines a file can have? (i'm converting to FB if that makes a difference.

thanx
Agent_Firestalker
"I ask you, is this a job for intelligent men?"
"Well show me one, i'll ask him?"

Val and Earl - "Tremors"
guest

Post by guest »

Agent_Firestalker wrote:Basically, if the first entry in the file is the desired weapon, in my example it's the rhomphaia (from Vagrant Story, PS1), then the program reads the next entries on that line and stores them in the appropriate variable. the loop that does all this exits when more than the first entry in a line is read (meaning the correct weapon was found).

P.S. is there a limit to how many lines a file can have? (i'm converting to FB if that makes a difference.

thanx
Agent_Firestalker
i dont know what FB does but your logic looks okay...

as for number of lines i thinks it like 16,000 line or something
im writing a game that quit's when i go over that number
of lines...
Guest

Post by Guest »

guest wrote:
Agent_Firestalker wrote:.....
P.S. is there a limit to how many lines a file can have?....
thanx
Agent_Firestalker
.....
as for number of lines i thinks it like 16,000 line or something
I'm writing a game that quit's when i go over that number
of lines...
I've been using QB and QuickBasic for over 10 years and I have never read or heard of a maximum number of records.

However, I have read advice to define your record counter as LONG. Probably the game that quit around 16 to 32k records was counting in an integer variable. However, this is not a QB restriction on the number of records it can read or write.
*****
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

Ooops, the above post was mine. Caught by the security login again.
*****
guest

Post by guest »

ahhhhh thats what was wrong...i retract my advice then
add as many as ya want! :)


Anonymous wrote:
guest wrote:
Agent_Firestalker wrote:.....
P.S. is there a limit to how many lines a file can have?....
thanx
Agent_Firestalker
.....
as for number of lines i thinks it like 16,000 line or something
I'm writing a game that quit's when i go over that number
of lines...
I've been using QB and QuickBasic for over 10 years and I have never read or heard of a maximum number of records.

However, I have read advice to define your record counter as LONG. Probably the game that quit around 16 to 32k records was counting in an integer variable. However, this is not a QB restriction on the number of records it can read or write.
*****
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

Um.. if your reading from a file, processing as you go, then the file can be as big as you can DIM a varible to read the info:

DIM Weap$(100), Weapstat$(100),.. ect

As for FreeBasic, the file sizes can be 2gig, minus the fact that take ages to parse on a slow comp...

What about your parser? Do you need help there too? You can do it, but deff not like your psuedocode... its alot more IF..THENs, MID$, UCASE$ (or LCASE$), ect.. :wink:

EDIT:

A easyer way than parsing would be:

Weapon's File

Code: Select all

Rapawhatever, whateverstat, whatevertype
Reading Code:

Code: Select all

OPEN "File.txt" FOR INPUT AS #1
DIM Weapname$(100), Weapstat$(100), Weaptype$(100)
cont = 0
DO
cont = cont + 1 '(In FB it can be done: cont += 1)
INPUT #1, Weapname$(cont), Weapstat$(cont), Weaptype$(cont)
LOOP UNTIL EOF(1)
CLOSE #1
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
ShadowWolf
Veteran
Posts: 56
Joined: Thu Mar 04, 2004 1:32 pm
Contact:

Post by ShadowWolf »

if your going to store wapons status/iteam states in a file might be esayer for you to use a UDT like

Type Iteams
IteamName as string*20
iteamclass as integer ' you can sue this as a flag i.e. wapons or
iteamextrainfo as integer ' heal then the next member in the type can
end type 'define the attack or healing power ect

dim iteamlist(100) as iteams


then
open "iteams.itm" for binary as 1

get #1,,iteamlist(0)

the binary get will grab as many byte as the UDT type size in this case it be 24 in qb in fb 28 byte then copy them directly in the udt allocated memorey filling the information in for you.
User avatar
UWLabs
Coder
Posts: 12
Joined: Sun Oct 03, 2004 7:53 am
Location: Tennessee

Just for clarification...

Post by UWLabs »

There's nothing like QB's original Help file...
(Coppied verbatim)

Code: Select all

 File  Edit  View  Search  Run  Debug  Options
───────────────────── HELP: Procedure and File Limits ─────────────────
 ◄Contents►  ◄Index►  ◄Back►
───────────────────────────────────────────────────────────────────────
                              Maximum                 Minimum
                              ════════════════════    ═══════════
Procedure size                64K                     0
Number of arguments passed    60                      0
Data file numbers             255                     1
Data file record number       2,147,483,647           1
Data file record size         32K                     1 byte
Data file size                Available disk space    0
Path names                    127 characters          1 character
Error message numbers         255                     1 
That should help somewhat. (I think).
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

Yup that should help :-)...only there's one problem is that the Maximum File Size is wrong...the help was written when hard drives weren't bigger than 2Gig. DOS imposes a 2 Gig limit to a data file size.
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
Post Reply