I am trying to assign a value to a variable by calling a function in my VBA code.
My subroutine body looks like this:
Sub testSubroutine()
Dim iVal As Integer
iVal = readSolOverviewTable("TOT_MAPS")
Debug.Print "Function readSolOverviewTable returned: " & iVal
End sub
The readSolOverviewTable function is returning correct value with in the function itself. I have verified it by debugging the function code.
But it seems there is some problem with the subroutine code as the following statement:
iVal = readSolOverviewTable("TOT_MAPS")
Always returns 0.
Am I doing something wrong?
Updated:
====================================
my function looked like this:
Function readSolOverviewTable(searchVal As String) As Integer
    Dim retVal As Integer
    retVal = -99
    ' Do some code and assign value to the variable retVal
    retVal = 100
    Debug.Print "retval is: " & retVal
End Function
As expected; this correctly shows the debug output as 100 However doesn't reflect in the subroutine call.
But changing the code to this made everything all right:
Function readSolOverviewTable(searchVal As String) As Integer
    Dim retVal As Integer
    retVal = -99
    ' Do some code and assign value to the variable retVal
    retVal = 100
    Debug.Print "retval is: " & retVal
    readSolOverviewTable = retVal
End Function
Now that I have resolved the problem (I hope), what is the reason and why this weird kind of syntax?
 
     
    