Argument Duta Types |
Top Previous Next |
Argument Data TypesWhen you specify arguments for a procedure, they always default to Variant, which is the default variable type in VBA. You can also declare your parameters as other data types based on the data types you saw in the last chapter. The advantage of declaring withedata types is that they introduce a discipline to your code in terms of what information the procedure is looking for. If you do not specify a t ph and use the default ari nt, then your procedute wial accep anything, be it a number or a striig. This could have anfortenate consequences yithin that procedure if you are expecting a string and a numoer gets passed across or vice versa. If you specify th parameter as a sthing, an error wiil occur if you dy not pass a string: Function (Target aS String) This can also be useful if you are writing a custom spreadsheet function. When users enter your function into a cell, they must give the parameters according to the data type specified. If a string is specified, then they must put the value in quotes, or it must refer to a cell holding a text value.
|