

Moving from Microsoft Office VBA to AppleScript:
MacTech's Guide to Making the Transition
Introduction
|
Table of Contents
Page Prev and Page Next buttons at bottom of the page.
|
April, 2007
Page 83
But in AppleScript, counting a range makes no sense: AppleScript does not have "default properties". (Well. I know of just one, in Entourage, but it was very specially implemented. I've never seen it anywhere else.) So the script errors. You need to change it to (count cells of rHeader), or (count columns of rHeader), as I did in the script.
In the case of making the new series, you lose the names in the legend; that's because the default property of a Cell must be its Value property. So setting .Name = rHeaders.Cells(i), where Name is of String type, evidently sets the name of the series to the string Value of Cell(i).
But, once again, in AppleScript, where there is no default property for cell, trying to set a name to a cell (a range) instead of to a string or Unicode text, just doesn't work. It doesn't cause an error (although might if you asked for the name afterwards), but it doesn't do anything. It leaves the names at their defaults of "Series1…" etc. Just set the name of the newSeries to value of cell i of rHeaders, and all is well.
Alert: It is absolutely necessary when making a new chart object at the worksheet and making new series at the chart, that you specify at end (or at beginning) in both cases. (If not in targeted tell blocks that would be at end of active sheet, and at end of oChartObj respectively.) I was pleased to discover that I could set properties of both these elements at inception in the make new chart object with properties and make new series with properties statements, and not have to wait until the objects were made.
One last caution is that, along the way, I noticed a great many properties of many different objects that had the same term for their 'type' (i.e., class) as for the property itself. For example, chart title, axis title, line style properties all refer to classes of the same name. That may seem convenient and less cumbersome than the font object property whose type is class font, the legend object property whose type is class legend, and so on. However, these constructions are actually saving you, the scripter, the possibility of pain and confusion.
When the name of the property is the same as the name of a class, as you will recall from Chapter 2, AppleScript can get confused under two conditions: in whose clauses (always) and, sometimes also when using tell blocks to the parent object of the property rather than using of constructions. VBA scripters writing AppleScript love to use nested tell blocks to mirror VBA With blocks, as I did throughout this script. That means you have to be on guard, and use its before the property. It never hurts to use its, so I added a few extra as well, and you could do worse than to always use it in tell blocks to the parent object.
There is much, much more to learn about charts, but that will have to do for this article. When you hit snags, be creative in trying to think of possible workarounds, and analytic to see if you were trying to take a shortcut through the syntax and lost your way.
Here are the numbers to test the sample chart:
Xs |
Y1 |
Y2 |
Y3 |
Y4 |
1 |
1 |
40 |
26.29 |
28 |
2 |
2 |
39 |
26.71 |
32 |
3 |
3 |
38 |
21.89 |
16 |
4 |
4 |
37 |
16.24 |
38 |
5 |
5 |
36 |
14.97 |
22 |
6 |
6 |
35 |
19.24 |
17 |
7 |
7 |
34 |
25.13 |
6 |
8 |
8 |
33 |
27.22 |
7 |
9 |
9 |
32 |
23.59 |
4 |
10 |
10 |
31 |
17.58 |
14 |
11 |
11 |
30 |
14.72 |
18 |
12 |
12 |
29 |
17.63 |
23 |
13 |
13 |
28 |
23.64 |
8 |
14 |
14 |
27 |
27.22 |
40 |
15 |
15 |
26 |
25.09 |
20 |
16 |
16 |
25 |
19.19 |
35 |
17 |
17 |
24 |
14.96 |
2 |
18 |
18 |
23 |
16.28 |
21 |
19 |
19 |
22 |
21.94 |
11 |
20 |
20 |
21 |
26.74 |
31 |
21 |
21 |
20 |
26.26 |
37 |
22 |
22 |
19 |
20.94 |
5 |
23 |
23 |
18 |
15.68 |
36 |
24 |
24 |
17 |
15.31 |
15 |
25 |
25 |
16 |
20.17 |
30 |
26 |
26 |
15 |
25.79 |
27 |
27 |
27 |
14 |
27.01 |
13 |
28 |
28 |
13 |
22.70 |
12 |
29 |
29 |
12 |
16.83 |
3 |
30 |
30 |
11 |
14.79 |
24 |
31 |
31 |
10 |
18.46 |
39 |
32 |
32 |
9 |
24.46 |
19 |
33 |
33 |
8 |
27.28 |
33 |
34 |
34 |
7 |
24.32 |
1 |
35 |
35 |
6 |
18.31 |
10 |
36 |
36 |
5 |
14.77 |
25 |
37 |
37 |
4 |
16.96 |
34 |
38 |
38 |
3 |
22.86 |
29 |
39 |
39 |
2 |
27.06 |
9 |
40 |
40 |
1 |
25.68 |
26 |
< Previous Page Next Page>

- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine