G
Guest
I have a function that prompts the user to enter a week number. Control then passes back to to another function that gets the appropriate info for that week. My problem is in checking the week number the user inputs is valid (whole number between 1 and 20 inclusive). I'm doing something wrong in the first Case (see below) Here is the function:
Function GetWeek() As Variant
Dim Answer As Variant
Begin:
Answer = Application.InputBox(prompt:="Enter Week # to change. Hit cancel" _
& " when done.", Type:=1)
If TypeName(Answer) = "boolean" Then
If ConfirmExit = True Then GetWeek = False
Else
Select Case Answer
Case Is > Application.WorksheetFunction.Round(Answer, 0)
'problem is here
MsgBox "You must enter a whole number."
GoTo Begin
Case Is < 1, Is > 20
MsgBox "You must choose a number between 1 and 20"
GoTo Begin
Case Else
GetWeek = Answer
End Select
End If
End Function
Is putting a function call inside a Case test legal? Do i need to do the check outside of the Case (assigning the result to a variable) then check 'answer' against that variable?
Function GetWeek() As Variant
Dim Answer As Variant
Begin:
Answer = Application.InputBox(prompt:="Enter Week # to change. Hit cancel" _
& " when done.", Type:=1)
If TypeName(Answer) = "boolean" Then
If ConfirmExit = True Then GetWeek = False
Else
Select Case Answer
Case Is > Application.WorksheetFunction.Round(Answer, 0)
'problem is here
MsgBox "You must enter a whole number."
GoTo Begin
Case Is < 1, Is > 20
MsgBox "You must choose a number between 1 and 20"
GoTo Begin
Case Else
GetWeek = Answer
End Select
End If
End Function
Is putting a function call inside a Case test legal? Do i need to do the check outside of the Case (assigning the result to a variable) then check 'answer' against that variable?