Function pls...

todoink

Member
Joined
Jul 27, 2006
Messages
15
Programming Experience
Beginner
Hi sir,

Can you please teach me how to construct a function in the most simpliest way? Thanks a lot.

Kudoz.
 
this is the basic layout of a function:
VB.NET:
Friend Function myFunct(ByVal Something As Something) As Something

  Return Something

End Function
you first give the function a scope (in this case it's Friend but it could be Private, Protected, Public)


next you give it a name (myFunct is an example) then you declare the parameters it'll accept and how they'll be passed (ByVal/ByRef are how the data is passed, ByVal passes a copy whereas ByRef passes a pointer to the actual value(s)) and functions can accept Integers, Doubles, Singles, Chars, Decimals, Strings, etc... too

then lastly you declare what data type the function will be returning (String, Integer, Double, etc...)

then somewhere in the function you use the 'Return' keyword to actually return the value from the function

that's about as simple as i can get
 
If the function was defined in the same file as the procedure, you would simply call it be name, passing the appropriate arguments:

myFunct(Something)

If the function had a return, you would need to assign it into something:

Dim myReturn as Something
myReturn=myFunct(Something)

If the function was defined in a seperate file, I usually keep all mine in a FunctionDefinitions.vb file, or an external DLL, you would include the assembly or enclosing class name:

ExternalDLLName.myFunct(Something)
 
Back
Top