Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
passing values to other sheets | New Users to Excel | |||
Passing values in Sheet to VBA | Charts and Charting in Excel | |||
Passing Values to Function | Excel Programming | |||
Passing values between 2 subs ? | Excel Programming | |||
passing values from one sheet to another | Excel Programming |