Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Variable Data Type

How can you tell the data type of a variable ?

The defined name "Test" has a Refers to: field of =SUM(A1,B1).

1) In the example below, what would the data type for "v" be ?

v = Application.Evaluate(ActiveWorkbook.Names("Test"))

2) For a ComboBox containing text values, what would the data type for
"x" be for the currently selected value ?




- Ronald K.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default Variable Data Type

On Wed, 28 Sep 2011 20:36:47 -0400, "kittronald" wrote:

How can you tell the data type of a variable ?

The defined name "Test" has a Refers to: field of =SUM(A1,B1).

1) In the example below, what would the data type for "v" be ?

v = Application.Evaluate(ActiveWorkbook.Names("Test"))

2) For a ComboBox containing text values, what would the data type for
"x" be for the currently selected value ?




- Ronald K.


The data type of a variable is determined by your type declaration. If you don't specifically declare the data type (a poor practice, in my opinion), it will be a variant data type.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 230
Default Variable Data Type

On 29/09/2011 01:36, kittronald wrote:
How can you tell the data type of a variable ?

The defined name "Test" has a Refers to: field of =SUM(A1,B1).

1) In the example below, what would the data type for "v" be ?

v = Application.Evaluate(ActiveWorkbook.Names("Test"))


Depends on whether =SUM(A1,B1) gives a valid answer or not.

Success will be a Double or failure will be an Error
(there might be other possibilities)

Simple clip to test

Sub test()
x = 1
y = "hello"
Z = Application.Evaluate("=SUM(A1..B2)")

Debug.Print x, TypeName(x)
Debug.Print y, TypeName(y)
Debug.Print Z, TypeName(Z)
End Sub


2) For a ComboBox containing text values, what would the data type for
"x" be for the currently selected value ?


I think either a Long internally or a Double in the linked cell
depending on exactly how you ask the question. Do the experiment to
check it to be sure.

Regards,
Martin Brown
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Variable Data Type

"Martin Brown" wrote in message
...
On 29/09/2011 01:36, kittronald wrote:
How can you tell the data type of a variable ?

The defined name "Test" has a Refers to: field of =SUM(A1,B1).

1) In the example below, what would the data type for "v" be ?

v = Application.Evaluate(ActiveWorkbook.Names("Test"))


Depends on whether =SUM(A1,B1) gives a valid answer or not.

Success will be a Double or failure will be an Error
(there might be other possibilities)

Simple clip to test

Sub test()
x = 1
y = "hello"
Z = Application.Evaluate("=SUM(A1..B2)")

Debug.Print x, TypeName(x)
Debug.Print y, TypeName(y)
Debug.Print Z, TypeName(Z)
End Sub


2) For a ComboBox containing text values, what would the data
type for
"x" be for the currently selected value ?


I think either a Long internally or a Double in the linked cell
depending on exactly how you ask the question. Do the experiment to
check it to be sure.

Regards,
Martin Brown


I have on occasion used typename() against a range.value to test for
error conditions -- that is one advantage of using the variant type
instead of specific typing. If memory serves, the iserror() function can
be useful when working with variants and formula results.

--
Clif McIrvin

(clare reads his mail with moe, nomail feeds the bit bucket :-)


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Variable Data Type

Clif,

Thanks for the help.



- Ronald K.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Variable Data Type

Martin,

Using Debug.Print helped a lot.

The problem I was running into was that the Refers to: field had an IF
statement (i.e., =IF(SUM(A1,B1)3,SUM(A1,B1),"Error").

So the result could be a number or a text value.

Is "As Variant" the appropriate data type for this type of situation ?

Thanks again for the help.



- Ronald K.


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
VBA Import Convert Data Type from Type 1 to Type 2 u473 Excel Programming 3 October 21st 08 08:22 PM
Extracting data type from variable ExcelMonkey[_183_] Excel Programming 2 November 9th 04 11:01 PM
How to find out the data type of a variable in VBA ? Adrian[_7_] Excel Programming 1 September 5th 04 05:00 PM
What data type for Variable? Jeff Armstrong Excel Programming 4 August 6th 04 09:38 PM
efine the data type of a variable monika Excel Programming 0 February 13th 04 02:01 AM


All times are GMT +1. The time now is 12:35 PM.

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

About Us

"It's about Microsoft Excel"