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 / writing to files. HELP

Author
Message
Joegio13
19
Years of Service
User Offline
Joined: 26th Jan 2005
Location: Miami, FL
Posted: 10th Jul 2005 04:12
whats wrong with my code its not working correctly. the bfirst variable isnt being set to 0 for some reason. Also the data isnt presenting itself. Please help.

-sigh- DBPro can't program in the 4th dimension
Joegio13
19
Years of Service
User Offline
Joined: 26th Jan 2005
Location: Miami, FL
Posted: 10th Jul 2005 05:39
Actually i should be a little more specific. The code is suppose to save information for a game. i have REMSTART - REMEND the FOR loop to simplify the output to 4 outcomes. The DataWriteTest() adds test data into the variables. Your input would be greatly apreciated.

-sigh- DBPro can't program in the 4th dimension
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Jul 2005 07:37 Edited at: 10th Jul 2005 07:56
When you make code to write to files you only need to copy the code and replace all writes with "read" to be able to read the files.

There were a few problems with your code.

At the end of your code you had copied the function ReadInfo() without the word "function" and without renameing ReadInfo() (so I got rid of it and moved the prints up).

I remed off the call to WriteInfo because it wasn't needed for this test.

Bfirst does equal zero because you have a do loop constantly calling the function PlayGame(). Inside functions all non-dimensionalized strings/integers equal zero. Any changes to strings/integers (that aren't dimed) inside functions only work in the function. Outside the function they remain the same unless changed outside of functions (PassiveSkill(), ActiveSkill(), and BagSlot() can be changed inside functions). So in the PlayGame() function there's no need to have "if bfirst=0" and "bfirst=1" and "endif"... I left them there in case there are things you didn't post in your code.

I added "suspend for key" to wait for a keypress to continue so its easy to see that it's working. Since it's constantly calling PlayGame() it keeps reading the same data over and over again with no end (even though I added an "end" after the do loop... it's never seen but it's a habit of mine).

Hope this helps you.

Joegio13
19
Years of Service
User Offline
Joined: 26th Jan 2005
Location: Miami, FL
Posted: 10th Jul 2005 08:49
thanks. funny thing is that when i copied your code over mines it still didnt work. So i then started a new project and copied your code, and it worked. i then when back to my original code(with your code copied over it) and it wouldnt work. yet in a new project it did. WTF is that? anyways thats a million.

I just got one more question. You moved the variables i had from ReadInfo() into DataReadTest(). Now had i kept the ReadInfo() function. Was the fact that the variables where in there the reason that my project wouldnt read the variables? Do variables lose there data once they leave the function? (E.I. the way VB6 treats variable)

-sigh- DBPro can't program in the 4th dimension
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Jul 2005 12:27 Edited at: 10th Jul 2005 13:13
NP Yeah it did that to me too. Everytime I post I always test any code before writing the message and I copy/paste any code after the post to make doubly sure it works. It didn't work for me until I saved. It must be some fluke in Darkbasic that won't allow file writing/reading unless it knows what directory it's going to use (the directory you save your code).

Yes. Since their not dimed the data won't be the same outside the function. You can either use a goto statement or dim the variables and change all of them appropriately.



It looks funny (since it only holds one variable) but it gives you the ability to keep data inside functions (at least for those variables).
Joegio13
19
Years of Service
User Offline
Joined: 26th Jan 2005
Location: Miami, FL
Posted: 10th Jul 2005 16:42
thanks a million dude.



-sigh- DBPro can't program in the 4th dimension
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 11th Jul 2005 06:35 Edited at: 11th Jul 2005 06:47
NP I'm still a newbie so my methods are sometimes a little odd. Like I just discovered this afternoon (while helping Saberdude) that he had the word "global" before a variable. I tested it with functions and it works great... and it avoids "looking funny". I'm kicking myself for not seeing the obvious.

Unfortunately it means changing your code back to the way you had it... sorry about that.

Joegio13
19
Years of Service
User Offline
Joined: 26th Jan 2005
Location: Miami, FL
Posted: 11th Jul 2005 16:05
lol I'm kicking myself too. I never thought of doing that. To think I won a state competition in VB programing, yet DB is killing me.

-sigh- DBPro can't program in the 4th dimension
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Jul 2005 03:56 Edited at: 12th Jul 2005 03:57
You won a state competition in Visual Basic? Cool!!! It's like anything... after a while you'll code Darkbasic in your sleep.

Practice, practice, practice.
James Morgan
19
Years of Service
User Offline
Joined: 17th Apr 2005
Location: Behind you
Posted: 12th Jul 2005 06:38
Quote: "Everytime I post I always test any code before writing the message and I copy/paste any code after the post to make doubly sure it works. It didn't work for me until I saved"


Thats more than likely because its creating the .exe in the temp folder until you save it, due to this it looks for the files (or media) in the wrong place

Hello!

Login to post a reply

Server time is: 2024-11-27 22:38:52
Your offset time is: 2024-11-27 22:38:52