![]() |
|
[.NET] [TUT]How to make your own functions[/TUT] - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] [TUT]How to make your own functions[/TUT] (/showthread.php?tid=1163277) |
[TUT]How to make your own functions[/TUT] - Modestep - Mar 27, 2011 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 numbers Code Function Add(ByVal intNumber1 As Integer, ByVal intNumber2 As Integer) As IntegerHow we use this: Code MessageBox.Show(Add(TextBox1.Text, TextBox2.Text))Even and Odd numbers Code Function EvenOrOdd(ByVal intNumber As Integer) As BooleanI 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 * - H3x0S - Mar 27, 2011 You should've explained the "ByRef", "ByVal" and "Optional". * - Modestep - Mar 27, 2011 (Mar 27, 2011 08:06 AM)H3x0S Wrote: You should've explained the "ByRef", "ByVal" and "Optional".I am gonna cover that in the following tut, these are a bit more advanced to explain. This was just a little intro to functions. * - wertyl11 - Mar 27, 2011 Nice tutorial dude. But could you explain why you dont have declared intNumber1 or IntNumber2, or are they there only to be replaced with a numbers ? Sorry If I am stupid :( * - H3x0S - Mar 27, 2011 (Mar 27, 2011 08:21 AM)wertyl11 Wrote: Nice tutorial dude. But could you explain why you dont have declared intNumber1 or IntNumber2, or are they there only to be replaced with a numbers ? They are arguments that have to be specified when using a function and they are declared as integers. * - no1me - Mar 27, 2011 he declared >>> (ByVal intNumber1 As Integer, ByVal intNumber2 As Integer) * - Modestep - Mar 27, 2011 The declaration happens here: Function Add(ByVal intNumber1 As Integer, ByVal intNumber2 As Integer) As Integer, if you wanna use the function you do it like this Add(PutAnIntegerHere, AndAnotherOneHere) if you want to add 3 numbers you do it like this: Code Function Add(ByVal intNumber1 As Integer, ByVal intNumber2 As Integer,ByVal intNumber3 As Integer) As Integer* - Cody8295 - Mar 27, 2011 Pretty helpful for people just starting out I guess. |