Saturday, March 10, 2007

Make it Simple

Some of the recursive functions seemed to be a little hard to debug so we are moving to a simple approach and then build complexity as needed.

Today we will start with simple code that will work something like this:

User clicks on next button.


Private Sub Command1_Click()
Static lClickNumber As Long

lClickNumber = lClickNumber + 1

'declare your varibles
Dim sDef1 As String
Dim sDef2 As String
'etc...

Select Case lClickNumber
Case 1
sWord = "House"
sDef = "A place to live."
sDef2 = "A color."
sDef3 = "An animal."
'etc...

Case 2
'etc....
Case 3
'etc...
End Select


Call WriteToRadios(lClickNumber, sWord, sDef, sDef2, sDef3, sDef4, sDef5)
End Sub

Private Function WriteToRadios(lClickNumber As Long, sWord As String, sDef1 As String, sDef2 As String, sDef3 As String, sDef4 As String, sDef5 As String)
'inside this sub will be something like:
label1.Text = sWord
radiobutton1.Text = sDef
'etc....
End Function

2 comments:

PhillipsInChina said...

Also we will need to declare a variable to keep the correct answer and compare it with what the user selected.

A module level variable. Something like this:

Private m_sCorrectAnswer as string

PhillipsInChina said...

Also we should create a function that will check to see if the user click on the correct answer.

Private Function IsAnswerCorrect() As Boolean

If m_sCorrectAnswer = m_sUserSelectedAnswer Then

IsAnswerCorrect = True
Else
IsAnswerCorrect = False
End If

End Function

'You can tell from the above fuction that we need a module level variable named m_sUserSelectedAnswer

'Also in the click event for each radiobutton we should set the value of m_sUserSelectedAnswer equal to the text of the radiobutton.