Solved

What datatype holds this {1,2;3,4} ? (It's not a string far as I can tell.)

Posted on 2012-03-09
9
354 Views
Last Modified: 2012-06-27
What datatype holds this {1,2;3,4}  Must it be variant?

The context is Evaluate(A1) where A1 contains this string {1,2;3,4}, which when evaluated is an array constant (I think).

I have experimented with various types, but they all get errors except Variant.

Anthony
Aspiring Novitiate, polishing my Datatypes
0
Comment
Question by:Anthony Mellor
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 37703090
I think you can only use a string for that purpose.
0
 
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 37703102
Hello,

it's a two-dimensional array with two rows and two columns. The commas starts a new row, the semicolon starts a new column.

cheers, teylyn
0
 
LVL 17

Assisted Solution

by:andrewssd3
andrewssd3 earned 250 total points
ID: 37703434
As teylyn says, it's an array.  That is why only a variant works here.  You can test it with the following code:
Sub TT()
    Dim v As Variant
    v = Evaluate(ActiveSheet.Cells(1).Value)
    Stop
End Sub

Open in new window

Then, when it stops, you can see your variable in the Locals window:screenshotIf you're using Evaluate like this without knowing what is is in the cell you must assign to a Variant, then you can check what has been returned using Typename or a similar function.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 9

Author Comment

by:Anthony Mellor
ID: 37703645
ok, if it's anything but an array (as described) I don't care, so it can generate an error to its heart's content; this would as I understand it fit the bill for one of the hard data types (i.e. not the "soft" Variant), except there doesn't seem to be one that accepts arrays. in fact I can't find where it says that Variant accepts arrays, though empirically and clearly, it does.

Hence my question really, can't find it in the docs.

Anthony
0
 
LVL 50

Expert Comment

by:Ingeborg Hawighorst
ID: 37703671
You can declare an array with a specific data type, just like any other variable. If you omit the data type, it will be a variant.

Can you provide a bit more context on what you are trying to accomplish? In what scenario do you use evaluate? You mention Evaluate(A1), so there really is no VBA or declaration of data types involved that I can see.

Have a look at Chip Pearson's site for much info on arrays in VBA http://www.cpearson.com/excel/VBAArrays.htm

cheers, teylyn
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37703895
It depends on what variable you assign it to, or how your function works.  I've been down the Evaluate path with you these past days- heck I started it I think, but that's not the only way you can interpret {1,2,3,4}.  You could build your own evaluate function (like I did for you earlier as an example assuming Evaluate didn't exist) reading it as a string.

Agree with what everyone else has said, with the exception that your code not using the Evaluate function can also evaluate it as a string.

Function getString(myStr as string) as string

   getString = left(myStr,3)

End Function

Of course, Evaluate sees it as an array, unless you improperly form it and it also sees it as a string, lol.

Use this against that {1,2;3,4} and you would get:

"{1,"

Cheers,

Dave
0
 
LVL 9

Author Comment

by:Anthony Mellor
ID: 37704436
If I seem confused, or unresponsive, see what you make of these:


by: teylynPosted on 2012-03-10 at 00:25:00ID: 37703671
You can declare an array with a specific data type, just like any other variable.

by: andrewssd3Posted on 2012-03-09 at 23:07:51ID: 37703434
As teylyn says, it's an array.  That is why only a variant works here.

by: ssaqibhPosted on 2012-03-09 at 21:39:06ID: 37703090
I think you can only use a string for that purpose.

by: dlmillePosted on 2012-03-10 at 02:14:13ID: 37703895
Agree with what everyone else has said, with the exception that your code not using the Evaluate function can also evaluate it as a string.

;-)

Yours sincerely,

Perplexed
0
 
LVL 9

Author Comment

by:Anthony Mellor
ID: 37712178
see above :-)
0
 
LVL 42

Accepted Solution

by:
dlmille earned 250 total points
ID: 37712191
I was being cute.  Evaluate sees it as a variant array.

Dave
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question