QBASIC SET VARIABLE in DOS

The forum for all of your Freebasic needs!

Moderators: Pete, Mods

Post Reply
Andries
Newbie
Posts: 6
Joined: Fri Jun 18, 2010 3:44 pm

QBASIC SET VARIABLE in DOS

Post by Andries »

Hello,


I have a Qbasic problem and I hope you can help me.

I would write a Qbasic program who ask me a 4 digit code
e.g. 1234
(and not A...z or 123)

And then use the "4 digit code" and SET it in the DOS variable NUMBER


In the DOS prompt I can type the followed code

SET NUMBER=1234

And if I check it in DOS
type: SET
And I see: NUMBER=1234

But how can I make this in Qbasic?


Greetings,
Andries.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Use INPUT "Enter a 4 digit number: ", number%

PRINT number%
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Andries
Newbie
Posts: 6
Joined: Fri Jun 18, 2010 3:44 pm

Post by Andries »

That's not a good solution
If I use this you can also type a 2 digit number or a 5 digit number.
there is no control if it is a 4 digit number.

And on this manner there is not variable SET it in the DOS variable.
(check it with type "SET" in the DOS command prompt)
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Try this:

Code: Select all

PRINT "Enter a 4 digit number"
num$ = INPUT$(4)
PRINT num$

ENVIRON "NUMBER=" + num$

This can be used as a temporary setting that will not work after the QB program is done. It will be added to the list to view with:

PRINT ENVIRON$("NUMBER") ' will display the number only

To view the entire list of settings as SET would display them:

Code: Select all

DO
  count = count + 1
  PRINT ENVIRON$(count)
  IF count MOD 20 = 0 THEN 
       PRINT "Press a key!": SLEEP
       CLS
  END IF
LOOP until ENVIRON$(count) = ""
Use SHELL to SET it in DOS. By the way, how would you UNSET it in DOS? Restart PC? I don't recommend messing with SET as the QB program could set it temporarily and invisibly.
Last edited by burger2227 on Tue Jun 22, 2010 3:05 pm, edited 1 time in total.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Andries
Newbie
Posts: 6
Joined: Fri Jun 18, 2010 3:44 pm

Post by Andries »

Mhh, I think it's the good way but it works not yet.

The followed error does I have:

With sample 1:

By running the code There is a error bij "INPUT$"
Expected: statement

(Sample 1 does not compile)



But by sample 2:
I can read the params from DOS but there is no setting from QB45 into this params field set.

And by the sample 3:
If I try to compile this rule:
ENVIRON "NUMBER=HELLO"
The following error is displayed on the screen:
"Out of Memory"

-------------------------------------------
What is the aim?
On my company we proceed to Windows 7.
We have create one "golden Image" for all type's of computers / notebooks.

All of this computers (I think approximately 1500) must have a unique number.

We fill in on each computer the ASSETTAG (from the BIOS)
And if we get the image on the computer we can read the ASSETTAG of the BIOS with *.VBS script.
And this number is the number of the Windows machine.


But we have different tools to set the ASSETTAG of this machine's
(different manufacturers)


I have create a BOOTABLE USB-key with a batch file.
But each tool has different params.

Now I would make a Batch or QB45 (DOS) tool


And if the USB start up I pressed a PCNumber.
Then SET the PCNumber in the DOS PARAMS
And also I can fill in the PCnumber without the list of params from the ASSETTAGTool.

e.q.

(QB?)Which PC number do you have?
Answer: 1234
(QB?) SET PCNUMBER=1234

And then I can make:

ASSETTAG.EXE /D /CA /-y %PCNUMBER%

And the I can RESET the computer and set the GoldenImage on this machine.
-------------------------------------------

I hope you can understand me, my English is not optimum
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

My bad! I was kinda busy when I posted code:

Code: Select all

PRINT "Enter a 4 digit number"
num$ = INPUT$(4)
PRINT num$

ENVIRON "NUMBER=" + num$
Sorry!

You can also try SET by using SHELL.

Code: Select all

  SHELL "SET NUMBER=1234"

Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Andries
Newbie
Posts: 6
Joined: Fri Jun 18, 2010 3:44 pm

Post by Andries »

gives nothing.
I am already glad that you try to help me!

but....

the first code works!

Code: Select all

PRINT "Enter a 4 digit number" 
num$ = INPUT$(4) 
PRINT num$ 
But you can not see the key who I pressed (realtime)?
Is that correct?
(I can see it with the PRINT COMMAND but it is less beautyfull)


And :-(

Code: Select all

ENVIRON "NUMER=" + num$
gives immediately a "Memory error"

I Hope that you can help me again..
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Either the computer is blocking the change or the environmental variable is overflowing the memory allowed. It is limited!

DID you try the SHELL?

SHELL "SET NUMBER=" + num$

That should work same as DOS. You said it worked in DOS right?


You can try LOCATE , , 1 to display the cursor, but it does not work on my XP. After INPUT$(4) procedure use LOCATE , , 0 to set it back.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Andries
Newbie
Posts: 6
Joined: Fri Jun 18, 2010 3:44 pm

Post by Andries »

Thanks for your reply again...

But I think, I must give it up.

If I try the

Code: Select all

SHELL "SET NUMBER=" + num$
there is no memory error.

But if I look on the DOS prompt with the command SET there is no variable NUMBER.

I do not get it. :(

If I start up with DOS and type

Code: Select all

SET NUMBER=3
And I type SET the variable NUMBER is set to 3 (NUMBER=3)

But if I would make it in QB45 it seems that it is not possible. :?:
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

You have to view the settings INSIDE a Qbasic program!

The value will disappear when the Qbasic program ends! It is not permanent! I cannot get it to work either. Out of memory.

However if you set the number at the beginning of the QB program it may be there when you need it IN the program. NOT DOS!

If that does not work, then create a batch file IN the Qbasic program and run it after it is made.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Andries
Newbie
Posts: 6
Joined: Fri Jun 18, 2010 3:44 pm

Post by Andries »

:oops: that works! :lol:

I think: "I make a stand alone exe-file and SET the DOS params"
But if I close the EXE file the DOS params is not set.

But this way (a batch file in Qbasic) work very well.

Thank you very much for all answers.

this is the solution! :D
Post Reply