Thanks for the reply. I did declare source as global. And when I run your script snippet, I am able to get the value of sourcetemp. Here’s the whole script, which errors out at ‘get item 1 of’. The code is still ugly.
global source
global plotdata
global fundmaxNO
set fundmaxNO to 6
global nonyear --counts number of blank years
set nonyear to 0
global incrCOL --column counter
set incrCOL to 2
global vleftscale -- the marker variable for whether the left scale will be 25-50-60-or 70,000
set vleftscale to 25000
set source to {} --raw data from Excel spreadsheet
set plotdata to {} --this is the data, scaled
global startpt -- this is the y value for the fund starting at 10,000
set startpt to 76
(*pulls one column of data*)
--to pulldata()
tell application "Microsoft Excel"
repeat while incrCOL ≤ fundmaxNO --steps through columns (funds)
set incrcell to 5
repeat while incrcell ≤ 15 --steps through cells
set vincrcell to (incrcell as string)
set vwhichcell to ""
set vwhichcell to "R" & incrcell & "C" & incrCOL
set vtemp to (get Value of Cell vwhichcell)
set end of source to (get Value of Cell vwhichcell)
set incrcell to incrcell + 1
end repeat --steps through cells
my checkdata()
set incrCOL to incrCOL + 1
end repeat --steps through columns (funds)
end tell
(*checks the data for range and length *)
to checkdata()
tell application "Script Editor"
repeat with anitem in source
if anitem < 1 then
set nonyear to nonyear + 1
else if anitem > 60000 then
set vleftscale to 70000
set startpt to 27.14
else if anitem > 50000 then
set vleftscale to 60000
set startpt to 31.66
else if anitem > 25000 then
set vleftscale to 50000
set startpt to 38
end if
end repeat
if nonyear > 0 then
my trimdata()
end if
my scaledata()
my makegraph()
display dialog vleftscale & nonyear
end tell
end checkdata
(*checks the data and converts it *)
(*trims blank dates from data*)
to trimdata()
repeat (count of nonyear) times
set source to end of source
end repeat
end trimdata
(*trims blank dates from data*)
(*scales data according to which vleftscale is being used (25,50,60,70)*)
to scaledata()
repeat (count of source) times
set sourcetemp to item 1 of source -- ****this is where it errors"Can't get item 1 of 2.612627E+4."
set tempvar to (190 * sourcetemp) / vleftscale
set end of plotdata to tempvar
set source to end of source
end repeat
end scaledata
(*scales data according to which vleftscale is being used (25,50,60,70)*)
(*makes graph*)
to makegraph()
tell application "Adobe Illustrator"
make new document with properties {color space:CMYK}
set spot646 to make new spot in document 1 with properties {name:"PANTONE 646 C", color:{cyan:65.0, magenta:30.0, yellow:0.0, black:11}, color type:spot color}
tell document 1
make new path item at layer "Layer 1" with properties {entire path:{{100, 100}, {250.03, 100}}, stroke width:1.0, name:"line1", filled:false, opacity:100.0, stroke cap:projecting, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, stroked:true}
make new path item at layer "Layer 1" with properties {entire path:{{100, 118}, {250.03, 118}}, stroke width:0.5, name:"line1", filled:false, opacity:30.0, stroke cap:projecting, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, stroked:true}
make new path item at layer "Layer 1" with properties {entire path:{{100, 136}, {250.03, 136}}, stroke width:0.5, name:"line2", filled:false, opacity:30.0, stroke cap:projecting, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, stroked:true}
make new path item at layer "Layer 1" with properties {entire path:{{100, 154}, {250.03, 154}}, stroke width:0.5, name:"line3", filled:false, opacity:30.0, stroke cap:projecting, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, stroked:true}
make new path item at layer "Layer 1" with properties {entire path:{{100, 172}, {250.03, 172}}, stroke width:0.5, name:"line4", filled:false, opacity:30.0, stroke cap:projecting, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, stroked:true}
make new path item at layer "Layer 1" with properties {entire path:{{100, 190}, {250.03, 190}}, stroke width:0.5, name:"line5", filled:false, opacity:30.0, stroke cap:projecting, stroke color:{class:CMYK color info, cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}, stroked:true}
my plotline()
make path item at layer "Layer 1" with properties {entire path:{{100, 100}, {115, 115}, {130, 130}, {145, 145}, {160, 160}, {175, 175}, {190, 190}, {205, 205}, {220, 220}, {235, 152}, {250, 152}}, filled:false, stroke width:2.0, name:"Path2", stroke color:{class:spot color info, tint:100.0, spot:spot "Pantone 646 C"}}
end tell
end tell
end makegraph
(*makes graph*)
to plotline()
if nonyear = 0 then
tell application "Adobe Illustrator"
make path item at layer "Layer 1" with properties {entire path:{{100, startpt}, {115, (item 1 of plotdata)}, {130, (item 2 of plotdata)}, {145, (item 3 of plotdata)}, {160, (item 4 of plotdata)}, {175, (item 5 of plotdata)}, {190, (item 6 of plotdata)}, {205, (item 7 of plotdata)}, {220, item 8 of plotdata}, {235, (item 9 of plotdata)}, {250, (item 10 of plotdata)}}, filled:false, stroke width:2.0, name:"Path2", stroke color:{class:spot color info, tint:100.0, spot:spot "Pantone 646 C"}}
end tell
end if
end plotline
(*makes graph*)
-Ralph