Page 1 of 1

New to QBasic

Posted: Mon Oct 02, 2006 6:27 pm
by ZZUB
Hi
Ive only recently started using QBasic at college and I would like to know how to loop something if a certain value is met... heres a silly example

DIM Username AS STRING
DIM Sentence AS STRING

CLS

INPUT "Please type your user name"; Username

INPUT "Please type sentence(s)"; Sentence

CLS

PRINT Sentence

IF Username = Mance THEN

PRINT "Invalid sentence structure, please input again"

ELSE

PRINT "Good job!"

END IF

How would I make the user 'Mance' have to start from the beginning?
Thanks...

Posted: Thu Oct 05, 2006 2:58 am
by buff1
The easiest (though not the most popular) in this particular situation is with a goto

Code: Select all

DIM Username AS STRING 
DIM Sentence AS STRING 
START:
  CLS 

  LINE INPUT "Please type your user name"; Username 

  LINE INPUT "Please type sentence(s)"; Sentence 

  CLS 

  PRINT Sentence 

  IF Username = Mance THEN 
    PRINT "Invalid sentence structure, please input again" 
    GOTO START
  ELSE 
    PRINT "Good job!" 
  END IF 
(I also replace input with line input)

Posted: Fri Nov 03, 2006 6:40 am
by Bulldog
DIM Username AS STRING
DIM Sentence AS STRING

DO

CLS

INPUT "Please type your user name"; Username

INPUT "Please type sentence(s)"; Sentence

CLS

PRINT Sentence

IF Username = Mance THEN

PRINT "Invalid sentence structure, please input again"

ELSE

PRINT "Good job!"
EXIT DO

END IF

LOOP

Posted: Fri Nov 03, 2006 6:23 pm
by buff1
Note:
should be
If UserName = "Mance" then
better is:

If Ucase$(UserName) = "MANCE" then