Creating Subroutine

walterf25

Expert
Licensed User
Longtime User
Hello all, this may seem like a noob question, although i'am a noob in Basic4Android, i'm trying to create a sub which i will call by clicking on a button,

Sub CalculateResistors (R1 As Double, R2 As Double) As Double
Dim S2 As Int
Dim S1 As Int
S2 = 1/(frequency * c * 0.693)
S1 = S2 * DutyCycle / 100
R2 = S2 - S1
R1 = S1 - R2
End Sub

when i call this sub like this, CalculateResistors(R1, R2) it doesn't return any values, can anyone help me with this, i'm sure is something very simple, but i can't figure it out, anybody?

thanks,
Walter:sign0085:
 

vb1992

Well-Known Member
Licensed User
Longtime User
You need to include the "return"
then the value will be returned to the calling code.
B4X:
Msgbox(MyMath(2.51,2.49),"")


Sub MyMath (a As Double, b As Double)

Dim c As Double

c = a + b

Return c

End Sub
 
Upvote 0

bustedkrutch

New Member
Licensed User
Longtime User
declaring subroutine with return type

When you declare the sub as one to return a value, don't you need to include the return type in the declaration ???

From above

Msgbox(MyMath(2.51,2.49),"")


With return type

Msgbox(MyMath(2.51,2.49),"") as Double

I'm new to b4a (which may be intuitively obvious, depending upon your response) lol
 
Upvote 0
Top