Multiple Output from a Function giving zero

3PlankWalker

Board Regular
Joined
Sep 18, 2014
Messages
76
I have writen this code to give Multiple Output from a Function but its All the Values as zero,

Code:
Sub Trial()Dim X As Double, Y As Double
Dim LlByL As Double, BbByB As Double
Dim Trail1 As Double
For X = 0.1 To 1 Step 0.1
    For Y = 0.1 To 1 Step 0.1
    Trial1 = Case2(X, Y, LlByL, BbByB)
    Cells(Count + 1, Count2 + 1) = LlByL
    Cells(Count + 2, Count2 + 1) = BbByB
    Count2 = Count2 + 1
    Next
Count2 = 0
Count = Count + 2
Next
End Sub


Function Case2(ByVal X As Double, ByVal Y As Double, _
ByRef LlByL As Double, ByRef BbByB As Double) As Double
'Area = (1 - X * Y / 2) * (B * L)
Fgx = (3 - X ^ 2 * Y) / (6 - 3 * X * Y)
Fgy = (3 - X * Y ^ 2) / (6 - 3 * X * Y)
'CGX = Fgx * L
'CGY = Fgy * B
Fxi = 1 / 12 * (1 - X * Y ^ 3 / 3 + X * Y / 3 * (3 - 2 * Y) ^ 2 / (X * Y - 2))
Fyi = 1 / 12 * (1 - X ^ 3 * Y / 3 + X * Y / 3 * (3 - 2 * X) ^ 2 / (X * Y - 2))
Fxy = (Fgx - 1 / 2) * (Fgy - 1 / 2) + (X ^ 2 * Y ^ 2 / 72) - (X * Y / 2) * (Fgx - X / 3) * (Fgy - Y / 3)
'Ix = L * B ^ 3 * Fxi
'Iy = L ^ 3 * B * Fyi
'Ixy = B ^ 2 * L ^ 2 * Fxy
'Revised Eccentricty
Feccb = 1 / 2 - Fgy
Feccl = 1 / 2 - Fgx
'Erb = B * (Eb / B + Feccb)
'Erl = L * (El / L + Feecl)
'Relationship B/W El/L and Eb/B and Factors X and Y
P1 = (-Fxi * Fgx + Fxy * (Y - Fgy)) / (Fxi * Fyi - Fxy ^ 2)
Q1 = (Fyi * (Y - Fgy) - Fxy * Fgx) / (Fxi * Fyi - Fxy ^ 2)
R1 = Feccl * (-Fxi * Fgx + Fxy * (Y - Fgy)) / (Fxi * Fyi - Fxy ^ 2) + _
     Feccb * (Fyi * (Y - Fgy) - Fxy * Fgy) / (Fxi * Fyi - Fxy ^ 2) + _
     1 / (1 - X * Y / 2)
P2 = (Fxi * (X - Fgx) - Fxy * Fgy) / (Fxi * Fyi - Fxy ^ 2)
Q2 = (-Fyi * Fgy + Fxy * (X - Fgx)) / (Fxi * Fyi - Fxy ^ 2)
R2 = Feccl * (Fxi * (X - Fgx) - Fxy * Fgy) / (Fxi * Fyi - Fxy ^ 2) + _
     Feccb * (-Fyi * Fgy + Fxy * (X - Fgy)) / (Fxi * Fyi - Fxy ^ 2) + _
     1 / (1 - X * Y / 2)
ElByL = (Q1 * R2 - Q2 * R1) / (P1 * Q2 - P2 * Q1)
EbByB = (R1 * P2 - R2 * P1) / (P1 * Q2 - P2 * Q1)
End Function

I had Referred vba - Return multiple values from a function, sub or type? - Stack Overflow

Thanks
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I have writen this code to give Multiple Output from a Function but its All the Values as zero,

Code:
Function Case2(ByVal X As Double, ByVal Y As Double, _
ByRef [COLOR=#ff0000][B]LlByL[/B][/COLOR] As Double, ByRef [COLOR=#ff0000][B]BbByB[/B][/COLOR] As Double) As Double
'Area = (1 - X * Y / 2) * (B * L)
Fgx = (3 - X ^ 2 * Y) / (6 - 3 * X * Y)
Fgy = (3 - X * Y ^ 2) / (6 - 3 * X * Y)
'CGX = Fgx * L
'CGY = Fgy * B
Fxi = 1 / 12 * (1 - X * Y ^ 3 / 3 + X * Y / 3 * (3 - 2 * Y) ^ 2 / (X * Y - 2))
Fyi = 1 / 12 * (1 - X ^ 3 * Y / 3 + X * Y / 3 * (3 - 2 * X) ^ 2 / (X * Y - 2))
Fxy = (Fgx - 1 / 2) * (Fgy - 1 / 2) + (X ^ 2 * Y ^ 2 / 72) - (X * Y / 2) * (Fgx - X / 3) * (Fgy - Y / 3)
'Ix = L * B ^ 3 * Fxi
'Iy = L ^ 3 * B * Fyi
'Ixy = B ^ 2 * L ^ 2 * Fxy
'Revised Eccentricty
Feccb = 1 / 2 - Fgy
Feccl = 1 / 2 - Fgx
'Erb = B * (Eb / B + Feccb)
'Erl = L * (El / L + Feecl)
'Relationship B/W El/L and Eb/B and Factors X and Y
P1 = (-Fxi * Fgx + Fxy * (Y - Fgy)) / (Fxi * Fyi - Fxy ^ 2)
Q1 = (Fyi * (Y - Fgy) - Fxy * Fgx) / (Fxi * Fyi - Fxy ^ 2)
R1 = Feccl * (-Fxi * Fgx + Fxy * (Y - Fgy)) / (Fxi * Fyi - Fxy ^ 2) + _
     Feccb * (Fyi * (Y - Fgy) - Fxy * Fgy) / (Fxi * Fyi - Fxy ^ 2) + _
     1 / (1 - X * Y / 2)
P2 = (Fxi * (X - Fgx) - Fxy * Fgy) / (Fxi * Fyi - Fxy ^ 2)
Q2 = (-Fyi * Fgy + Fxy * (X - Fgx)) / (Fxi * Fyi - Fxy ^ 2)
R2 = Feccl * (Fxi * (X - Fgx) - Fxy * Fgy) / (Fxi * Fyi - Fxy ^ 2) + _
     Feccb * (-Fyi * Fgy + Fxy * (X - Fgy)) / (Fxi * Fyi - Fxy ^ 2) + _
     1 / (1 - X * Y / 2)
[COLOR=#008000][B]ElByL[/B][/COLOR] = (Q1 * R2 - Q2 * R1) / (P1 * Q2 - P2 * Q1)
[COLOR=#008000][B]EbByB[/B][/COLOR] = (R1 * P2 - R2 * P1) / (P1 * Q2 - P2 * Q1)
End Function
If the two variables variable in your function header that I colored red are supposed to be the same as the variables I highlighted in green toward the bottom of your code, then the problem is you spelled them differently... make them the same spelling and, unless there is some other problem in your code, it should work the way you expect. By the way, using Option Explicit at the top of your modules would have helped you prevent this problem.
 
Upvote 0
It was a spelling mistake, I was able to get the desired result after using "Option Explicit".

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,661
Messages
6,120,797
Members
448,994
Latest member
rohitsomani

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top