Calling a function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi ! I am trying to call a function in a sub. However there is some error,
Compilation error, sub function or property expected. What am I doing wrong?

In the sub:

StrikePrice (secID)

.....and the function
Public Function StrikePrice(secID As String) As String
secID = Split(secID, " ")(1)
If InStr(secID, "C") Then
secID = Split(secID, "C")(1)
Else
If InStr(secID, "P") Then
secID = Split(secID, "P")(1)
Else
MsgBox "Error"
End If
End If
StrikePrice = secID
End Function
 
Works for me...

Sub test()
Dim str As String

str = StrikePrice("Puppy Cat Dog")
End Sub

Public Function StrikePrice(secID As String) As String
secID = Split(secID, " ")(1)
If InStr(secID, "C") Then
secID = Split(secID, "C")(1)
Else
If InStr(secID, "P") Then
secID = Split(secID, "P")(1)
Else
MsgBox "Error"
End If
End If
StrikePrice = secID
End Function

The one thing that I notice is that your function returns a string but in
the code you posted you were not assigning the return value "StrikePrice
(secID)"
 
By doing that the function will just return a variant. Generally not a good
idea unless you mean to return a variant. Additionally I fail to see how that
will resolve the issue.
 
While your solution will resove the error, it will (I believe based on the
code posted) cause the function to do nothing truely productive. It is a true
function in that it just returns a value without changing anything else. If
Arne does not capture the return value then what was the point of calling the
function.
 
Scratch that last post... SecId is passed by Ref and not by Value. SecId will
change... Time for me to get another cup of coffee. :-)
 
Back
Top