Page 1 of 1

searching a file for specific data

Posted: Fri Jul 15, 2005 3:34 pm
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

Posted: Fri Jul 15, 2005 3:40 pm
by Zamaster
As far as I know it works fine, except what is the "something"?

Posted: Fri Jul 15, 2005 8:07 pm
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

Posted: Fri Jul 15, 2005 9:51 pm
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...

Posted: Fri Jul 15, 2005 11:31 pm
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.
*****

Posted: Fri Jul 15, 2005 11:34 pm
by moneo
Ooops, the above post was mine. Caught by the security login again.
*****

Posted: Sat Jul 16, 2005 12:19 am
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.
*****

Posted: Sat Jul 16, 2005 10:29 am
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

Posted: Sun Jul 17, 2005 4:22 pm
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.

Just for clarification...

Posted: Wed Jul 27, 2005 11:56 am
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).

Posted: Wed Jul 27, 2005 12:27 pm
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.