QuickBASIC code help!
Moderator: Quantum P.
QuickBASIC code help!
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?
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?
- Dr. Dos
- OH YES! USE VINE WHIP! <3
- Posts: 1772
- Joined: Tue Mar 11, 2003 12:00 am
- Location: Washington
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.
Visit the Museum of ZZT
Follow Worlds of ZZT on Twitter
Apologies for the old post you may have just read.
Follow Worlds of ZZT on Twitter
Apologies for the old post you may have just read.
- Quantum P.
- Level 17 Accordion Thief
- Posts: 1433
- Joined: Fri Sep 12, 2003 1:41 am
- Location: Edmonds, WA
- Contact:
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:
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!
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
Hope that wasn't confusing, and good luck with your project!
- Quantum P.
- Level 17 Accordion Thief
- Posts: 1433
- Joined: Fri Sep 12, 2003 1:41 am
- Location: Edmonds, WA
- Contact:
(annoyed grunt)
(smacks head for not seeing the simple solution)
...Or you could just say IF A$ = expression THEN ENVIRON "KEYS_RETURN=pressedKey"
...Or you could just say IF A$ = expression THEN ENVIRON "KEYS_RETURN=pressedKey"
- Dr. Dos
- OH YES! USE VINE WHIP! <3
- Posts: 1772
- Joined: Tue Mar 11, 2003 12:00 am
- Location: Washington
Nadir did, and I changed the sig.
Visit the Museum of ZZT
Follow Worlds of ZZT on Twitter
Apologies for the old post you may have just read.
Follow Worlds of ZZT on Twitter
Apologies for the old post you may have just read.
-
- LOOK OUT FER BAAAD BOB
- Posts: 116
- Joined: Fri Mar 28, 2003 12:51 am
- superbowl shuffle
- Official Clamp School Defender
- Posts: 418
- Joined: Mon Apr 07, 2003 4:52 am
- Location: CAsE SenSiTiVe
- Quantum P.
- Level 17 Accordion Thief
- Posts: 1433
- Joined: Fri Sep 12, 2003 1:41 am
- Location: Edmonds, WA
- Contact:
BASIC itself is archaic. (1960)
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.Ryan Ferneau wrote:You mean they aren't two names for the same thing?
Boom.dk, I found this in the QuickBASIC 4.5 documentation under ENVIRON, Details:
I assume that you can use ENVIRON to set an environment variable and read it immediately from within the program, as in the following: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.
Code: Select all
ENVIRON "ZZT=Cool"
PRINT ENVIRON$("ZZT")
Just out of curiosity, what are you working on, and why do you need keypress information put in the environment-string table?
A program like this you wood probably beter use DEBUG to do this.
This example will tel you key code on errorlevel.
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...
this just returns the keypress' ascii number in the %errorlevel% environment variable
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
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());
}
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
we're not bad people, we're not dirty, we're not mean, we love everybody, but we do as we please