Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Calling a function

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default Calling a function

Remove As String from the end of the Public Function line.

Ian

"Arne Hegefors" wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Calling a function

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.
--
HTH...

Jim Thomlinson


"Ian" wrote:

Remove As String from the end of the Public Function line.

Ian

"Arne Hegefors" wrote in message
...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Calling a function

Either drop the ()'s
StrikePrice SecID
or add Call
Call StrikePrice(SecID)



Arne Hegefors wrote:

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


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Calling a function

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.
--
HTH...

Jim Thomlinson


"Dave Peterson" wrote:

Either drop the ()'s
StrikePrice SecID
or add Call
Call StrikePrice(SecID)



Arne Hegefors wrote:

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


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Calling a 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. :-)
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

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.
--
HTH...

Jim Thomlinson


"Dave Peterson" wrote:

Either drop the ()'s
StrikePrice SecID
or add Call
Call StrikePrice(SecID)



Arne Hegefors wrote:

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


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Calling a 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)"
--
HTH...

Jim Thomlinson


"Arne Hegefors" wrote:

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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a function in my SQL-DB from VBA KSor Excel Discussion (Misc queries) 0 March 11th 09 02:08 PM
Help with calling a function CR[_4_] Excel Programming 5 May 23rd 06 03:38 PM
calling a function dmexcel Excel Programming 5 February 23rd 06 12:02 PM
Calling Function mattsvai[_18_] Excel Programming 4 February 13th 06 10:49 PM
calling a function praptisahni Excel Programming 2 April 26th 04 05:17 PM


All times are GMT +1. The time now is 12:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"