PC Review


Reply
Thread Tools Rate Thread

Calling a function

 
 
=?Utf-8?B?QXJuZSBIZWdlZm9ycw==?=
Guest
Posts: n/a
 
      8th Nov 2007
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 With Quote
 
 
 
 
Ian
Guest
Posts: n/a
 
      8th Nov 2007
Remove As String from the end of the Public Function line.

Ian

"Arne Hegefors" <(E-Mail Removed)> wrote in message
news:4AF5EEB8-8AC0-4CE6-9950-(E-Mail Removed)...
> 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 With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      8th Nov 2007
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
 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      8th Nov 2007
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 With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      8th Nov 2007
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" <(E-Mail Removed)> wrote in message
> news:4AF5EEB8-8AC0-4CE6-9950-(E-Mail Removed)...
> > 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 With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      8th Nov 2007
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
>

 
Reply With Quote
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      8th Nov 2007
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
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method of calling a function where function name is stored in a variable or control Tony Vrolyk Microsoft Access VBA Modules 9 12th Jul 2007 07:20 PM
Method of calling a function where function name is stored in a variable or control Bob Quintal Microsoft Access 2 11th Jul 2007 08:49 PM
Calling EXE Function Getting handle to calling exe Abhishek Microsoft VC .NET 1 25th Sep 2006 01:58 PM
Calling managed function from unmanaged function in mixed mode dll slugster@gmail.com Microsoft VC .NET 1 25th Jul 2005 07:30 AM
Calling DoCmd.RunCommand acCmdSaveRecord, after calling an API function Savvoulidis Iordanis Microsoft Access Form Coding 2 19th Mar 2005 06:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:17 PM.