To quote my colleague:
all variables in VBA are variants but with different vartype:
Dim x '--->variant with vartype = vbEmpty x= "hello" '--->vartype changed from vbEmpty to vbString and value assigned x= 1 '--->vartype changed to vbInteger
Dim x as String '--->variant with vartype = vbEmpty is created and then vartype changed to vbString x= "hello" '--->vartype = vbString x=1 '--->because x was declared explicitly with String it will try to implicitly convert 1 to string, so, x will remain vbString
My main point of contention is how can Dim x as String
fit in with his statement that all variables in VBA are variants
. Variants are more inefficient to work with so why would everything start there and get converted.
Are all variables, in VBA, variant?
Can anyone find any documentation or provide code that categorically proves the answer one way or the other?
EDIT
He put forward the following as a start to try and prove the above - but I think that all it proves is that they are all strings:
Sub aaa()
Dim str_str As String
Dim str_var
str_str = "aaa"
str_var = "aaa"
str_xxx = "aaa"
MsgBox VarType(str_str) & ": " & TypeName(str_str)
MsgBox VarType(str_var) & ": " & TypeName(str_var)
MsgBox VarType(str_xxx) & ": " & TypeName(str_xxx)
End Sub