Re: VBA.convertFromJava("instanceof")=?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.

.



Relevant Pages

  • ANN: MeObjects Library for Delphi
    ... object type small and powerful. ... the Object instance can use the ClassType method return the ... Especially for lists of pointers to dynamically allocated memory. ... {Summary Adds Ansi String and correspondent object to a list. ...
    (borland.public.delphi.thirdpartytools.general)
  • Re: Muliple Users aspx project
    ... because "*" is not a valid operator for the Object type. ... John Saunders ... >> Public Shared Property FirstName As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: SCJP Question - Polymorphism, method overloading, overridding
    ... object type is considered, when overloading the reference type is ... Others have already explained the reason, but I want to add that overloading is not operative in this particular situation. ... The expression in question is ruled by the variable at compile time; that's why it delivers an error. ... String s = thing.method1; ...
    (comp.lang.java.help)
  • Re: Delphi.NET
    ... Object type wasn't broken, people just didn't know how to use it. ... the object model was written before the Pointer strings came out.. ... If one was to use the correct type of string that was designed for it, one wouldn't need to use those 2 fancy calls to use the systems default Pointer string that every one has gotten use to. ...
    (comp.lang.pascal.delphi.misc)
  • Re: ASP and session object (get type)
    ... Head of Development ... Integrity eLearning ... > contains (for example, determine whether it is a string, integer, single ... > Is there any easy way to detect the object type in ASP? ...
    (microsoft.public.inetserver.asp.general)