Qbasicnews.com

Full Version: More help please!!!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have another problem and I don't know why.

""""""""""""""""""""""""""""""""""
INPUT "SELECT A LOCATION FOR THE TUBE OR A DESCRIPTIVE AREA OR ENTER YOUR OWN"; DES.3$
IF DES.3$ = "1" THEN
NAME.3$ = "FRONT LEG"
END IF
IF DES.3$ = "2" THEN
NAME.3$ = "REAR LEG"
END IF
IF DES.3$ = "3" THEN
NAME.3$ = "BASKET TUBE"
END IF
IF DES.3$ = "4" THEN
NAME.3$ = "CROSS TUBE"
END IF
IF DES.3$ <> "1-4" THEN
NAME.3$ = DES.3$
END IF
"""""""""""""""""""""""""""""""""""""""""""""

This is the code that I have and later on I print the name.3$. But no matter what I enter the name.3$ print always shows up as the des.3$ input. Unless I delete the following part.

"""""""""""""""""""""""""""""""""""""""""""""
IF DES.3$ <> "1-4" THEN
NAME.3$ = DES.3$
END IF
"""""""""""""""""""""""""""""""""""""""""""""

Can anybody tell me why?
thanks
chris
Strings are not like numbers. If it's not literally 1-hyphen-4 in the string it will register that.

There is another, better way to do what you're doing known as SELECT CASE

Code:
SELECT CASE DES.3$
  CASE "1"
    NAME.3$ = "FRONT LEG"
  CASE "2"
    NAME.3$ = "REAR LEG"
  CASE "3"
    NAME.3$ = "BASKET TUBE"
  CASE "4"
    NAME.3$ = "CROSS TUBE"
  CASE ELSE
    NAME.3$ = DES.3$
END SELECT

You can also use ELSEIF with basic, and INPUT with numeric values

INPUT x
print x + 2

Use qb's help (press f1 in qb or click the "qboho" link above). It has an excellent index of every qb statement in its standard library.
Hopefullty this answers your question:

Code:
CLS
INPUT "SELECT A LOCATION FOR THE TUBE OR A DESCRIPTIVE AREA OR ENTER YOUR OWN"; DES.3%
IF DES.3% = 1 THEN
name.3$ = "FRONT LEG"
END IF
IF DES.3% = 2 THEN
name.3$ = "REAR LEG"
END IF
IF DES.3% = 3 THEN
name.3$ = "BASKET TUBE"
END IF
IF DES.3% = 4 THEN
name.3$ = "CROSS TUBE"
END IF

IF DES.3% < 1 OR DES.3% > 4 THEN
name.3$ = STR$(DES.3%)
END IF

PRINT "This is DES.3% :  "; DES.3%
PRINT "This is name.3$:  "; name.3$

Test it!
Like toon said, if you put "1-4" in brackets, it will only work when you actually type in "1-4".
Ok all, I am a little confused. Please try and help me out with this.

1st. The problem that I asked about. I tried your suggestion prof_flex, but I need the user to be able to enter an alphanumeric entry. The way you suggested to do it only let me enter a numeric number.

As for your suggestion toonski84, I don't really understand the use of the CASE command. Maybe if I show you what I am doing you can better explain it to me.

Here is the basic code of what I want.

"""""""""""""""""""""""""""""""""""""""""
CLS
PRINT "1.YES"
PRINT "2.NO"
PRINT "3.MAYBE"
PRINT
INPUT "SELECT YOUR ANSWER OR ENTER YOUR OWN"; ANSWER$
IF ANSWER$ = "1" THEN
ANS.1$ = "YES"
END IF
IF ANSWER$ = "2" THEN
ANS.1$ = "NO"
END IF
IF ANSWER$ = "3" THEN
ANS.1$ = "MAYBE"
END IF
IF ANSWER$ = (anything other then 1 to 3) THEN
ANS.1$ = ANSWER$
END IF
CLS
PRINT "YOUR ANSWER WAS"; ANS.1$
"""""""""""""""""""""""""""""""""""""""""""""""""

This is basically a real simplified version of what I would like to do. I want them to answer 1,2 or 3 or they can enter their own answer. But I want to later print it.

prof_flex how do I get the program to understand to do something if the answer is something other then the 1,2 or 3. Like if I want to say that if the answer is <> 1-3 then do this. How do I achieve this. I thought that using "1-3" would work. But I have been out of programming so long I don't remember anything. LOL

I appreciate the help guys.
Thanks
Chris
Code:
CLS
PRINT "1.YES"
PRINT "2.NO"
PRINT "3.MAYBE"
PRINT
INPUT "SELECT YOUR ANSWER OR ENTER YOUR OWN"; ANSWER$
IF ANSWER$ = "1" THEN
ANS.1$ = "YES"
END IF
IF ANSWER$ = "2" THEN
ANS.1$ = "NO"
END IF
IF ANSWER$ = "3" THEN
ANS.1$ = "MAYBE"
END IF
ELSE
ANS.1$ = ANSWER$
END IF
CLS
PRINT "YOUR ANSWER WAS"; ANS.1$
Whitetiger0990 -
Thanks, but this doesn't work. I copyed and pasted exactly what you have and tried it, but I get an error that says ELSE without IF.
An edit of whitetiger's code

Code:
CLS
PRINT "1.YES"
PRINT "2.NO"
PRINT "3.MAYBE"
PRINT
INPUT "SELECT YOUR ANSWER OR ENTER YOUR OWN"; ANSWER$
IF ANSWER$ = "1" THEN
ANS.1$ = "YES"
END IF
IF ANSWER$ = "2" THEN
ANS.1$ = "NO"
END IF
IF ANSWER$ = "3" THEN
ANS.1$ = "MAYBE"  
ELSE
ANS.1$ = ANSWER$
END IF
CLS
PRINT "YOUR ANSWER WAS"; ANS.1$
SELECT CASE works like this

Code:
CLS
PRINT "1.YES"
PRINT "2.NO"
PRINT "3.MAYBE"
PRINT
INPUT "SELECT YOUR ANSWER OR ENTER YOUR OWN"; ANSWER$

SELECT CASE ANSWER$
    CASE "1" : ANS.1$ = "YES"    
    CASE "2" : ANS.1$ = "NO"
    CASE "3" : ANS.1$ = "MAYBE"    
    CASE ELSE : ANS.1$ = ANSWER$
END SELECT
CLS
PRINT "YOUR ANSWER WAS"; ANS.1$