Hello to everybody,
I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know), but each answer is given a different point value for each question.
For instance, question 1 might ask "Do you like candy?" and if you answer Yes you will get +1, No will earn you -1, and Don't know will net you zero points. The next question might earn you -1 for Yes, +2 for No, and so on.
I would like to total the points for each section in a disabled, but visible textbox at the end of the 10 questions. Problem is, I'm fairly sure that using an if statement will make my already large form run very slowly. I'm leaning toward using a select case (or switch) statement, but I'm having some trouble initializing it and then deciding what it is I'm actually testing against.
Right now, and keep in mind that this is my most recent frustrated attempt, I have a select case statement with nested if statements, but I'm getting an error message that says "Case without Select Case."
[code=vb]
Private Sub CommandButton1_ Click()
Dim total As Integer 'declare an integer for total
total = 0 'initialize total equal to zero
Select Case total 'begin switch
Case 1
If Me.Yes1.Value = True Then 'if option button is true...
total = total + 1 'assign points to total
Else
total = total + 0 'otherwise assign no points
Case 2
If Me.Yes2.Value = True Then
total = total + 2
ElseIf Me.No2.Value = True Then
total = total - 1
Else: total = total + 0
Case 3
If Me.Yes3.Value = True Then
total = total + 1
Else
total = total + 0
Case 4
If Me.Yes4.Value = True Then
total = total + 2
ElseIf Me.No4.Value = True Then
total = total - 1
Else
total = total + 0
Case 5
If Me.Yes5.Value = True Then
total = total - 1
ElseIf Me.No5.Value = True Then
total = total + 2
Else
total = total + 0
Case 6
If Me.Yes6.Value = True Then
total = total - 1
ElseIf Me.No6.Value = True Then
total = total + 1
Else
total = total + 0
Case 7
If Me.Yes7.Value = True Then
total = total + 1
Else
total = total + 0
Case 8
If Me.Yes8.Value = True Then
total = total + 1
Else
total = total + 0
Case 9
If Me.Yes9.Value = True Then
total = total + 1
Else
total = total + 0
Case 10
If Me.Yes10.Value = True Then
total = total + 1
Else
total = total + 0
Case Default
total = 0
End Select
'Somewhere in here, print out total in the total textbox.
End Sub
[/code]
I have noticed that some of the questions, the ones that give the same point value for answers as other questions, could possibly be grouped together in a single case, but because the answers are grouped by question, I thought it best to include my code this way to make things clear.
Thanks for any help any of you can throw my way...beacon
I have a section on a form that has 10 questions, numbered 1-10, with 3 option buttons per question. Each of the option buttons have the same response (Yes, No, Don't know), but each answer is given a different point value for each question.
For instance, question 1 might ask "Do you like candy?" and if you answer Yes you will get +1, No will earn you -1, and Don't know will net you zero points. The next question might earn you -1 for Yes, +2 for No, and so on.
I would like to total the points for each section in a disabled, but visible textbox at the end of the 10 questions. Problem is, I'm fairly sure that using an if statement will make my already large form run very slowly. I'm leaning toward using a select case (or switch) statement, but I'm having some trouble initializing it and then deciding what it is I'm actually testing against.
Right now, and keep in mind that this is my most recent frustrated attempt, I have a select case statement with nested if statements, but I'm getting an error message that says "Case without Select Case."
[code=vb]
Private Sub CommandButton1_ Click()
Dim total As Integer 'declare an integer for total
total = 0 'initialize total equal to zero
Select Case total 'begin switch
Case 1
If Me.Yes1.Value = True Then 'if option button is true...
total = total + 1 'assign points to total
Else
total = total + 0 'otherwise assign no points
Case 2
If Me.Yes2.Value = True Then
total = total + 2
ElseIf Me.No2.Value = True Then
total = total - 1
Else: total = total + 0
Case 3
If Me.Yes3.Value = True Then
total = total + 1
Else
total = total + 0
Case 4
If Me.Yes4.Value = True Then
total = total + 2
ElseIf Me.No4.Value = True Then
total = total - 1
Else
total = total + 0
Case 5
If Me.Yes5.Value = True Then
total = total - 1
ElseIf Me.No5.Value = True Then
total = total + 2
Else
total = total + 0
Case 6
If Me.Yes6.Value = True Then
total = total - 1
ElseIf Me.No6.Value = True Then
total = total + 1
Else
total = total + 0
Case 7
If Me.Yes7.Value = True Then
total = total + 1
Else
total = total + 0
Case 8
If Me.Yes8.Value = True Then
total = total + 1
Else
total = total + 0
Case 9
If Me.Yes9.Value = True Then
total = total + 1
Else
total = total + 0
Case 10
If Me.Yes10.Value = True Then
total = total + 1
Else
total = total + 0
Case Default
total = 0
End Select
'Somewhere in here, print out total in the total textbox.
End Sub
[/code]
I have noticed that some of the questions, the ones that give the same point value for answers as other questions, could possibly be grouped together in a single case, but because the answers are grouped by question, I thought it best to include my code this way to make things clear.
Thanks for any help any of you can throw my way...beacon
Comment