PDA

View Full Version : DefType Statements in VBA



Transformer
06-06-2013, 04:52 PM
UsefulGyaan Has Posted the Following On 06-06-2013 05:18 PM:

The syntax for declaring a variable in VBA is: ****** Dim [VariableName]**** As [VariableType] If the variable type is not specified, then the variable becomes a Variant by default. However, this behavior can be modified using DefType statements. A DefType statement can be used to set the default data type for those Variables/Functions(return type)/Function-Parameters whose […]http://stats.wordpress.com/b.gif?host=usefulgyaan.wordpress.com&blog=50473542 &post=900&subd=usefulgyaan&ref=&feed=1





DefType Statements in VBA (http://usefulgyaan.wordpress.com/2013/06/06/deftype-statements-in-vba/)

Excel Fox
06-06-2013, 07:26 PM
It is worthwhile to go through these documents

BET: Microsoft VBA Datatypes - DefType (http://www.bettersolutions.com/vba/VAX123/LY710811611.htm)

Deftype Statements (http://msdn.microsoft.com/en-us/library/aa263421%28v=vs.60%29.aspx)

Trip Planner, Deftypes and Options (http://www.vbatrain.com/samples_parallel/tripplan_20_deftypesplus.php)

snb
06-06-2013, 07:47 PM
@Excel Fox,

You referred to the (rather pretentious named) 'Better Solutions' website.
Using Deftype is being commented as 'This is not good prograaming practice and using these statements should be avoided.' (typo unaltered)
No arguments were provided. That is what I call 'not good communication practice'.
I wish that site should concentrate on 'Better arguments'.

Excel Fox
06-06-2013, 08:01 PM
snb, I tend to agree with you. Personally, if given an option, I would also like to stick to the more orthodox way of programming, and I don't vouch for using Deftype. Having said that, it might be an interesting method, as I haven't come across any microsoft sites that against this either. So I'll take a neutral stand on this. I thought Transformer shared something that was a learning for me, so I thought it's better to give viewers inputs from a few other sites also.

Having said that, if you do have any evidence, personal or otherwise, that may lead one to believe that Deftype is faulty, I'd be interested.

snb
06-07-2013, 12:35 AM
@Excel Fox

I have no evidence whatsoever. Personally I have the impression that the mention of 'good practice' is seldom accompanied by 'sound argumentation'.