Dave: I tried your suggestion for accepting both upper and lower case of a letter. As you suspected the && (AND) || (OR) will not work in QB 4.5. I modified it to a syntax that does work; see my attached file, BOTHCASE.txt. Thanks for the offer for additional assistance.
Original
CLS
PRINT "Would you like to print this information?"
PRINT
INPUT "ENTER 'Y' for YES"; Enter$
IF Enter$ = "y" THEN Enter$ = "Y": GOTO PrintIt
IF Enter$ = "y" THEN GOTO PrintIt
IF Enter$ <> "y" THEN IF Enter$ <> "Y" THEN GOTO RUSure
PrintIt:
PRINT : PRINT "Print it": END
RUSure:
PRINT : PRINT "Not print it": END
What about:
CLS
PRINT "Would you like to print this information?"
PRINT
INPUT "ENTER 'Y' for YES"; Enter$
Enter$ = UCASE$(Enter$)
IF Enter$ = "Y" THEN GOTO PrintIt
GOTO RUSure
PrintIt:
PRINT : PRINT "Print it": END
RUSure:
PRINT : PRINT "Not print it": END
Or, changing it to use structured programming, rather than "street BASIC" stuff (I think I'll describe that in a bit):
CLS
PRINT "Would you like to print this information?"
PRINT
INPUT "ENTER 'Y' for YES"; Enter$
Enter$ = UCASE$(Enter$)
IF Enter$ = "Y" THEN
PRINT
PRINT "Print it"
ELSE
PRINT
PRINT "Not print it"
END IF
END
That is essentially what you are "emulating" using the street BASIC goto. GOTO was the only control structure you could use in some early BASIC interpreters for Personal Computers. However, there hasn't been a good reason to limit yourself to using GOTO as the only method of flow control. It makes things more difficult to follow, and as programs get larger, it can become impossible to keep track of all the control flow. This applies equally to "GOSUB"; GOSUB works basically like GOTO, but you can make it return to where you used it with RETURN. For example:
CLS
PRINT "Would you like to print this information?"
PRINT
INPUT "ENTER 'Y' for YES"; Enter$
Enter$ = UCASE$(Enter$)
IF Enter$ = "Y" THEN GOSUB PRINTIT ELSE GOSUB NOPRINTIT
END
PRINTIT:
PRINT
PRINT "Print it"
RETURN
NOPRINTIT:
PRINT
PRINT "Not print it"
RETURN
END
This is functionally identical to the above. Naturally the appropriate logic would go within each, as I imagine you are implying with your own example.
BC_Programmer I must admit I'd never heard of the "StrComp," function
StrComp isn't in QuickBASIC, or most older BASIC dialects. I was thinking of Visual Basic.
and the code you provided is a little above me at this point.
My code was in error, actually.
The purpose is to create a new Function- STRCOMP, for comparing strings. Though perhaps a stumbling block for you is that you don't appear to be using Functions at all. Examples of common functions include LEFT$(), RIGHT$(), etc. StrComp() as present in languages that have it- unsurprisingly- compares the two strings you give it. if the first string is less than the second in the sort order, it returns -1; if they are equal, it returns 0. and if the second string is smaller, it returns 1.
Now, I quite recall my initial hurdles learning about Functions. The best way I found to consider them is more or less like a Math function. For example, math usually portrays math functions as f(x), which performs some function f on the value x. Most BASIC dialects include common Functions such as SIN, COS, and TAN.
A Function, then, usually has a few basic properties.
-A Name. This is pretty obvious. You need a name for a function so you can call it and use it.
-Arguments. Most functions take in inputs. for example, the trigonometric functions accept a number. This isn't required, though.
-A return value. This is what the function gives you back.
Now, in the case of StrComp, we have the following:
The Name will follow the standard "convention" of QuickBASIC, which is all uppercase function names. I think it looks ugly and makes the code look like it's yelling but when in Rome... Anyway, the name here will be STRCOMP.
Arguments. Our function will compare two strings. So we will need to accept two strings as arguments. We also want a argument to determine whether we will be case insensitive. We will accept an "INTEGER" number value. 0 will mean we don't want to compare text, and 1 will mean we do. ("Compare Text" meaning to be case insensitive)
QuickBASIC's rules regarding functions means we have to "DECLARE" it before we use it. This isn't 100% necessary but it's a good habit anyway. The line is essentially used to tell the compiler "I'm going to be using a Function, if you don't know what it does when you see it, don't worry, I'll tell you".
DECLARE FUNCTION STRCOMP(BYVAL str1 AS STRING,BYVAL str2 AS STRING, BYVAL COMPARETEXT AS INTEGER) AS INTEGER
the Function is declared with two String Arguments, and one INTEGER argument. the final section says the type of the Function's return value. in this case, INTEGER. BYVAL is worthy og explanation as well. This says that the Function will accept the parameters "By Value". In other words, when you call the function, the function get's a copy of what you sent it. This prevents the Function from changing those parameters, which can cause side effects later on.
Here is the implementation:
FUNCTION STRCOMP(BYVAL str1 AS STRING,BYVAL str2 AS STRING,BYVAL COMPARETEXT AS INTEGER) AS INTEGER
IF COMPARETEXT THEN
str1 = UCASE$(str1)
str2 = UCASE$(str2)
END IF
iF str1<str2 THEN STRCOMP=-1
IF str1=str2 THEN STRCOMP=0
IF str1>str2 THEN STRCOMP=1
END FUNCTION
The first step we take is to check if the passed in COMPARETEXT argument is non-zero. This satisfies the IF condition, and we then change the two input strings to be the uppercase versions of themselves by assigning the result from the UCASE$() function on them. After that, we simply follow the convention. "return" values are set by assigning values to the name of the function. In this case, we set the appropriate values to STRCOMP inside the function. The last thing we assigned when the function exits will be used in place of the function call.
Some examples:
PRINT "StrComp test."
PRINT STR$(STRCOMP("False","FALSE",0))
PRINT STR$(STRCOMP("Turkey","Monkey",0))
PRINT STR$(STRCOMP("Animal","Weasel",0))
Linux711 I'll add your suggestion to my list of apps to try. So now my list has:
1. QB64
2. Visual Basic
3. FreeBasic
FWIW your budget program works fine in QB64 as well. QB64 is available
here