Case differantiation through Return Value of a function

Ben_Entrew

Registered User.
Local time
Today, 14:00
Joined
Dec 3, 2013
Messages
177
Dear all,

I would like to select a case depending on the output of a function.
This function tests the syntax of the reporting month.
If the syntax is fine nothing should be done further in the main sub else it should return to the Input window for the reporting month.
Somehow it doesn't work out.
Maybe someone out there has a clue?

Thanks in advance.

Regards,
Ben


Code:
Public Function RepMonthCheck(rep_date As String) as Boolean 
        If Len(rep_date) <> 6 Or Left(rep_date, 2) > 12 Or Left(rep_date, 2) < 1 Then 
        MsgBox ("Reporting rep_date is not in the correct format = mmyyyy") 
        Return False 
        ElseIf Right(rep_date, 4) > 9998 Then 
        MsgBox ("No forecast available for year 9998") 
        Return False
        Else 
        Return True
        End If 
         
End Function 
 
 
Sub IMPORT 
 
Dim repmonth As String 
Dim Test2 As Boolean 
NewEntry 
 
repmonth = InputBox("Please type in the reporting month", "Reporting_Month"e, "", 5000, 5000) 
 
RepMonthCheck (repmonth,Test2) 
 
    If Test2 = False Then 
    GoTo NewEntry 
    Else 
    End If 
 
End Sub
 
First thing I see is that you are passing it the wrong number of arguments. The function declaration says it has 1 argument:

Public Function RepMonthCheck(rep_date As String) as Boolean

But when you call it, you are passing it two arguments:

RepMonthCheck (repmonth,Test2)

Also, in IMPORT, you declare Test2 and test the value of Test2, but you never assign it a value.


Lastly, you've got an errant 'e' floating outside quote marks in this line:

repmonth = InputBox("Please type in the reporting month", "Reporting_Month"e, "", 5000, 5000)
 
Thanks for the hints.

I corrected this, however now it runs into a never ending loop, showing me the error message "Reporting rep_date is not in the correct format = mmyyyy"

Code:
Public Function RepMonthCheck(rep_date As String) as Boolean          

If Len(rep_date) <> 6 Or Left(rep_date, 2) > 12 Or Left(rep_date, 2) < 1 Then          

MsgBox ("Reporting rep_date is not in the correct format = mmyyyy")          

RepMonthCheck = False         

ElseIf Right(rep_date, 4) > 9998 Then          

MsgBox ("No forecast available for year 9998")          

RepMonthCheck = False         

Else          

RepMonthCheck = True         

End If           

End Function      


Sub IMPORT    

Dim repmonth As String  
Dim Test2 As Boolean  

NewEntry:   

repmonth = InputBox("Please type in the reporting month", "Reporting_Month", "", 5000, 5000)    

TEST2 = RepMonthCheck (repmonth)       

If Test2 = False Then      

GoTo NewEntry      

Else      

End If    

End Sub
 

Users who are viewing this thread

Back
Top Bottom