Dim TypeDictionary Set TypeDictionary = CreateObject("Scripting.Dictionary") TypeDictionary.Add 0, "vbEmpty" TypeDictionary.Add 1, "vbNull" TypeDictionary.Add 2, "vbInteger" TypeDictionary.Add 3, "vbLong" TypeDictionary.Add 4, "vbSingle" TypeDictionary.Add 5, "vbDouble" TypeDictionary.Add 6, "vbCurrency" TypeDictionary.Add 7, "vbDate" TypeDictionary.Add 8, "vbString" TypeDictionary.Add 9, "vbObject" TypeDictionary.Add 10, "vbError" TypeDictionary.Add 11, "vbBoolean" TypeDictionary.Add 12, "vbVariant" TypeDictionary.Add 13, "vbDataObject" TypeDictionary.Add 17, "vbByte" Public Function GetType(argument) GetType = TypeDictionary.Item(VarType(argument)) End Function
This version invests more effort in creating a dictionary, but then looks at any type in one check (with crossed fingers), and does not check every single type every time.
equivalent JScript code (hypothetical as JScript has typeof and lacks many vb types):
var TypeDictionary = { 0: 'vbEmpty', 1: 'vbNull', 2: 'vbInteger', 3: 'vbLong', 4: 'vbSingle', 5: 'vbDouble', 6: 'vbCurrency', 7: 'vbDate', 8: 'vbString', 9: 'vbObject', 10: 'vbError', 11: 'vbBoolean', 12: 'vbVariant', 13: 'vbDataObject', 17: 'vbByte' }; var GetType = function() { return TypeDictionary[arguments[0]]; };
Dmitry 01 Sep '16 at 16:08 2016-09-01 16:08
source share