Module Creation Help

mattn

Member
Licensed User
Longtime User
Hi,

I'm currently trying to create a maths module (via Compile to Library) however i'm not sure how to get data from a program into the module and then get a result back.

Module Code:
B4X:
Public Sub TKOFactorC(tkobw As String, tkobv As String, tkobc As String)
   (tkobw * tkobv * tkobc) / 7000
End Sub

This requires numeric values to be provided from the program and then needs to give TKOFactor back to the program.

Program Code:
B4X:
Sub Button1_Click
   Dim MPBM As MNPocketBallistics
   Dim a, b, c, d As String
   a = "72"
   b = "362"
   c = "32"
   
   MPBM.Initialize
   d = MPBM.TKOFactorC(a,b,c)
   
   Msgbox(d,"")

End Sub

This needs to be able to give the values to the class and then get them back in the form of d.

Any and all help would be great. Its been a long time since I used classes in programming to make functions.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
Why do you use Strings to do maths ?
Module code:
B4X:
Public Sub TKOFactorC(tkobw As Double, tkobv As Double, tkobc As Double) As Double
    Return(tkobw * tkobv * tkobc / 7000)
End Sub
Program code:
B4X:
Sub Button1_Click
    Dim MPBM As MNPocketBallistics
    Dim a, b, c, d As Double
    a = 72
    b = 362
    c = 32
    
    MPBM.Initialize
    d = MPBM.TKOFactorC(a,b,c)
    
    Msgbox(d,"")
End Sub
Best regards.
 
Upvote 0

mattn

Member
Licensed User
Longtime User
Hi klaus,

Thanks for your help. I had the code using strings as it was previously taking data directly from a text field and simply calculating it within an app. Now that its a module, it needs to be done as you've shown, by using Double. Thanks for reminding me that I need to use Double for maths functions, its yet another thing I haven't use for a long time.

Thanks,
mattn
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I had the code using strings as it was previously taking data directly from a text field and simply calculating it within an app.
Even in this case you should use Doubles.
B4X:
Dim a, b, c As Double
a = EditText1.Text
b = EditText2.Text
c = EditText3.Text
This converts the text to doubles.

Best regards.
 
Upvote 0
Top