Take the 2-minute tour ×

I am investigating types in VB especially in VBA. Generally, given an entity there are two types: Effective value type, I guess, is defined as value types in this part of the specification; Declared Type is defined in this part of the specification.

To do tests, I need to use some functions to check types. There are TypeName and VarType. I think they are used to check effective value type of an entity, because TypeName can return DBNull, Decimal and Nothing; VarType can return vbNull, vbEmpty, vbError and vbDecimal. These types exist in the table of effective value types, but not in the table of declared type.

So now, my question is, does anyone know how to check/display the declared type of an entity (variable, expression...)?

Edit 1: Probably for a variable, its declared type is just the type that the declaration of the variable specifies. I would like to insist that, it seems that VBA has declared type for expressions. For instance, Operator Declared Type is mentioned in this link. I think that refers to the declared type of the result of an operation. That means such entities as -i, i+5, i>6... can have a declared type. I would like to know how to display their declared type.

share|improve this question
TypeName and VarType are regular function with a single Variant parameter, so no matter "declared type" every variable is cast to Variant before passing to them. In this VarType(1) what is the "declared type" of 1? It's not a variable, so it's not declared/dimensioned at all. The only way to implement something like this is through a special language construct, not a function, and I'm not aware of any, closest being TypeOf ... Is –  wqw Nov 4 '12 at 20:18
It seems that TypeOf can only checks Object in VBA, we cannot use it to check Interger, String... –  SoftTimur Nov 4 '12 at 20:34
VarType in VBA & VBScript is not the same as the reference you link, it is msdn.microsoft.com/en-us/library/3kfz157h(v=vs.84).aspx, and does what you want, I think. –  Remou Nov 4 '12 at 22:00
This is the correct reference for TypeName in VBA - msdn.microsoft.com/en-us/library/gg278698.aspx The link in the question is for VB –  barrowc Nov 5 '12 at 7:55
i is an integer because its declared as an integer, within the scope of that declaration i is forever & always an integer. The only context where the phrase "effective value type" has meaning is when a variant holds a value, are you asking how to determine the corresponding datatype for the value in a variant? –  Alex K. Nov 5 '12 at 10:54
show 9 more comments

1 Answer


Dim i as integer
i = 6/3

then you do, TypeName(i>3) it returns Boolean which is the expression's Type based on the Type of the resulting value it holds not operand's declare type. And it complies with the specification given in your link for msdn 2.2 Entities and Declared Types.

Or else are you looking for a syntax/function (e.g. DType, imaginative function) that could return DType(i>3) as integer which is operand's (i) Type? Or rather it's more useful when you have multiple variables within some expression, so you can find all their Types in one go? e.g. some String that combined all sorts of different TYPE variables in one expressoin.

Just trying to understand when and how this can be useful to you and what could be the end result you are looking for.. Seems like this is more to lanague root definitions.

PS: I do not have reps points to comment. So I added as an answer.

share|improve this answer
add comment

Your Answer


