Qbasicnews.com

Full Version: A small question.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi I have a little code problem in Qbasic and wonder if anyone know the solution. I made a trivia program for school. It's nearly complete except for this one problem. Here is the part of my code that has a problem. (in Bold)


Quote:'***************************************************************************
'INPUT

SLEEP
SCREEN 0
WIDTH 80
CLS
COLOR 12
LOCATE 6, 20
INPUT "Hello there, please enter your name:", username
LOCATE 7, 20
INPUT "Enter your name here please:", username
LOCATE 8, 20
PRINT "Thank you "; username
LOCATE 9, 20

I put the sleep command there because by doing so I can allow user to press any key to continue to the next screen. It works well other than the fact that the first INPUT command after the sleep command won't work. It display the question there but doesn't allow you to input anything. The second input works but I don't want to use it because its sort of faulty coding and going to cost me marks. I tried a number of different ways but couldn't find out why this is happening. Anyone know how to solve it? Thanks alo
Ok, this is easy, and should be in the noob one...but anyways....

Your trying to input a string value into a number variable.

To fix it:

Use:
username$

Instead of:
username

Now your inputing a string value into a string variable. Big Grin
Yeah Mitth, that's one of the problems, but there's another one lurking in there as well...and it involves that dreaded SLEEP command.

p3t3r, replace
Code:
SLEEP
with
Code:
DO: LOOP WHILE INKEY$ = ""
in addition to what Mitth suggested and everything will work just fine. The problem is that you're probably pressing the ENTER key to resume execution (almost all people press either ENTER or the spacebar) and that's passing the keypress to the first input, effectively killing its usefulness.

Also, if you don't want to change username to username$, you can always do this before you use the variable:
Code:
DIM username AS STRING
and you don't have to make any changes to how you use username.
Ya? Well, I NEVER press enter to pass a sleep....well I guess that's why I didn't see that...heh :roll:

I like the $ at the end of the variable better, it keeps you from getting conused on what kind of variable it is, so I know I'm not doing a len() to a number, or a cos() to a string....lol :lol:
You can also try this(dunno if it will work correctly):
Code:
CLS
Input "Enter your username ", u$
dummy$ = input$(1)
Input "Enter something else ", e$
Hey, thanks for the replies.

Quote:Also, if you don't want to change username to username$, you can always do this before you use the variable:
Code:
DIM username AS STRING

and you don't have to make any changes to how you use username.

I did DIM the username as string in my program but I didn't post that part of the code. Could it still be the root of the problem?

Thanks for the tip adosorken. I think it will fix the input problem until I can find the root of the sleep problem. Thanks alot.

Anonymous

dude, fuck sleep. never ever use it unless youre programming in FB, kay?

use like

while inkey$ = "": wend

or

do while inkey$ = "": loop

never use sleep. ever. i mean it.
*sigh* no one ever thanx me.... :roll:

Well if you aready dimed them as strings and there spelled the same then that is not the problem...CHANGE THE SLEEP!

ok, the sleeps the prob....change it to DO:LOOP WHILE INKEY$ = "". That should be it! Big Grin
Code:
SLEEP: k$ = INKEY$

Works flawlessly in QB. Why not use it?
thats two statements. AFAIK this should work the same:
Code:
dummy$ = input$(1)
Pages: 1 2