QB scoring problem

Started by
5 comments, last by Daerax 19 years ago
Here is my source: ( If any HTML shows, ignore it.) <htmL> <body> <title> QB Help</title> "CLS DIM score$ PRINT" Welcome to TS2Trivia/TS2U Trivia .47!" INPUT " Whate website can you get TheSims2 Enhancer from "; TS2E$ ' Select the variable SELECT CASE TS2$ CASE "sims2programs.com" LOCATE 12, 16 PRINT "SCORE:"; PRINT score$ + "1" END SELECT Then I add another question but when I answer correct it is still 1. Do I need to make an array? What can I do? Please help." </html> </body>
My friend wants to learn to program in C++. If he forgets BASIC right away, well, I am worried.
Advertisement
Quote:Original post by fuchu
INPUT " Whate website can you get TheSims2 Enhancer from "; TS2E$
SELECT CASE TS2$


Shouldn't TS2$ be TS2E$?

This is one of the(many) problems with QB. You can just create variables anywhere so typos then go unnoticed.
Well that isn't exactly the main one. But no, I know that wasn't my problem. Thanks.
My friend wants to learn to program in C++. If he forgets BASIC right away, well, I am worried.
You know, you can specify OPTION EXPLICIT in QB so that you have to declare variables before you use them. Here's an example:
'beginning of programprint "this is a variable", x

That is perfectly valid QB(and FB) code, but x will always be 0 unless you initialize it. However, if you want to use OPTION EXPLICIT, you cannot use a variable without declaring it first. So, this:
option explicit'beginning of programprint "this is a variable", x

would be invalid and you would get an error. You would have to make it this:
option explicitdim x as integer x = 0'beginning of programprint "this is a variable", x

for that to work. So that's one remedy for a QB problem.
I remember the option explicit command from php, which I stilll need to learn better. I hope that helped me. Thanks.
My friend wants to learn to program in C++. If he forgets BASIC right away, well, I am worried.
PRINT "SCORE:"; PRINT score$ + "1"

The above line doesn't actually increment the score$ variable. To actually increment the variable, you should type:

PRINT "SCORE:"
score$ = score$ + 1
PRINT score$

In your code, you only printed score$ + "1" to the screen (you probably meant score$ + 1), but you did not store the result anywhere.
h20, member of WFG 0 A.D.
As pointed out by mnangsar, since score$ is initialized to "" , you were outputting "" + "1" or "1" everytime. Also however, note that in QB having the '$' sign at the end of a variable designates it as a string. So even score$= score$ + 1 would leave you with unwonted results, youd get "111111..." for however many times you concatenate 1 to your string. You need to hold your score with an integer and display that.
CLSDIM score% 'dim score as integerPRINT" Welcome to TS2Trivia/TS2U Trivia .47!"INPUT " Whate website can you get TheSims2 Enhancer from "; TS2E$' Select the variableSELECT CASE TS2E$CASE "sims2programs.com"   score% = score% + 1   LOCATE 12, 16   PRINT "SCORE:"; score% END SELECT

This topic is closed to new replies.

Advertisement