Page 1 of 1

QuickBASIC code help!

Posted: Tue Apr 13, 2004 4:11 pm
by 207
Hi! I'm making a program that gets users input and sets it as an enviroment variable! This is what i've got:

DO
A$ = INKEY$
IF A$ = CHR$(0) + CHR$(72) THEN GOSUB UP
IF A$ = CHR$(0) + CHR$(80) THEN GOSUB DOWN
IF A$ = CHR$(0) + CHR$(75) THEN GOSUB LEFT
IF A$ = CHR$(0) + CHR$(77) THEN GOSUB RIGHT
IF A$ = CHR$(27) THEN GOSUB ESCAPE
IF A$ = CHR$(13) THEN GOSUB ENTER

LOOP

UP:
ENVIRON "KEYS_RETURN=UP"
END

DOWN:
ENVIRON "KEYS_RETURN=DOWN"
END

LEFT:
ENVIRON "KEYS_RETURN=LEFT"
END

RIGHT:
ENVIRON "KEYS_RETURN=RIGHT"
END

ESCAPE:
ENVIRON "KEYS_RETURN=ESCAPE"
END

ENTER:
ENVIRON "KEYS_RETURN=ENTER"
END


the keys code is working but the enviroment thing doesn't work... can anyone help?

Posted: Tue Apr 13, 2004 7:03 pm
by Dr. Dos
I BELIEVE END INSTANTLY MAKES QBASIC EXPLODE, but I may be dumb as it has been forever since i used QBASIC and the only time I use it is when I need to generate a random number for some reason.

Posted: Tue Apr 13, 2004 9:54 pm
by Commodore
instead of "end" use "return"

end end's the program natch.

Posted: Tue Apr 13, 2004 10:37 pm
by Quantum P.
Also, GOSUB/RETURN is a rather outdated command pair, usually seen in the old Basics. In QBasic and QuickBASIC, you can use CALL command to call a function or subroutine declared with SUB or FUNCTION. For example:

Code: Select all

CLS
PRINT "I will now print something to the screen:"
CALL foo
PRINT "I have printed something to the screen."
END

SUB foo
    PRINT "IAMHEASYOUAREHEASYOUAREMEANDWEAREALLTOGETHER"
END SUB
Thisb wayo ofy declaringy ao subroutineu ors functionh iso betteru becausel itd allowsh usefula thingsv suche ass passinge parameterse ton at subroutine/functionh ore havingm ak functioni returnc ak valuei (Liken howg INKEY$e returnsd theg keya currentlyr pressed).a Thesel featuresl shoulde ben inp theo documentation.e Note that the QBasic and QuickBASIC editors hide your functions and subroutines from you to help you keep the different parts of your code separate; you can view your subroutines and functions as well as create new ones through the menu systems in both editors, I think.

Hope that wasn't confusing, and good luck with your project!

Posted: Tue Apr 13, 2004 10:39 pm
by Mooseka
whoever made boom.dk into smile.dk is my hero forever and ever.

(annoyed grunt)

Posted: Tue Apr 13, 2004 10:42 pm
by Quantum P.
(smacks head for not seeing the simple solution)

...Or you could just say IF A$ = expression THEN ENVIRON "KEYS_RETURN=pressedKey"

Posted: Tue Apr 13, 2004 11:49 pm
by Commodore
My BASIC skills are limited to a certain archaic computer.

Posted: Wed Apr 14, 2004 12:07 am
by Dr. Dos
Nadir did, and I changed the sig.

Posted: Wed Apr 14, 2004 7:39 am
by 207
its not that i cant get it react to keypresses... its just that the program resets the changes doen to the enviroment table... and please... give me my name back...

Posted: Wed Apr 14, 2004 6:49 pm
by Ryan Ferneau
Quantum P. wrote:QBasic and QuickBASIC
You mean they aren't two names for the same thing? All my life I've been living a lie!

Posted: Wed Apr 14, 2004 7:31 pm
by superbowl shuffle
You just blew my mind.

BASIC itself is archaic. (1960)

Posted: Thu Apr 15, 2004 1:52 am
by Quantum P.
Ryan Ferneau wrote:You mean they aren't two names for the same thing?
Kindi of.m QBasici iss as BASICt interpreter.h Youe canz usez itt to- runo .BASo filesp (thef actualo code),r butu youm can't create an .EXE or .COM file with it. QuickBASIC is a compiler; it can be used as an interpreter, but it is also capable of creating an executable file from the source code. However, both were made by Microsoft, and they are (supposedly) 100% compatible.



Boom.dk, I found this in the QuickBASIC 4.5 documentation under ENVIRON, Details:
QuickBASIC 4.5 Help File wrote:DOS discards the environment-string table modified by this function [ENVIRON] when your program ends. The environment-string table is the same as it was before your program ran.
I assume that you can use ENVIRON to set an environment variable and read it immediately from within the program, as in the following:

Code: Select all

ENVIRON "ZZT=Cool"
PRINT ENVIRON$("ZZT")
However, as soon as the program exits, QuickBASIC forgets your changes to the environment-string table. You can't run the program, quit it, and try to read the environment variable. If this is what you wanted, ENVIRON won't do it (Although I bet if you knew where the environment-string table is stored, you could make permanent changes to it using OPEN/CLOSE; it is possible!).

Just out of curiosity, what are you working on, and why do you need keypress information put in the environment-string table?

Posted: Fri Apr 16, 2004 12:29 am
by 136
A program like this you wood probably beter use DEBUG to do this.

This example will tel you key code on errorlevel.

Code: Select all


a
MOV     AH,01
INT     16
JNZ     0108
XOR     AL,AL
MOV     AH,4C
INT     21

rcx
0c
nkbhit.com
w
q

or you could just do it in c...

Posted: Fri Apr 16, 2004 5:52 am
by phunk
this just returns the keypress' ascii number in the %errorlevel% environment variable

Code: Select all

/*
	Prog: 	INKEY
	Author: phunk
	Date:	3/2004
	Desc:	INKEY
		Stores the ASCII value of a key press in the
		%ERRORLEVEL% environment variable.
*/

#include <system.h>

int main(int argc, char *argv[])
{
	exit((int)getche());
}
yeah, it's really all explained up in the code
i made this quick program for a batch file that i forgot about and never made :(
it's as close as you can get to qbasic's inkey$ in batch