help calling function!!!!! novice

P

pino

I really dont understand why I cannot pass the vector rstar in the function
forward...it gives me #value!!!!!!!!!!
The input of the function forward is a vector of the same dimension of
rstar!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Option Base 1
Function swap(r As Variant, date_pay As Variant)
Dim fw() As Variant
Dim rstar() As Variant

n = date_pay.Rows.Count
ReDim rstar(n, 2)
ReDim fw(n, 1)

rstar = interpolated_yield_curve(r, date_pay)

fw = forward(rstar)


swap=fw

If I use just::
fw = forward(r)
swap=fw

OR

rstar=interpolated_yield_curve(r, date_pay)

swap=rstar


it works sigularly so the function are right, but i can pass the input of
the first in the other.!

why??


thank a lot!
 
D

Devin Linnington

I'm a novice at this too but I do remember something about parameter arrays,
and I think that is what you need to use (please correct me if I'm wrong
here). Type this in help and press on the first thing that comes up, I
*think* it may help:

Understanding Parameter Arrays

And don't hate me if that doesn't help much :p
 
P

Pino

I really dont understand the help :-(
Consider this example. Here, the function thirdsecond_pow does not work
Can you help me more?

Option Base 1
Function thirdsecond_pow(s As Variant)


Dim w(), q()
n = s.Rows.Count

ReDim w(n, 1), q(n, 1)


q = second_pow(s)
w = third_pow(q)



thirdsecond_pow = w


End Function


Function second_pow(s As Variant)

Dim w()
n = s.Rows.Count
ReDim w(n, 1)




For i = 1 To n
w(i, 1) = s(i) ^ 2
Next i

second_pow = w


End Function

Function third_pow(s As Variant)

Dim w()
n = s.Rows.Count



ReDim w(n, 1)
For i = 1 To n
w(i, 1) = s(i) ^ 3
Next i

third_pow = w


End Function

thank you

Devin Linnington ha scritto:
 
D

Devin Linnington

Ah ha! After some figuring, I think I got it down to what you wanted. Don't
use paramarray for functions that are returning values, instead look at the
code below and figure out what I did (hard to remember). I would suggest you
open the immediate window (ctrl+g) and then hit F8 continuously to go through
the code step by step. This does work, I've already tested it. You're
welcome!!




Option Base 1
Sub main()

Dim s(3) As Variant 'sample "s"
s(1) = 1
s(2) = 2
s(3) = 3

Debug.Print s(1), s(2), s(3) ' open immediate window to view
' these values (ctrl+G) during execution

n = UBound(s) ' defined in "thirdsecond_pow" again, can be passed
' to it by first declaring it as an integer
Debug.Print n

a = thirdsecond_pow(s)

Debug.Print a(1, 1), a(2, 1), a(3, 1)

End Sub
Function thirdsecond_pow(s() As Variant)

Debug.Print s(1), s(2), s(3)

Dim w(), q()
Dim n As Integer
' n = s.Rows.Count <== it's this function that does not work
' as it only works with range selections
n = UBound(s) ' returns # of 'rows' (or first dimention)
Debug.Print n

ReDim w(n, 1), q(n, 1)

q = second_pow(n, s) ' passed "n" for convienience
Debug.Print q(1, 1), q(2, 1), q(3, 1) ' note that after you redim "w(n,1)"
in
' "second_pow" you have to make "q(1)"
' "q(1,1)" instead
w = third_pow(n, q)
Debug.Print w(1, 1), w(2, 1), w(3, 1)

thirdsecond_pow = w

End Function
Function second_pow(n, s() As Variant)

Debug.Print n
ReDim w(n, 1)

For i = 1 To n
w(i, 1) = s(i) ^ 2
Debug.Print w(i, 1), s(i)
Next i

second_pow = w()


End Function
Function third_pow(n, s() As Variant)

Debug.Print n
ReDim w(n, 1)

For i = 1 To n
w(i, 1) = s(i, 1) ^ 3
Debug.Print w(i, 1), s(i, 1)
Next i

third_pow = w()


End Function
 
P

Pino

Thank you very much!
I find a simple solution! I was calling thirdsecond_pow(s() As Variant)
selecting a range on the sheet1.
So there was a type mismatch!
Now set thirdsecond_pow(s as range) and after i declare a variant A
and use the command A=s.
Now s can be applied to all the function.
Of course there was the error of the Ubound ...

Regards



Devin Linnington ha scritto:
 
P

Pino

Thank you very much!
I find a simple solution! I was calling thirdsecond_pow(s() As Variant)
selecting a range on the sheet1.
So there was a type mismatch!
Now set thirdsecond_pow(s as range) and after i declare a variant A
and use the command A=s.
Now s can be applied to all the function.
Of course there was the error of the Ubound ...

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top