Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 11th, 2005, 5:15 AM   #1
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
how do i make custom functions

hey, i want to know

how i can make a like.. a custom "function" or whatever its called
so in my command button click event i can call the cutom one and it will do
all the commands in there instead of having to write the same thing for each
control that will do the same thing.

thanks
cloud- is offline   Reply With Quote
Old Jan 11th, 2005, 9:48 AM   #2
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Copyed and Pasted from the msdn lib:

Quote:
Visual Basic includes built-in, or intrinsic functions, like Sqr, Cos or Chr. In addition, you can use the Function statement to write your own Function procedures.

The syntax for a Function procedure is:

[Private|Public][Static]Function procedurename (arguments) [As type]
statements

End Function

Like a Sub procedure, a Function procedure is a separate procedure that can take arguments, perform a series of statements, and change the value of its arguments. Unlike a Sub procedure, a Function procedure can return a value to the calling procedure. There are three differences between Sub and Function procedures:



  • Generally, you call a function by including the function procedure name and arguments on the right side of a larger statement or expression (returnvalue = function()).
  • Function procedures have data types, just as variables do. This determines the type of the return value. (In the absence of an As clause, the type is the default Variant type.)
  • You return a value by assigning it to the procedurename itself. When the Function procedure returns a value, this value can then become part of a larger expression.
For example, you could write a function that calculates the third side, or hypotenuse, of a right triangle, given the values for the other two sides:


   
  
   Function Hypotenuse (A As Integer, B As Integer)  As String
 				 Hypotenuse = Sqr(A ^ 2 + B ^ 2)
  End Function


You call a Function procedure the same way you call any of the built-in functions in Visual Basic:

   Label1.Caption = Hypotenuse(CInt(Text1.Text),  CInt(Text2.Text))
  strX = Hypotenuse(Width, Height)

For More Information For additional details about the Function procedure, see "Function Statement" in the Language Reference. The techniques for calling all types of procedures are discussed in the section, "Calling Procedures," later in this chapter.
There you go, all this info and more is avalible at msdn.microsoft.com then click on the library link along the top of the page.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Jan 11th, 2005, 11:59 AM   #3
cloud-
Hobbyist Programmer
 
Join Date: Jan 2005
Posts: 110
Rep Power: 4 cloud- is on a distinguished road
ahh

thanks alot for that
got it working great now
thanks
cloud- is offline   Reply With Quote
Old Jan 11th, 2005, 1:14 PM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
no problem, that's what we're here for. the msdn reference is a great resource for microserf programming.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:49 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC