What is function in vb net?

1st, I hope you do know what a 'sub' is, if you don't, anyways its like a paragraph that includes codes to be executed when an event happens, as button.click event or mousehover event

a function is like a sub but returns a value, and does the same work of a variable, for example you can make a function for adding numbers:

private function Name_Of_Your_Function(Byval num1 as integer,byval num2 as integer) as integer

and now u made a function that dims 2 variables (num1, num2) and returns an integer (as integer)

now we type inside it:

dim num3 as integer

num1 + num2 = num3

return num3

notice the return cmd, u can also type: Name_Of_Your_Function = num3

Notice that we didnt dim the num3 in the function declaration ull know why later

now put 2 textboxs and a button and in the Sub of the button add:

dim frstnum, scndnum as integer

and assign them the textboxs input

now to call out function we right its name:

Name_Of_Your_Function()

now we put in the brackets the old num1 and num2,, but as whatever we want, so if we want to add 1 and 6 we do:

Name_Of_Your_Function(1, 6)

now we want to add variables frstnum and scndnum so we will do

Name_Of_Your_Function(frstnum, scndnum)

and now to get the result we'll get the value of the function, remember?

so we wil assign the value of that function to a new variable for us to use

dim answer as integer

answer = Name_Of_Your_Function

And then add a label and do label1.text = answer

and your done!

You successfully used a function

I hope you understood the consept, you can make functions return other things than integers tho, as strings and booleans