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 files

Author
Message
Cyborg ART
17
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden - Sthlm
Posted: 20th Oct 2009 22:08
Hi there!

I am working on a project for my carpentry class, and my idea is to make a simple Quiz game.

And to make it even simpler I dont want the questions to be hardcoded into the software. Instead I want to be able to write questions with one .exe and then read the questions in another .exe

And I just want to see if I am doing right:


This is just a test, but no file is written. Do you have any ideas?

Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 20th Oct 2009 22:55 Edited at: 20th Oct 2009 22:56
One thing you need to change is the way you build the filename.

It should be something like:



but you should also put an "end" statement after your wait key, so that the code doesn't keep executing down into your gosub.

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 20th Oct 2009 23:20
Also, if the carpentry file already exist, and so does the next increment of x, that code will fail.
I would do it like so:


Cyborg ART
17
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden - Sthlm
Posted: 21st Oct 2009 09:22
Thank you!

Just a question, what happen if I write:



instead of



?

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 21st Oct 2009 11:13
It will attempt to write to file 2 instead of 1, which in your code above isn't open, thus closing the application with a "File is not open at line xxxx" error.

Cyborg ART
17
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden - Sthlm
Posted: 21st Oct 2009 19:48
I see, taht will come in handy

Now I have another question:

I want the user to make their own questions, and also write the options for it.
That works great, but i also want the user to be able to write a "command" so the computer fills all options with presets:



What I want is when the user writes "Stilar1" in

it will assign the right words to the right variable.

Cyborg ART
17
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden - Sthlm
Posted: 21st Oct 2009 19:50
The code did actually work, it just didnt recognize a ciptal letter in Stilar1. I can live with that

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 21st Oct 2009 20:31
You can just check for upper$(alternativ1$) = "STILAR" or lower$(alternativ$) = "stilar".
(As you guessed, those functions return the input string in all caps or no caps).

Cyborg ART
17
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden - Sthlm
Posted: 21st Oct 2009 20:59
Where would I put it?

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 21st Oct 2009 21:47 Edited at: 21st Oct 2009 21:48
Where you now did the check.
Or, if the case-sensitivity is completely unneccessary alltogether, you can set alternativ$ = upper$(alternativ$) directly after retrieving the input.

But my general suggestion was this:


Cyborg ART
17
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden - Sthlm
Posted: 22nd Oct 2009 22:49
I see, thanks!

Here is my complete code (dont steal it )
I would like you to take a look at it, I know it is a complete mess but its my first program in DbPro



I dont have that much of a problem with it.
But for some reason it dont want to write files for the "Ny kategori", and I dont know why

But I think it has everything to make questions for my quiz. I even made another code which read the files written from this code.

I am so proud of myself

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 23rd Oct 2009 00:46
Well, am on my way to bed right now, but off the top of my head, it seems that you never set the mapp$ string.

Therefore the writequestion routine would try to open the file '\ID.frg', which probably won't work.

Also, it is inneccessary to use the $ symbol when manually declaring the variables as strings using the 'as string' syntax. Doing so probably shouldn't cause any problems though.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 28th Oct 2009 13:27
You should also read up on program structure and layout... before you get any better at spaghetti coding.

The method you are using right now is OK when you are starting to program, but if they get any bigger they will be almost impossible to follow - making problem fixing a nightmare.

Here's a start:

Tutorial 2

This is part 2 of a series for beginners so you might like to start with number 1 if number 2 covers anything you aren't sure about.

All Tutorials

TDK

Cyborg ART
17
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden - Sthlm
Posted: 29th Oct 2009 09:05
Thanks, will keep that in mind.

Login to post a reply

Server time is: 2024-11-24 00:37:05
Your offset time is: 2024-11-24 00:37:05