11-07-2013, 07:54 AM
Hello Gintaras, hello all,
I use a file to store informations.
Each record is composed of 3 string variables.
The numbers of records is from 100 to 5000 (maximum).
*** To write records, if gather information (3 items per record at the moment, could be 5 later), add them to a variable and then write them down in the file
str datas
datas.addline("Item1")
datas.addline("Item2")
datas.addline("Item3")
datas.setfile("c:\myfile.txt" -1 -1 1)
myfiles.txt then is:
________________
Item1
Item2
Item3
Item1-1
Item2-1
Item3-1
Item1-3
Item2-3
Item3-3
etc etc
-----------------------
*** Searching
To search in the file, i simply seach for a string matching Item2 (i have a routine to seach for each item, but it's the same code except
the matched line search)
str queue.getfile("c:\myfile.txt")
str s
str f="texttofind"
int i(1)
** search for matching line
foreach s queue
if(!StrCompare(s f)) break
i+1
str infos
** get line before and after to get record missing infos of matched pattern
for _i i-1 i+2
_s.getl(queue _i)
infos.addline(_s)
** Choose information needed through a list
_i=list(infos "Quoi copier?" "Copier les informations" 0 0 0 0 1)
ARRAY(str) a=infos
_s=a[_i-1]
finally, _s handles what I needed to find.
My question : this code works very well, but i'm sure it can be optimized by using some other technique.
How can I improve it for speed, memory usage and efficiency?
Thanks.
I use a file to store informations.
Each record is composed of 3 string variables.
The numbers of records is from 100 to 5000 (maximum).
*** To write records, if gather information (3 items per record at the moment, could be 5 later), add them to a variable and then write them down in the file
str datas
datas.addline("Item1")
datas.addline("Item2")
datas.addline("Item3")
datas.setfile("c:\myfile.txt" -1 -1 1)
myfiles.txt then is:
________________
Item1
Item2
Item3
Item1-1
Item2-1
Item3-1
Item1-3
Item2-3
Item3-3
etc etc
-----------------------
*** Searching
To search in the file, i simply seach for a string matching Item2 (i have a routine to seach for each item, but it's the same code except
the matched line search)
str queue.getfile("c:\myfile.txt")
str s
str f="texttofind"
int i(1)
** search for matching line
foreach s queue
if(!StrCompare(s f)) break
i+1
str infos
** get line before and after to get record missing infos of matched pattern
for _i i-1 i+2
_s.getl(queue _i)
infos.addline(_s)
** Choose information needed through a list
_i=list(infos "Quoi copier?" "Copier les informations" 0 0 0 0 1)
ARRAY(str) a=infos
_s=a[_i-1]
finally, _s handles what I needed to find.
My question : this code works very well, but i'm sure it can be optimized by using some other technique.
How can I improve it for speed, memory usage and efficiency?
Thanks.