Custom function

Status
Not open for further replies.
G

go4saint

Guest
Hi,

Is there a way to create a custom function, like in Excel VBA ?
For example a function to multiply two numbers,

=multiply(a,b)

where a and b are 2 text boxes on a form.

If anyone can give me an example, I will understand better and try to create my own functions.

Thanks!
 
Last edited by a moderator:

klaus

Expert
Licensed User
Longtime User
Yes you can !

I have added a small example that shows a solution.

B4X:
Sub Globals
'Declare the global variables here.
   c=0
End Sub

Sub App_Start
   Form1.Show
End Sub

Sub Multiply(a,b)
   Return a*b
End Sub

Sub Button1_Click
   c=Multiply(TextBox1.Text,TextBox2.Text)
   Label1.Text=c
End Sub

You can of course use other intermediate variables for the values in the textboxes.

Best regards
 
G

go4saint

Guest
Thanks for solution klaus,

but there is a problem when I try to compile in both Desktop and Device.

Error Message CS1525:Invalid expression term ')'
in line c=Multiply(TextBox1.Text,TextBox2.Text)
 

specci48

Well-Known Member
Licensed User
Longtime User
Hm... there must be a typo or something like that in your personal code because the sample of klaus works fine. Take his attachment and try to compile it, it will work. So I'm sure you implemented his solution manually into your own code.

Error CS1525 occurs when the compiler detects an invalid character in an expression, so have a close look to you code again.


specci48
 
Status
Not open for further replies.
Top