Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / I Wrote this Function But it isnt Working, WHY ???

Author
Message
SeNsE
21
Years of Service
User Offline
Joined: 26th Nov 2002
Location:
Posted: 27th Nov 2002 14:40
input Search$
Search_Data("Data_",".txt")

Function Search_Data(File$,Ext$)
Numb$="000"
Look$=File$+Numb$+Ext$
Find First
repeat
Numb$="Numb$+1"
Open to read 1,Look$
Until Search$=Title$
endfunction

This function is supposed to load an file with the name Data_001.txt, search it for the Title$ string and if it dosn't contain it, it will move on and search the next file ect...
But i don't know why it isn't working (?).
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 27th Nov 2002 15:48
Perform Checklist For Files?

I think you missed that bit.


Van-B
TheCyborg
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 27th Nov 2002 15:52
Boy... I think you have a loooong way to learn the DB language. My adwise to you is to start with something really easy, and work your way to the top. Maybe you should have posted this in the Newcomers Corner.

But don't worry, I'll try to help you anyway...
Every variable is is not global, so you have to specify the Title$ in the function declaration. The Function also have to return some kind of result, In this case the file where the search string is found. The Open To Read command should only be used once to open the file (not to read it). The variable Numb$ cammot be increased because it's a string varible.
This is coded right out of my head. This means that I did not test if it works. But try it anyway. This will not check files named like "Data_000.txt", because else it would be enormous. It checks files like "Data_1.txt", "Data_217.txt" or "Data_8311.txt". It doesn't either check "Data_5.txt" if all files with lower numbers does not exist and the start number is specified lower than 5. This function will return the filename of the file wich the string is found in.

Syntax:
Return String$ = Search_Data$(File$,StartNum,Extension$,LookForThis$)


Explanation:
Return String$ -> (String) This is the return string. It will be the full filename of the file wich the string is found in.

File$ -> (String) This is the name of the file before the number.

StartNum -> (Integer) This is the filenumber to start at.

Extension$ -> (String) This is the file extension inclusive the ".". (i.e. ".txt" or ".dat")

LookForThis$ -> (String) This is the string to look for in the files.


The Function:
Function Search_Data$(File$,StartNum,Ext$,FindString$)
Numb=StartNum
NotFound:
FileName$=File$+Str$(Numb)+Ext$
If File Exist(FileName$)=1
Open To Read 1,FileName$
Repeat
Read String 1,String$
If String$=FindString$ Then ExitFunction FileName$
Until File End(1)=1
Close File 1
Inc Numb
Goto NotFound
EndIf
EndFunction "String Not Found!"


Hope that helped...
Post here if it does...

Happy Learning... TheCyborg.

Ps: Phew. That's my longest post I ever posted...

TheCyborg Development.
http://TheCyborg.Amok.dk
The Ultimate Source To DarkBASIC Programming.
Zooker
21
Years of Service
User Offline
Joined: 27th Oct 2002
Location: United States
Posted: 27th Nov 2002 18:19
Just A thought!

Use DarkEdit. Specify
Global Search$
Put Open to Read Before Repeat and Read String inside Repeat.
Could Work!

It took Years to Make Me this Stupid!
SeNsE
21
Years of Service
User Offline
Joined: 26th Nov 2002
Location:
Posted: 28th Nov 2002 07:25
Thanks i'll give it a try, and mabey start from Scratch

TheCyborg
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Denmark
Posted: 28th Nov 2002 09:40
I tested the code when I got home from school, and it worked. I think i'll make it search for the search string inside the string (and not in the whole line) at a later time.

I use DarkEDIT, but if I make Globals it will not be compatible with people who don't.

TheCyborg Development.
http://TheCyborg.Amok.dk
The Ultimate Source To DarkBASIC Programming.

Login to post a reply

Server time is: 2024-04-25 05:19:58
Your offset time is: 2024-04-25 05:19:58