|
-
Dec 22nd, 2001, 11:30 PM
#1
Function parameter
I want to make a Function who not all parameter are needed how can I do that ?
-
Dec 22nd, 2001, 11:32 PM
#2
Example :
VB Code:
Private Function Calcu(x as Double, y as Double, z as Double) as Double
Calcu = x + y + z
End Function
Like if I do not put z it will work... How can I do that ?
-
Dec 22nd, 2001, 11:45 PM
#3
VB Code:
Option Explicit
Private Sub Command1_Click()
MsgBox Calcu(1, 2)
End Sub
Private Function Calcu(x As Double, y As Double, Optional z As Double) As Double
Calcu = x + y + z
End Function
-
Dec 22nd, 2001, 11:46 PM
#4
Hyperactive Member
Use the optional keyword
As follows:
VB Code:
Function XYZ(X As This, Y As That, [COLOR=red]Optional[/COLOR] Z As Whatever)
'Your Code
End Function
Thats it, you won't have to pass z if you don't want to.
Remember the following points in case of using Optional Parameters:
- The Paramebers following the first Optional Parameter must also be optional
- You can specify the default value of the Optional Parameter, if the user doesn't Pass any Value for that
- In case of a Variant Optional Parameter, you could check to see if it was specified using the IsMissing() Function
- In case you don't specify the Default Value of other DataTypes, it will be initialized as a standard Variable of that type: Inetegers will be Initialized to zero
- In case you need to use *any* number of Parameter which is unknown at the time you write the code, you can use the ParameterArray which would allow you to pass any number of parameters to a function.
Cheers
Abu Haider
____________________________
100% Data Validation for the MS DataGrid Control. Plus Support for Custom and Foreign Lists, DatePicker and much more...
The DataGridEnhancer
I often point to a place where the problem has been discussed, instead of giving you the code that solves it. This is for good, may be you will understand some day...
-
Dec 22nd, 2001, 11:49 PM
#5
Hyperactive Member
I think 50 words per minute is not good enough. I have to be faster.
Abu Haider
____________________________
100% Data Validation for the MS DataGrid Control. Plus Support for Custom and Foreign Lists, DatePicker and much more...
The DataGridEnhancer
I often point to a place where the problem has been discussed, instead of giving you the code that solves it. This is for good, may be you will understand some day...
-
Dec 22nd, 2001, 11:50 PM
#6
Abu haider your explication was simply excellent!!! THX YOU man !!!
-
Dec 22nd, 2001, 11:52 PM
#7
Hyperactive Member
Abu Haider
____________________________
100% Data Validation for the MS DataGrid Control. Plus Support for Custom and Foreign Lists, DatePicker and much more...
The DataGridEnhancer
I often point to a place where the problem has been discussed, instead of giving you the code that solves it. This is for good, may be you will understand some day...
-
Dec 22nd, 2001, 11:55 PM
#8
The only one thing I do not understand is : In case you need to use *any* number of Parameter which is unknown at the time you write the code, you can use the ParameterArray which would allow you to pass any number of parameters to a function.
-
Dec 23rd, 2001, 12:58 AM
#9
Frenzied Member
If you dont know the datatype of the para
-
Dec 23rd, 2001, 12:59 AM
#10
Yes but I do not know what to do in that case
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|