J
James
Hello,
I hope some one can please help me with returning a string from a function
back to a label on a form?
I have a document that has several OptionButtons on it that I use to help
test my grandson.
After I check the answers I put, in a label, the words "You're Correct" or
Incorrect" in appropriate labels for the questions.
I can get the right string into the function, but I can't get anything back
Can some one show me how to do this?
Here is some code that sends the string to the function
'Begin Code========================================
If radSaveAs2.Value = -1 Then
Dim answer As String
intNumberCorrect = intNumberCorrect + 1 'Add one to the
correct answer total
CorrectMyAnswer ("Correct") 'Call
the function for correct
Else
CorrectMyAnswer ("Incorrect") 'Call the
function for incorrect
End If
lblSaveAsAnswer.Caption = CorrectMyAnswer(answer)
'End Code==========================================
'Function Code=======================================
Public Function CorrectMyAnswer(ByVal answer As String) As String
If answer = "Correct" Then
answer = "You're Correct"
Else
answer = "Sorry, Incorrect"
End If
End Function
'End Code===========================================
I know I could just code the lblSaveAsAnswer.Caption = "Correct" or
"Incorrect" for each one,
but I'm trying to learn how to do this so I can get better at Word VBA as I
go.
Thanks James
I hope some one can please help me with returning a string from a function
back to a label on a form?
I have a document that has several OptionButtons on it that I use to help
test my grandson.
After I check the answers I put, in a label, the words "You're Correct" or
Incorrect" in appropriate labels for the questions.
I can get the right string into the function, but I can't get anything back
Can some one show me how to do this?
Here is some code that sends the string to the function
'Begin Code========================================
If radSaveAs2.Value = -1 Then
Dim answer As String
intNumberCorrect = intNumberCorrect + 1 'Add one to the
correct answer total
CorrectMyAnswer ("Correct") 'Call
the function for correct
Else
CorrectMyAnswer ("Incorrect") 'Call the
function for incorrect
End If
lblSaveAsAnswer.Caption = CorrectMyAnswer(answer)
'End Code==========================================
'Function Code=======================================
Public Function CorrectMyAnswer(ByVal answer As String) As String
If answer = "Correct" Then
answer = "You're Correct"
Else
answer = "Sorry, Incorrect"
End If
End Function
'End Code===========================================
I know I could just code the lblSaveAsAnswer.Caption = "Correct" or
"Incorrect" for each one,
but I'm trying to learn how to do this so I can get better at Word VBA as I
go.
Thanks James