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 / Database help

Author
Message
DethFenix
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location:
Posted: 18th Jul 2009 10:06
Creating this for a game.

I've tried to make it work and I was successful up until it told me that I didn't have "name$" anywhere in the code, so I just gave up.


This is supposed to be a Database. Can anyone help me?




Also, the "0:" is supposed to be when you type "3" in the menu you can add a new entry...Functions won't work for some reason, they just make it not be able to read the code for some reason. But yeah, if anyone can help me on those two things I'd much appreciate it. Thanks.

Rise from the fallen ashes.
bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 18th Jul 2009 13:18
the first problem (Name$), it says that that variable does not exist?
if it does, you might have to create it. just Dim name$(200) is enough. but if you're gonna print it, it's gonna be all empty, so don't forget to fill it. And gosubs are just as fine as functions, just be sure you don't use... *tamtamtaaaam* GOTO's! those things are nearly illegal!

Oh No, there's too much blood in my caffeine system!
Stack Overflow: Too many pancakes...
The programmer's national anthem is 'AAAAAAAAHHHHHHHH'. -Weinberg, p.152
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Jul 2009 21:05 Edited at: 18th Jul 2009 21:09
Quote: "I've tried to make it work and I was successful up until it told me that I didn't have "name$" anywhere in the code, so I just gave up."


Just as Bobbel said it doesn't exist. Since you use a User Defined Type there's no need for name$() so you can just get rid of it.

Quote: "Also, the "0:" is supposed to be when you type "3" in the menu you can add a new entry...Functions won't work for some reason, they just make it not be able to read the code for some reason. But yeah, if anyone can help me on those two things I'd much appreciate it. Thanks."


I imagine functions won't work for you because you use the variable index. To make it work inside functions you can set the variable to GLOBAL by typing (without quotes) "global index".

Looking at your code... you don't have to define the User Defined Type every time you want to use it. It needs to just go at the top of the code and only defined once... under it should be any GLOBALs.

You were on the right track with saving/loading the data but you needed to type out the UDTs instead of saving "fbi"... all that does is save the text "fbi". And because Age is an integer it needs to be saved with the STR$() command to convert an integer to a string. When you load Age it needs a temporary string (like a$) to store the string till it's converted back to an integer or float with the VAL() command.

The one thing that was annoying is when the user hits 3 to type in a new entry it asks again if the user wants to add a new entry. This is the same as asking twice... if the first answer is yes there's no need to ask again. Also if they say No it doesn't give the user the opportunity to save the data before quitting. So if they accidentally hit No after typing in a hour of entries... all that work is gone. It's best to keep the only exit on the main menu.

Since you used GOTO and I'm SO against it I rewrote your code to use functions instead of the GOTO statement. GOTO while a good command to use when your first learning programming once you learn about GOSUB and functions you should avoid GOTO at all costs.



DethFenix
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location:
Posted: 18th Jul 2009 21:27
Okay. Thanks so much for the help guys! I really appreciate it.

Rise from the fallen ashes.
DethFenix
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location:
Posted: 18th Jul 2009 22:41
One more question, is there a way I can have people load up entries? Like instead of making the last entry viewable, is there a way possible to have them select which entry number they can view?

Rise from the fallen ashes.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Jul 2009 00:27
Yeah, you can put the printing of the records in it's own DO/LOOP and check for the arrow keys to increase or decrease the current record being shown (any variable instead of index will do)... just be sure to add a way for the user to EXIT the DO/LOOP so it goes back to the main DO/LOOP.

DethFenix
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location:
Posted: 19th Jul 2009 03:00
Alright. Sorry for all the questions...But how does this look?




I'm fairly new to the coding thing. Sorry again for the questions.

Rise from the fallen ashes.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Jul 2009 06:06
It looks good. One thing you should probably do though is make two UDTs instead of one. Putting all individual people and all gang information in one UDT is probably a bad idea.

Simply putting UPKEY() next to the input does not make it detect the up arrow. It needs to be in an IF/THEN statement so you can tell it what to do when the up arrow is hit.

Like:


Use CRecord instead of index for printing the data. When the function is entered any variables not global or defined before their first used are automatically zero. Do the same for the down arrow but instead of decreasing CRecord increase it instead with the INC command. Be sure to add an IF/THEN to check if CRecord goes beyond what you want it to be. You don't want it to be less than zero or more than index. Use KEYSTATE() instead of the INPUT command in the ShowData function. INPUT stops all action so you won't have any time to hit the up or down arrow keys to cycle through the records. Here's a link to my KEYSTATE map. Every number under each key is the KEYSTATE number to use to detect that key.

http://mysite.verizon.net/grueslayer/Keystate.png

Login to post a reply

Server time is: 2024-11-25 05:01:24
Your offset time is: 2024-11-25 05:01:24