Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
Variable Data Type
Clif,
Thanks for the help. - Ronald K. |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VBA Import Convert Data Type from Type 1 to Type 2 | Excel Programming | |||
Extracting data type from variable | Excel Programming | |||
How to find out the data type of a variable in VBA ? | Excel Programming | |||
What data type for Variable? | Excel Programming | |||
efine the data type of a variable | Excel Programming |