Click to See Complete Forum and Search --> : Getting Command Buttons To perform different subs depending on form state


Tim
March 24th, 1999, 01:01 AM
Hi:


big time newbie, here.

I have a simple form with a label on it.

I have two command buttons. One is captioned yes and the other no.

Basically, I'm changing the label caption to a question.

The client clicks yes or no, then the label caption is changed.

The client clicks yes or no, and another caption is passed to the label.

This process continues, but does not repeat, as the more questions are asked, I need to know the path of yes's and no's followed to know which captions to pass to the labels. (hope that makes some kind of sense).

Basically, i want to know how to manipulate a command button so that i can get it to call different subroutines based on client choices during runtime.

thanks a lot,

Tim

Brian
March 24th, 1999, 05:14 PM
Although I think that there's a better way to deal with a sequence of questions, I believe the following code answers your question:


Option Explicit


Dim sQuestions(1 To 5) As String

Dim iQuestion As Integer


Private Sub Form_Load()

For iQuestion = LBound(sQuestions) To UBound(sQuestions)

'Put some code here to load the array of questions

sQuestions(iQuestion) = "..."

Next



'Display first question

iQuestion = LBound(sQuestions)

lblQuestion.Caption = sQuestions(iQuestion)

End Sub


Private Sub cmdNo_Click()

Debug.Assert (iQuestion >= LBound(sQuestions)) _

And (iQuestion = LBound(sQuestions)) _

And (iQuestion <= UBound(sQuestions))

Select Case iQuestion

Case 1: Call Q1_Yes

Case 2: Call Q2_Yes

Case 3: Call Q3_Yes

Case 4: Call Q4_Yes

Case 5: Call Q5_Yes

End Select



Call NextQuestion

End Sub


Private Sub NextQuestion()

iQuestion = iQuestion + 1

If iQuestion <= UBound(sQuestions) Then

lblQuestion.Caption = sQuestions(iQuestion)

Else

'All done, unload the form or do whatever when all

' questions have been answered

End If

End Sub


Private Sub Q1_No()

'

End Sub


Private Sub Q2_No()

'

End Sub


Private Sub Q3_No()

'

End Sub


Private Sub Q4_No()

'

End Sub


Private Sub Q5_No()

'

End Sub


Private Sub Q1_Yes()

'

End Sub


Private Sub Q2_Yes()

'

End Sub


Private Sub Q3_Yes()

'

End Sub


Private Sub Q4_Yes()

'

End Sub


Private Sub Q5_Yes()

'

End Sub


Hope this helps.


Brian