Re: VBA.convertFromJava("instanceof")=?
- From: "Chip Pearson" <chip@xxxxxxxxxxxx>
- Date: Tue, 26 Jun 2007 13:55:09 -0500
You can use TypeName to get the name of the variable type. E.g.,
Dim V As String
Debug.Print "TypeName: " & TypeName(V)
For object type variables only (not intrinsic variables), you can use the TypeOf operator to get the type (as long as the object is not Nothing):
Dim V As Range
Set V = Range("A1")
Debug.Print "TypeName: " & TypeName(V)
Debug.Print "TypeOf Is Range: " & TypeOf V Is Range
When working with object variables, TypeOf is better than TypeName because you can prefix a typelib to the object type to ensure that you have the right object type. For example, both the Excel and the MSForms libraries have an object named CheckBox. With TypeName, you will get only the string "CheckBox" as the result. You don't know whether it is a Excel CheckBox or an MSForms CheckBox. With TypeOf, you can specifiy the typelib. E.g.,
If TypeOf V Is MSForms.CheckBox Then
' do something
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)
"vivmaha" <vivmaha@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:598DC6B7-ADDB-4ECD-8F15-1670FB47F245@xxxxxxxxxxxxxxxx
Hi,
In java, I use the instanceof keyword to check if an object is a certain
type of class.
So you can do things like:
if (s instance of string) then output("String!!!") else output("Needs a
string")
Whats the equivalent in VBA?
Thanks.
.
- Prev by Date: Re: Edit Listbox in Userform
- Next by Date: Re: Macro to copy data
- Previous by thread: Re: VBA.convertFromJava("instanceof")=?
- Next by thread: Find string in Data
- Index(es):
Relevant Pages
|