using functions

S

Sanjay

Hi,

I'm trying to undertand hpw to return a value from another function, when I
run the mtest function I receive an error for the MsgBox (IsValidType) how I
can I return a value?

Thanks!


Private Function IsValidType(ByVal sString) As String
If LCase(sString) = "standard" Then
IsValidType = "SomethingA"
Else
IsValidType = "SomethingB"
End If
End Function


Sub mtest()
myvar = "standarda"
IsValidType myvar
MsgBox (IsValidType)
End Sub
 
N

Norman Jones

Hi Sanjay,

Try something like:

'=============>>
Public Sub mTest()
Dim res As Variant
Dim myVar As String

myVar = "standarda"
res = IsValidType(myVar)
MsgBox res
End Sub

'-------------->>
Private Function IsValidType(ByVal sString) As String
If LCase(sString) = "standard" Then
IsValidType = "SomethingA"
Else
IsValidType = "SomethingB"
End If
End Function
'<<=============
 
R

RB Smissaert

Try this:

Private Function IsValidType(sString As String) As String

If LCase(sString) = "standard" Then
IsValidType = "SomethingA"
Else
IsValidType = "SomethingB"
End If

End Function

Sub mtest()

Dim myvar As String

myvar = "standarda"

MsgBox IsValidType(myvar)

End Sub

Best is to put Option Explicit at the top of every module as that will force
you to declare
your variables. And do in the VBE: Tools, Options, Editor, tick Require
variable declaration.

RBS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top