searching a file for specific data
-
- Coder
- Posts: 18
- Joined: Fri Feb 11, 2005 11:51 am
- Location: Lea Monde Ruins
searching a file for specific data
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
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"
"Well show me one, i'll ask him?"
Val and Earl - "Tremors"
-
- Coder
- Posts: 18
- Joined: Fri Feb 11, 2005 11:51 am
- Location: Lea Monde Ruins
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
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"
"Well show me one, i'll ask him?"
Val and Earl - "Tremors"
i dont know what FB does but your logic looks okay...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
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...
I've been using QB and QuickBasic for over 10 years and I have never read or heard of a maximum number of records.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...
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.
*****
ahhhhh thats what was wrong...i retract my advice then
add as many as ya want!
add as many as ya want!
Anonymous wrote:I've been using QB and QuickBasic for over 10 years and I have never read or heard of a maximum number of records.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...
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.
*****
-
- Veteran
- Posts: 1055
- Joined: Sun Jan 02, 2005 2:11 pm
- Location: At my computer
- Contact:
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..
EDIT:
A easyer way than parsing would be:
Weapon's File
Reading Code:
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..
EDIT:
A easyer way than parsing would be:
Weapon's File
Code: Select all
Rapawhatever, whateverstat, whatevertype
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)
(x.t.r.GRAPHICS)
- ShadowWolf
- Veteran
- Posts: 56
- Joined: Thu Mar 04, 2004 1:32 pm
- Contact:
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.
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...
There's nothing like QB's original Help file...
(Coppied verbatim)
That should help somewhat. (I think).
(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
-
- Veteran
- Posts: 703
- Joined: Sun Nov 14, 2004 7:36 am
- Contact:
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
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com