Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default VBA.convertFromJava("instanceof")=?

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default VBA.convertFromJava("instanceof")=?

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?


I don't know Java, but I think you are looking for either the VarType or
TypeName function (they are similar, but one outputs a number representing
the data type and the other outputs the data type name as a String value).

Rick

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default VBA.convertFromJava("instanceof")=?

This doesnt work for user defined types.

Chip Pearson's typeOf does.

Thanks though.


"Rick Rothstein (MVP - VB)" wrote:

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?


I don't know Java, but I think you are looking for either the VarType or
TypeName function (they are similar, but one outputs a number representing
the data type and the other outputs the data type name as a String value).

Rick


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default VBA.convertFromJava("instanceof")=?

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" wrote in message
...
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.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default VBA.convertFromJava("instanceof")=?

Cool.

Thanks man.

"Chip Pearson" wrote:

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" wrote in message
...
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.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
If changed array formula reduce ""\""\""\ - signs to #Missing, will it make ... Maria J-son[_2_] Excel Programming 2 March 5th 06 12:20 PM


All times are GMT +1. The time now is 05:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"