Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Passing Values Syntax

I'm trying to create a tool that values various stock option
positions. I want to read in option values (the strike and cost) and
pass that information into prodcedures that calculate and graph the
payoff.

I'm having trouble passing the information from procedure to
procedure. A bit of pseudo-code might help:

Sub BullSpread()
GetPrices(strike1,strike2,cost1,cost2)
if strike1<shareprice then
blah blah
endif
.....
end sub

sub getprices()
strike1=range("A1")
strike2=range("B1")
......
end sub

I can't seem to get the GetPrices routine to pass the bits of info -
debugging shows the variables as "empty". I can't seem to figure out
what goes in the parentheses when calling/returning.

Thanks for any help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Passing Values Syntax

You can Dim your varialbes in the Declarations arrear of the module as shown. This should then work for you. Step through the code and you will see x change to the appropriate value after each line is read.

Dim strike1, strike2, cost1, cost2

Sub BullSpread()
GetPrices
x = strike1
x = strike2
x = cost1
x = cost2

End Sub

Sub GetPrices()
strike1 = 1 ' Range("A1")
strike2 = 2 ' Range("B1")
cost1 = 3
cost2 = 4
End Function

TerryK


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Passing Values Syntax

Chuck,

Firstly, add Option Explicit to the top of your code module. Then make sure
you declare your variables. Your code should look something like this

Sub BullSpread()
Dim SharePrice as Double
SharePrice = GetPrices(Range("A1"),Range("B1"),Range("C1"),Rang e("D1")
if Range("A1") < Shareprice then
blah blah
endif
......
end sub

sub getprices(strike1 as double, strike2 as double, cost1 as double, codt2
as double)
.......
end sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Chuck Taylor" wrote in message
...
I'm trying to create a tool that values various stock option
positions. I want to read in option values (the strike and cost) and
pass that information into prodcedures that calculate and graph the
payoff.

I'm having trouble passing the information from procedure to
procedure. A bit of pseudo-code might help:

Sub BullSpread()
GetPrices(strike1,strike2,cost1,cost2)
if strike1<shareprice then
blah blah
endif
.....
end sub

sub getprices()
strike1=range("A1")
strike2=range("B1")
......
end sub

I can't seem to get the GetPrices routine to pass the bits of info -
debugging shows the variables as "empty". I can't seem to figure out
what goes in the parentheses when calling/returning.

Thanks for any help.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Passing Values Syntax

Bob,
I agree the arguments of GetPrices should be ByRef but I think
BullSpread should be passing (empty) variables for GetPrices to fill.
And you do realise that your getprices sub isn't returning a value to
the Shareprice variable, right?

I think this is what's required:

Sub BullSpread()

Dim strike1 As Double, strike2 As Double, cost1 As Double, cost2 As
Double

GetPrices strike1, strike2, cost1, cost2

If strike1<shareprice Then
' blah blah
End If

End Sub

Sub GetPrices (ByRef strike1 As Double, ByRef strike2 As Double, _
ByRef cost1 As Double, cost2 As Double)

strike1 = Range("A1").Value
strike2 = Range("B1").Value
cost1 = Range("C1").Value
codt2 = Range("D1").Value

End Sub

--

"Bob Phillips" wrote in message ...
Chuck,

Firstly, add Option Explicit to the top of your code module. Then make sure
you declare your variables. Your code should look something like this

Sub BullSpread()
Dim SharePrice as Double
SharePrice = GetPrices(Range("A1"),Range("B1"),Range("C1"),Rang e("D1")
if Range("A1") < Shareprice then
blah blah
endif
.....
end sub

sub getprices(strike1 as double, strike2 as double, cost1 as double, codt2
as double)
......
end sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Chuck Taylor" wrote in message
...
I'm trying to create a tool that values various stock option
positions. I want to read in option values (the strike and cost) and
pass that information into prodcedures that calculate and graph the
payoff.

I'm having trouble passing the information from procedure to
procedure. A bit of pseudo-code might help:

Sub BullSpread()
GetPrices(strike1,strike2,cost1,cost2)
if strike1<shareprice then
blah blah
endif
.....
end sub

sub getprices()
strike1=range("A1")
strike2=range("B1")
......
end sub

I can't seem to get the GetPrices routine to pass the bits of info -
debugging shows the variables as "empty". I can't seem to figure out
what goes in the parentheses when calling/returning.

Thanks for any help.

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
passing values to other sheets [email protected] New Users to Excel 1 February 23rd 08 02:03 AM
Passing values in Sheet to VBA Jonathan Charts and Charting in Excel 1 June 30th 06 06:00 AM
Passing Values to Function Newbie Excel Programming 2 January 8th 04 06:01 PM
Passing values between 2 subs ? [email protected] Excel Programming 1 November 21st 03 05:56 PM
passing values from one sheet to another BubBob[_2_] Excel Programming 1 September 4th 03 01:09 PM


All times are GMT +1. The time now is 07:56 PM.

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

About Us

"It's about Microsoft Excel"