How to make a function

Functions are used for operations that give back a value.
They have a return type, which has to be declared.
You can declare parameters to be passed to the function when it is called.

The Program

First you can type a number in the TextField.
If the Button is clicked, the first Label shows the Text "Hello",
and the second shows the product of your number and five.

The Code:

Fmain.class

STATIC PUBLIC SUB Main()
  DIM hForm AS Fmain
  hForm = NEW Fmain
  hForm.show
END

PUBLIC SUB Button1_Click()
  Label1.Text=sayHello()
  Label2.Text=timesFive(TextBox1.Text)
'the parameter of the function is declared as
'Integer, but it works if the input is
'like a integer number
'or use CInt()
END

PUBLIC FUNCTION sayHello() AS String
'the returntype is String
  word AS String
  word = "Hello"
  RETURN word
END

PUBLIC FUNCTION timesFive(x AS Integer) AS Integer
  RETURN x * 5
END

The Source

Download


Referenced by :