Post: [TUT]How to make your own functions[/TUT]
05-09-2011, 11:59 PM #1
(adsbygoogle = window.adsbygoogle || []).push({});
Originally posted by kingdeath360
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[/align]
[size=large][color=#FFD700]Add 2 numbers[/color][/size]
    Function Add(ByVal intNumber1 As Integer, ByVal intNumber2 As Integer) As Integer
Dim intReturn As Integer
intReturn = intNumber1+ intNumber2
Return intReturn
End Function

Lets break it down. I named the function "Add" as you can see. And i give the function 2 Integers "intNumber1 and intNumber2" then i say that the return value is gonna be an integer "As Integer".
How we use this:
    MessageBox.Show(Add(TextBox1.Text, TextBox2.Text))

Its better to put variables but now i used "TextBox1.Text" because that's easier to follow. Next in our code we calculate the sum "intReturn = intNumber1+ intNumber2". Fine we now have the sum, we have the return the sum "intReturn". If we dont do that, are function is worthless

[size=large][color=#FFD700]Even and Odd numbers[/color][/size]
    Function EvenOrOdd(ByVal intNumber As Integer) As Boolean
If intNumber Mod 2 = 0 Then
Return True
Else
Return False
End If
End Function

Now the name of our function is EvenOrOdd, we give 1 integer to it "intNumber" and the output will be "boolean" true or false. If the rest is 0 then we have a even number so we return True "Return True" else it's an odd number and we return false "Return False". So it's not necessary to have only one return option, we can return different things. In this case true or false.
[align=center]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[/align]


source You must login or register to view this content.
05-10-2011, 12:19 AM #2
cs475x
You talkin to me?
Too bad VB isn't the best language to be learning/teaching... It's okay to start out but not really good to put all of your focus on.
05-10-2011, 12:34 AM #3
cs475x
You talkin to me?
Originally posted by KingDeath360 View Post
vb helped me learn php & mw2 patch coding


Okay, but I'm saying that once you learn other languages from VB, you should stop using VB and switch to C++.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo