Argument Data Types


When 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 with data 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 type and use the default Variant, then your procedure will accept anything, be it a number or a string. This could have unfortunate consequences within that procedure if you are expecting a string and a number gets passed across or vice versa. If you specify the parameter as a string, an error will occur if you do 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.




Excel VBA Macro Programming
Excel VBA Macro Programming
ISBN: 0072231440
EAN: 2147483647
Year: 2004
Pages: 141

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net