2
' Gambas class file
' Math Drill by William Teder. Feel free to use parts of the code, but please give me credit.
' Declare Variables
' Define number of times user has pressed the Give Up button
PRIVATE givenuptimes AS Integer
' Define how many questions the user has answered
PRIVATE questionsanswered AS Integer
' Define what level the user is on
PRIVATE level AS Integer
' Define the number of points the user has
PRIVATE points AS Integer
' Define whether ot not addition, subtraction, multiplication, and division are enabled. This value is changed whrn the textboxes are togglrd.
PRIVATE additionenabled AS Boolean
PRIVATE subtractionenabled AS Boolean
PRIVATE multiplicationenabled AS Boolean
PRIVATE divisionenabled AS Boolean
'Set an integer for counting the number of times the program resets, for use in email.
PRIVATE resetcount AS Integer
' Define variable to help in detrmining the problem type
PRIVATE problemtype AS Integer
' Define number of numbers to add when using an addition problem
PRIVATE currentproblem AS String
PRIVATE currentanswer AS String
PRIVATE currentproblempointvalue AS Integer
PRIVATE add1 AS Integer
PRIVATE add2 AS Integer
PUBLIC SUB Form_Open()
'Set inital values

givenuptimes = 0
questionsanswered = 0
level = 1
points = 0
additionenabled = TRUE
subtractionenabled = TRUE
multiplicationenabled = TRUE
divisionenabled = TRUE
' GET RID OF THE FOLLOWING LINE WHEN USED IN BUILDING OR THE PROGRAM WILL NOT WORK!
' currentanswer = 0
makeproblem()

END

PUBLIC SUB btnClearAnswer_Click()
 'clear the contents of txtAnswer and give it the focus
  txtAnswer.Text = ""
  txtAnswer.SetFocus
END

PUBLIC SUB chkGiveUp_Click()

  ' Check to see if the Give Up button's visible property is set to true, and if it is, hide the button. If it is hidden, show it again.

IF btnGiveUp.Visible = FALSE THEN 
  btnGiveUp.visible = TRUE
      lblhGiveUp.visible = TRUE
  lblGivenUp.visible = TRUE
  expSettings.Raise
    RETURN 
END IF

IF btnClearAnswer.Visible THEN
  btnGiveUp.Visible = FALSE
    lblGivenUp.Visible = FALSE
      lblhGiveUp.Visible = FALSE
        expSettings.Raise
  RETURN  
END IF

END

PUBLIC SUB btnGiveUp_Click()
'Increment the counter that shows the number pf times the user has given up by 1
  givenuptimes = givenuptimes + 1
  lblGivenUp.Text = givenuptimes
  'Display the right answer
  txtAnswer.Text = currentanswer
  WAIT 2
  txtAnswer.Text = ""
  points = points - 10
  lblPoints.Text = points
  makeproblem()


END

PUBLIC SUB chkLevels_Click()

  ' Check to see if the Level label's visible property is set to true, and if it is, hide the label. If it is hidden, show it again.

IF lblLevel.Visible = FALSE THEN 
  lblhLevel.Visible = TRUE
      lblLevel.visible = TRUE
          'Move the answered section down one place, if it is not already
    lblhAnswered.Top = 150
    lblAnswered.Top = 143
      'For some odd reason, when the new objects appear they move themselves forward. Re-lowering the Settings container fixes this.
          IF lblGivenUp.Visible = FALSE OR lblAnswered.Visible = TRUE THEN

        lblhGiveUp.Top = 200
    lblGivenUp.Top = 193
    END IF
  expSettings.Raise
    RETURN 
END IF

IF lblLevel.Visible THEN
  lblLevel.Visible = FALSE
    lblhLevel.Visible = FALSE
    'Move the answered section up one place
    lblhAnswered.Top = 105
    lblAnswered.Top = 98
    'Check to see if the GiveUp section needs to be moved
    IF lblGivenUp.Visible = TRUE AND lblhLevel.Visible = FALSE THEN

        lblhGiveUp.Top = 150
    lblGivenUp.Top = 143
    END IF
        'See above comment
        expSettings.Raise
  RETURN  
END IF


END

PUBLIC SUB btnReset_Click()
' Notify user the program is working 
lblProblem.Text = "Resetting, please wait..."
'First, reset variables
givenuptimes = 0
questionsanswered = 0
level = 1
points = 0
'Clear the answer textbox.
txtAnswer.Text = ""
'Next, clear interface.
lblAnswered.Text = "0"
lblLevel.Text = "0"
lblPoints.Text = "0"
lblGivenUp.Text = "0"
' Notify user that the reset has finished and that the program is generating a new problem
lblProblem.Text = "Reset complete, generating new problem..."
makeproblem()


END

' These four subs are the same code with different variables. Changes state of variable the checkbox is assigned to, makes it the opposite of it's current state.
PUBLIC SUB chkAddition_Click()
IF divisionenabled = FALSE AND subtractionenabled = FALSE AND multiplicationenabled = FALSE THEN 
PRINT Message("You must select at least one option.")
additionenabled = TRUE
chkAddition.Value = TRUE
RETURN
END IF
' Set the boolean additionenabled to be true or false based on it's current state
  IF additionenabled = TRUE THEN 
  additionenabled = FALSE
  RETURN 
  END IF

  IF additionenabled = FALSE THEN 
  additionenabled = TRUE
  RETURN 
  END IF

END

PUBLIC SUB chkSubtraction_Click()
IF additionenabled = FALSE AND divisionenabled = FALSE AND multiplicationenabled = FALSE THEN 
PRINT Message("You must select at least one option.")
subtractionenabled = TRUE
chkSubtraction.Value = TRUE
RETURN
END IF
  ' Set the boolean subtractionenabled to be true or false based on it's current state
  IF subtractionenabled = TRUE THEN 
  subtractionenabled = FALSE
  RETURN 
  END IF

  IF subtractionenabled = FALSE THEN 
  subtractionenabled = TRUE
  RETURN 
  END IF

END

PUBLIC SUB chkMultiplication_Click()
IF additionenabled = FALSE AND subtractionenabled = FALSE AND divisionenabled = FALSE THEN 
PRINT Message("You must select at least one option.")
multiplicationenabled = TRUE
chkMultiplication.Value = TRUE
RETURN
END IF
  ' Set the boolean multiplicationenabled to be true or false based on it's current state
  IF multiplicationenabled = TRUE THEN 
  multiplicationenabled = FALSE
  RETURN 
  END IF

  IF multiplicationenabled = FALSE THEN 
  multiplicationenabled = TRUE
  RETURN 
  END IF

END

PUBLIC SUB chkDivision_Click()

IF additionenabled = FALSE AND subtractionenabled = FALSE AND multiplicationenabled = FALSE THEN 
PRINT Message("You must select at least one option.")
divisionenabled = TRUE
chkDivision.Value = TRUE
RETURN
END IF
  ' Set the boolean divisionenabled to be true or false based on it's current state
  IF divisionenabled = TRUE THEN 
  divisionenabled = FALSE
  RETURN 
  END IF

  IF divisionenabled = FALSE THEN 
  divisionenabled = TRUE
  RETURN 
  END IF

END

' Subroutine to make a problem
SUB makeproblem()
' This is the code that determines a new problem for the user based on a number of factors, including how many problems of that type they have done,
' whether or not the type is enabled or disabled, how quickly they can answer the question, thier points and level, and how many times they have
' given up on that type of problem. The rest is random. DO NOT MESS WITH THIS CODE UNLESS YOU KNOW WHAT YOU ARE DOING! It is very easy to mess up the program,
' as well as generate stack overflow errors.
' Engine version : 0.0.0.1
' Engine by William Teder
'  ------------------------------------
' Generates a random number for the Problem Type, 1 - 4
problemtype = Rnd(1, 5)
IF problemtype = 1 THEN 
' Problem Type: Addition
lblProblem.Text = "Problem Type: Addition"
' Determine the number of numbers to add together
IF level <= 5 THEN 
' Determine how high the number should be
IF points <= 200 THEN 
add1 = Rnd(1, 10)
add2 = Rnd(1, 10)
currentanswer = add1 + add2
currentproblem = add2 & " + " & add1
lblProblem.Text = currentproblem
RETURN
END IF
IF points > 200 AND < 400 THEN 
add1 = Rnd(1, 20)
add2 = Rnd(1, 20)
add1 + add2 = currentanswer
currentproblem = add2 & " + " & add1
lblProblem.Text = currentproblem
RETURN
END IF
IF points > 400 AND < 500 THEN 
add1 = Rnd(1, 30)
add2 = Rnd(1, 30)
add1 + add2 = currentanswer
currentproblem = add2 & " + " & add1
lblProblem.Text = currentproblem
RETURN
END IF
END IF
IF level <= 10 AND >= 6 THEN 
' Code for three numbers
END IF
IF level <= 15 AND >= 11 THEN 
'Code for 4 numbers
END IF
IF level <= 20 AND >= 16 THEN 
' Code for 5 numbers
END IF

IF problemtype = 2 THEN 
' Problem Type: Subtraction
lblProblem.Text = "Problem Type: Subtraction"
END IF

IF problemtype = 3 THEN 
' Problem Type: Multiplication
lblProblem.Text = "Problem Type: Multiplication"
END IF

IF problemtype = 4 THEN 
' Problem Type: Division
lblProblem.Text = "Problem Type: Division"
END IF

END

PUBLIC SUB gotright()
  ' Increment questions answered counter
  questionsanswered = questionsanswered + 1
  ' Increment Points
  points = points + currentproblempointvalue
  ' For every 100 points, increment the level counter by 1.
  IF level = 1 AND points = 200 THEN level = 2
  IF level = 2 AND points = 300 THEN level = 3
  IF level = 3 AND points = 400 THEN level = 4
  IF level = 4 AND points = 500 THEN level = 5
  IF level = 5 AND points = 600 THEN level = 6
  IF level = 6 AND points = 700 THEN level = 7 
  IF level = 7 AND points = 800 THEN level = 8
  IF level = 8 AND points = 900 THEN level = 9
  IF level = 9 AND points = 1000 THEN level = 10
  IF level = 10 AND points = 1100 THEN level = 11
  IF level = 11 AND points = 1200 THEN level = 12
  IF level = 12 AND points = 1300 THEN level = 13
  IF level = 13 AND points = 1400 THEN level = 14
  IF level = 14 AND points = 1500 THEN level = 15
  IF level = 15 AND points = 1600 THEN level = 16
  IF level = 16 AND points = 1700 THEN level = 17
  IF level = 17 AND points = 1800 THEN level = 18
  IF level = 18 AND points = 1900 THEN level = 19
  IF level = 19 AND points = 2000 THEN level = 20
  ' Change font color of the textbox to green to let the user know he/she got the problem right
  txtAnswer.Foreground = &H579524&
  ' Create delay to let the user know they got the answer right
  WAIT 1
  ' Change back to regular color
  txtAnswer.Foreground = &HFF004&
END

PUBLIC SUB txtAnswer_KeyRelease()


  IF txtAnswer.Text = currentanswer THEN 
    txtAnswer.Foreground = &H579524&
  questionsanswered = questionsanswered + 1
  lblAnswered.Text = questionsanswered
  WAIT 0.25
  txtAnswer.Text = ""
    ' Change back to regular color
  txtAnswer.Foreground = &HFF0004&
  lblPoints.text = points
  makeproblem()
  END IF

END



PUBLIC SUB Button1_Click()

  makeproblem()

END

251行目に、予期しない>があります。なぜコンパイルに失敗するのですか?ありがとう。

4

1 に答える 1

4
IF points > 400 AND < 500 THEN

あなたのBASICが本当に進んでいない限り、それは私にはまったく正しく見えません(そして GAMBASはそれほど進んでいないようです)。そのはず:

IF points > 400 AND points < 500 THEN

あなたはこの行で正しい考えを持っています、例えば:

IF lblGivenUp.Visible = TRUE AND lblhLevel.Visible = FALSE THEN

これのすべてのバリエーションについて同じですが、の右側にも変数を含める必要がありますand):

IF points > 200 AND < 400 THEN 
IF points > 400 AND < 500 THEN 
IF level <= 10 AND >= 6 THEN 
IF level <= 15 AND >= 11 THEN 
IF level <= 20 AND >= 16 THEN 
于 2012-04-04T22:40:28.990 に答える