QuickBASIC code help!

..................WTF?! YOU DONT KNOW WHAT IS "XRUMER"?!

Moderator: Quantum P.

Locked
207
What can be said now?
Posts: 0
Joined: Sat Jul 26, 2003 8:42 pm

QuickBASIC code help!

Post 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?
User avatar
Dr. Dos
OH YES! USE VINE WHIP! <3
Posts: 1772
Joined: Tue Mar 11, 2003 12:00 am
Location: Washington

Post 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.
Visit the Museum of ZZT
Follow Worlds of ZZT on Twitter

Apologies for the old post you may have just read.
User avatar
Commodore
fgsdfs
Posts: 2471
Joined: Wed Mar 12, 2003 5:44 pm
Location: :noitacoL
Contact:

Post by Commodore »

instead of "end" use "return"

end end's the program natch.
*POW* *CLANK* *PING*
User avatar
Quantum P.
Level 17 Accordion Thief
Posts: 1433
Joined: Fri Sep 12, 2003 1:41 am
Location: Edmonds, WA
Contact:

Post 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!
User avatar
Mooseka
;-*
Posts: 282
Joined: Mon Sep 22, 2003 5:01 pm

Post by Mooseka »

whoever made boom.dk into smile.dk is my hero forever and ever.
Image
User avatar
Quantum P.
Level 17 Accordion Thief
Posts: 1433
Joined: Fri Sep 12, 2003 1:41 am
Location: Edmonds, WA
Contact:

(annoyed grunt)

Post by Quantum P. »

(smacks head for not seeing the simple solution)

...Or you could just say IF A$ = expression THEN ENVIRON "KEYS_RETURN=pressedKey"
User avatar
Commodore
fgsdfs
Posts: 2471
Joined: Wed Mar 12, 2003 5:44 pm
Location: :noitacoL
Contact:

Post by Commodore »

My BASIC skills are limited to a certain archaic computer.
*POW* *CLANK* *PING*
User avatar
Dr. Dos
OH YES! USE VINE WHIP! <3
Posts: 1772
Joined: Tue Mar 11, 2003 12:00 am
Location: Washington

Post by Dr. Dos »

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.
207
What can be said now?
Posts: 0
Joined: Sat Jul 26, 2003 8:42 pm

Post 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...
Ryan Ferneau
LOOK OUT FER BAAAD BOB
Posts: 116
Joined: Fri Mar 28, 2003 12:51 am

Post 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!
User avatar
superbowl shuffle
Official Clamp School Defender
Posts: 418
Joined: Mon Apr 07, 2003 4:52 am
Location: CAsE SenSiTiVe

Post by superbowl shuffle »

You just blew my mind.
[size=75:lh51rn9h][b:lh51rn9h]When the 5 o'clock whistle blows, so do I.[/b:lh51rn9h]
[/size:lh51rn9h]
User avatar
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)

Post 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?
136
What can be said now?
Posts: 0
Joined: Thu Apr 03, 2003 2:10 am

Post 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
phunk
captain champion
Posts: 56
Joined: Mon Aug 25, 2003 10:30 pm
Location: dicktown

or you could just do it in c...

Post 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
we're not bad people, we're not dirty, we're not mean, we love everybody, but we do as we please
Locked