redo from start

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
relic
Newbie
Posts: 4
Joined: Tue Feb 08, 2005 6:13 pm

redo from start

Post by relic »

Somewhere on this huge board I'm sure the answer lies, but I cannot find it. So, here goes....
When entering a response to a question that wants a numerical value. If the user accidently types a letter you would get `redo from start?'
So, my question is: How would you stop the error message from popping up, and simply make it loop back to the question without making it look messy?
thanks for any help.
Nathan1993 no login

Post by Nathan1993 no login »

I won't give you the code :? (to lazy :twisted: ) but I will give you the steps.

#1>Input as STRING
#2>Check for letters, if there are, loop
#3>No letters, convert the string to #s. I dunno the function.

KNOW: MID$, INPUT$, IF, GOTO, DO, LOOP, GOSUB, and Something I don't.

OK... so the KNOW section was stupid. I don't care :wink:
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

Code: Select all

Do
Input "Enter any number to exit: ", value$
If LTrim$(Str$(Val(Value$) ) ) = value$ Then exit Do
Loop
value = Val(Value$)
"LTrim$(Str$(Val(Value$) ) ) = value$" is quick 'n dirty way to check if value$ is a valid number only, that is, no letters
I have left this dump.
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

Quick question Z!re....ummm what's with converting it to an % then back to a $?


:shock: But to my suprise it works! :D

I used to always to the LOOP/ASCII thing....
"But...It was so beutifully done"
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

You also need to check for commas.. I get a "Redo from start" every time I use a comma. This happens since a comma is used for to variables:

Code: Select all

INPUT "Q"; num1, num2
So if you use a comma and only have one variable, it messes up.. :wink: So it also needs a comma check to if that can be fabricated.. :)
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

Code: Select all

Do
Line Input "Enter any number to exit: ", value$
If LTrim$(Str$(Val(Value$) ) ) = value$ Then exit Do
Loop
value = Val(Value$)
Line input can handle commas


And it convert to number, then to string to check if it's the same. consider:
Value$ = "23A"
VAL(Value$) = 0
LTRIM$(STR$(VAL(Value$))) = "0"
If "0" = "23A" Then Exit Do
I have left this dump.
relic
Newbie
Posts: 4
Joined: Tue Feb 08, 2005 6:13 pm

thanks

Post by relic »

thanks guys. Worked like a charm!
:D
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

Hmmm...I remember when I was getting these errors.. I forgot about that until this post because I never had to deal with that for like a year...
"But...It was so beutifully done"
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

Yeah, I was playing with INPUT, MID$, LEN, and those others after Nathans bug (Not making a parser system, no way :shock: ,.) Not going to say what I'm trying to make with 'em tho,. :wink:

I noticed it when applying them in a CHAT style app, if I used a "," it messed up.. :( , LINE INPUT, that will help, but I'm off the CHAT thing for now.. :roll: hehe :wink: I'm on the secret one..
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

?Que dicis?
"But...It was so beutifully done"
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

Tranlate:
What for the sake of appearances?? :shock: What? :shock:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

Espanol....oh sorry Spanish....

It = What did you say?
"But...It was so beutifully done"
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

I typed what you said in a latin dictionary..

It came out as : What for the sake of apearances? Ques dicis? :)
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

He he...did I mention I know enough Spanish to communicate little in it?

Oh ya I said Que which is pronounced k.
"But...It was so beutifully done"
Post Reply