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.

Newcomers DBPro Corner / Can someone help with my database please?

Author
Message
Game Master1330
17
Years of Service
User Offline
Joined: 19th Oct 2007
Location: (GetReaderXYZ() * 42 ) / 0
Posted: 29th Sep 2009 23:08 Edited at: 1st Oct 2009 22:35
I've made a code which has data put in and when you put a number in, it shows the corresponding data. The problem is that i don't know how to get it to save new data that you put in. And also, i don't know how to get it to add an account automatically. You will see what i mean if you try to run it.



EDIT - I have compleltely re-written most of the code and have now solved most of the issues.

I do still need help ironing out a couple more though.
I need to know how to check if a file exists and cancel a file reading operation if it doesn't. Because at the moment if the user types a file that doesn't exist, the program exits.

Also, i need to know how to set cd to the default path. At the moment, once you have made a default path, you have to go into settings and tell it to set it to the default path.



I have edited it yet again (WITH LOADS OF HELP FROM GROG) to perfection (Hopefully)


Please leave comments or suggestions.
Any help appreciated.
Matt

Umm...
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 1st Oct 2009 07:20
Quote: "I need to know how to check if a file exists and cancel a file reading operation if it doesn't. Because at the moment if the user types a file that doesn't exist, the program exits."


You can use the command FILE EXIST():


Quote: "Also, i need to know how to set cd to the default path. At the moment, once you have made a default path, you have to go into settings and tell it to set it to the default path."


I don't quite understand what you mean. The default path is always the directory the .exe is in. If you change to a directory within the starting directory and want to go back to the default you use CD ".." to go back one directory. And the \ should be at the end of the directory path... not the beginning.

What you should really do is keep away from GOTO. The way you do the code it's going to have a problem because you keep going to choices before the RETURN. When you want to use a RETURN you use GOSUB to go to the label and use RETURN to come back to the next line under the GOSUB.

If you want to repeat code you can encase it in a DO/LOOP instead of using GOTO over and over again. There are also conditional loops like REPEAT/UNTIL loops that should work nicely when you want to check if a file exists or not.

Another thing you may not realize is a file cannot exist before you can write to it. So to write a new file you need a check to see if the file exists already and deletes it if it does.

I really don't get why you want to change directories. The files are so small there's no need to have a bunch of different directories for each... and if you want to use account numbers you can add numbers to the filenames like Account_1.txt, Account_2.txt, Account_3.txt.



But the easiest way is using the SAVE ARRAY and LOAD ARRAY commands. You can use those to quickly save the array you had in the first code snip and you won't have to worry about writing a bunch of different files.



And don't be afraid to use rem statements... a remark filled code is easy to understand.

Here's some changes to your code:


Game Master1330
17
Years of Service
User Offline
Joined: 19th Oct 2007
Location: (GetReaderXYZ() * 42 ) / 0
Posted: 1st Oct 2009 09:52
Thanks! This really helps. I knew about the file exist command and all of the commands that return a number but I didnt know how to use them and thanks for explaining the goto gosub thing. the reason I put the goto choices in every subroutine was because at the end of the subroutine, it always exited. Now i know that it was because of goto.

Thanks for the help!
Matt

Umm...
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 1st Oct 2009 21:02
Np.

Login to post a reply

Server time is: 2024-11-24 01:38:56
Your offset time is: 2024-11-24 01:38:56