Hello,
I need to create a single populated array that is available to all procedures in a script file.
I moved the hoursArray inside the SetForAPoint procedure, after the "begin" and it works. But I have more procedures to write and I want them all to reference the one declared array. What I want to do is the example at the end.
I really do not want to declare the array in the main procedure and pass the array to each calling procedure.
The only other thing that compiled, do not know if it will work, is to declare a procedure
procedure GetDatesArray(var theArray);
begin
theArray:=[0,4,8,12,16,20];
end;
And then, in each procedure that needs the array.
var
hoursArray:array;
begin
GetDatesArray(hoursArray);
Not the Pascal way, to me.
Ideas?
Thanks,
Mark
//This is the hours to store the values. Add, change or reduce the values as
//needed. The last hour will generate the report.
hoursArray:=[0,4,8,12,16,20];
//this walks all the values in array hoursArray, combines it with the point
//name and sets the value to the defined constant resetValue.
procedure SetForAPoint(pointName:string);
const
resetValue = 'N/A'; //this is the value to set the global. Change as needed.
var
i:integer;
begin
for i := 0 to length(hoursArray) - 1 do //IntToStr converts the hour number to a string
value:=GlobalSet(pointName,IntToStr(hoursArray),resetValue);
end;
procedure ResetScriptGlobalValues;
begin
//each point need to call the SetForAPoint function.
SetForAPoint('Point_alpha');
SetForAPoint('Point_bravo');
SetForAPoint('Point_charlie');
SetForAPoint('Point_delta');
SetForAPoint('Point_echo');
SetForAPoint('Point_foxtrot');
end;
//this is the main script
begin
end;
You can declare the hoursArray as a variable that is global to the script. But you cannot initialize it there, you must be sure you initialize it at some point before the procedures access to it. If you always execute the script before calling any procedure, you can simply add the initialization code in the main block:
var
hoursArray;
procedure SetForAPoint(pointName:string);
begin
// use hoursArray;
end;
begin
hoursArray:=[0,4,8,12,16,20];
end;
OK, the GetDatesArray(hoursArray); does work
for i := 0 to length(hoursArray) - 1 do
does not work.
Had to change to
for i := 0 to high(hoursArray) do
Still seeking a solution for declaring the array global.
Am I correct, Scripter does not support nested procedure.
Excellent.
Was it working before? There should not be a difference. Nevertheless, hourArray is a variant array, I'm not sure if Length works.
Nested procedures are not supported.
Don't know, I was just trying to get a error free compile at that moment.
The GetDatesArray(hoursArray); worked.
Define the array as a var and initialize in the main procedure works.
Length for the array does not work. Get a convert error at runtime.
High for the array does work.
Thanks.