Link to home
Start Free TrialLog in
Avatar of paulwhelan
paulwhelan

asked on

VB - Beginners, why isnt value returned from function

I'm editing some code but this seems to give me
bErrors is .
ie it doesnt seem to return the value

Am I calling the function in the wrong way?

Thanks




Dim sErrorText, bErrors
sErrorText = DoErrorChecks()

response.Write "bErrors is " & bErrors & ".<br>"


Function DoErrorChecks()

bErrors=True

End Function
Avatar of AlfaNoMore
AlfaNoMore

Your Function should always returna value locally or explicitly referenced (i.e. within it's parameter list, not just defined within the page. Try this for correctness.

Dim sErrorText, bErrors
sErrorText = DoErrorChecks(bErrors)

Response.Write "sErrorText is " & sErrorText & ".<br>"   'Will be equal to "Some text to output from our Function"
Response.Write "bErrors is " & bErrors & ".<br>"            'Will be equal to True

Function DoErrorChecks(ByRef bErrors)

      bErrors=True

      DoErrorChecks = "Some text to output from our Function"

End Function
Hello
please specify the return type in the function as function always returns a value

Function DoErrorChecks() as Boolean

End Function

babuno5, VBscript (as used in asp classic) doesn't allow a function to be early bound as you suggested. If paulwhelan is using ASP.net or VB, then fine.
ASKER CERTIFIED SOLUTION
Avatar of sparkattack
sparkattack

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial