Qbasicnews.com

Full Version: Help with file access
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
First how can i access a file for an encryption program when the file has > 256 characters? :???:

Secound can anyone give me a short practice on subs?
Encryption program???

Are you encrypting a string or something? I have a program that does that. But I don't know why you are having problems with files larger than 256 characters unless I have more info.

Subs: Say you have something you want to repeat in several places around your program, eg say you have a platform type game and if you run out of health you die, or if you fall into a bottomless pit you die etc. You would not want to write out the code for what happens every time you need to check that they have died, so you put all the code for when they die into a SUB.

eg:
Code:
IF hp = 0 then
  youhavedied        ' the name of the sub
ELSEIF time <= 0 then
  youhavedied        ' you would have to write the code all over again here unless you used a sub
END IF

' And then in your sub...

SUB youhavedied ()

CLS
LOCATE 10,10
PRINT "You have died"
LOCATE 11,10
PRINT "(R)estart level"
LOCATE 12,10
PRINT "(Q)uit game"
LOCATE 14,10
INPUT "Your choice? (r,q): ", choice
' etc etc

When making a sub, you do the following:

Find a blank line in your code and write "SUB whatever" (without quotes and you can call it something else if you want).

This will take you to a new window, where you can write all the code you want to be in the sub. Make sure that the END SUB line that the program generates for you is last in the sub, for obvious reasons.

Then hit F2 to change between subs and the main module. This is self explanatory when you see the dialogue box.

Then somewhere in your program you can put a "call" to the sub. Just like in the example above, just write "whatever" when you need to call the sub.

last eg:
Code:
whatever

SUB whatever
PRINT "Hello world"
END SUB

Guess what this program does...

This is a quick, oversimplified version of events. If you want to learn about subs properly, check some tutorials on the subject.
Well it had been a while since i had ran the code and all i remember is that it didn't work. Then.

Now it works I'll post it later when I'am done messing with other codes Big Grin