03-27-2011, 07:23 AM
A function is something you can write and put in your code. You can use it as many times later on in the code without having to write it again and again. The difference between a Sub and a function is that a function returns something.
It's being used in crypters for the encrypting/decrypting alot. Oke lets start
Add 2 numbersIt's being used in crypters for the encrypting/decrypting alot. Oke lets start
Code:
Function Add(ByVal intNumber1 As Integer, ByVal intNumber2 As Integer) As Integer
Dim intReturn As Integer
intReturn = intNumber1+ intNumber2
Return intReturn
End Function
How we use this:
Code:
MessageBox.Show(Add(TextBox1.Text, TextBox2.Text))
Even and Odd numbers
Code:
Function EvenOrOdd(ByVal intNumber As Integer) As Boolean
If intNumber Mod 2 = 0 Then
Return True
Else
Return False
End If
End Function
I hope this was a good little tut, if there is interest i will make another to check if a number is a prime number, perfect number etc.. And i will cover a Sub in the next tut and more advanced functions