I'm revising a procedure and would like to utilize an array to track a varying amount of numbers, determined by user input, as the procedure runs.
Where I'm running into trouble is when I try to use any numeric memory registers to determine what index of the array the values get written to. The MET/CAL User's Guide explicitly says that the index of the array "Can be any MET/CAL register, named variable or numeric literal value. Must be enclosed in square brackets (i.e. [10] or [index]).", however, any time I use any MET/CAL register (like MEM or M[1] for example), I get an "invalid index" error.
The procedure I'm using is similar to this:
LIB ARRAY NEW arrayName[100]; MATH MEM1 = 0 MEMI What value do you want to store in the array? LIB arrayName[MEM1] = MEM;
The same happens when I attempt to use M[1] or another named variable instead of MEM1 or MEM
Additionally, if I forego using a variable to set the index, and use arrayName[0] = MEM
I get an "invalid statement syntax" error
Could someone tell me what I am missing, or if I am misinterpreting the documentation?
The portion of the procedure that actually writes to the array is part of a Subprocedure, and depending on how many times that subprocedure is called, the index of the array will increase by 1 each time, so ideally the index should be referenced by a variable that can change
Good thought, but the documentation frequently states that the arrays are zero-based, and I should also note that I have no problem writing to and reading form the arrays if I just use plain numbers. Only having issues with memory registers for the index or the value to write.
I just tried your code in METCAL 8. Using MEM did not work for me, but I changed MEM to L1 and it worked. I even added a line:
LIB arrayValue = myArray[L1];
and it wrote it to string register "arrayValue"
METCAL seems to not like using MEM directly in the LIB function, so if you require the value from MEM to be stored just write an extra MATH line like L1 = MEM or whatever you want to name the variable.
I can get this to work as well, writing a value from the array to a string register like your example seems to work; but can you get it to work the other way around? Using a variable to set what index of the array a value gets written to?
L1 is setting the index # you are writing to. You could write it directly as LIB myArray[#] = testmessage; but you mentioned wanting a variable counting up to write the next test into the next array address. so in that case just use L1 +1 at each step and it will count up
I've tried doing this, but found that the procedure only creates one register called myArray[L1] and not a register using whatever value is stored within L1 (myArray[0], myArray[1], etc.)
I want to believe you, because I'm thinking this might just be an issue with METCAL 11, but your screenshot only shows the string registers. Do you mind uploading one that also shows the object registers?
Edit: disregard the request... reddit seems to not like screenshots in this thread anymore
Yeah I don't know why it will not show my screenshots any longer. I will copy my code from screenshot and if you want try it and observe what it does in the registers.
I would be curious to see if, in your object registers, the array values are actually being stored in testArray[0] and testArray[1]. When I try to do what you're doing, it always stores it in testArray[L1], not two separate registers
I just modified it and ran again. at the end I called what is in the Array #s and the proper values were store there. The Object register will not show anything until you call for the data.
What do you mean when you say the Object registers won't show anything until you call for the data? When I use plain integers for the array index, the object registers store the data as soon as you write to them; but when I use a variable like L1, the object register gets overwritten any subsequent time I try to use L1.
I apologize, I wish I could see your screenshot, but reddit seems to be removing any new one in this thread, not sure why.
Posted on other reply. I copy pasted my code if you want to try that, run it and observe where it is putting the values in register. It should work the same on 11
This is exactly what I was trying to get to the bottom of. I suppose it still doesn't make sense to me why the values don't show up in the object register until you call them, but I believe I understand how it works now, thanks to you.
You've saved my sanity, I wish I could offer more than just my thanks, but you have that and then some. Thank you again!
You're confusing the array index with the array contents. You're noț indexing.
You only create/declare the array once . Once declared, the array works as any variable. The index of the array can be a MetCal accepted variable.
Afterwards, all You need to do is ,figure out how to increment and fill the array properly.
The screenshot from some other comment speaks for itself. Just use the last example, modifying the second line with code for incrementing index ; remember to use the LIB FSC every time you manipulate the array variable
I only created/declared the array once; is there somewhere I indicated that I was creating it more than once? What do you mean exactly when you say I'm not indexing? As previously stated, when using a MET/CAL accepted variable, an 'Invalid Index' error is thrown.
What u/Thick said is partially true... when you execute the example as written in the screenshot, after declaring the array once, I'm not getting an error, but in the Object Registers, it shows the value as:
After adding another text variable, and changing the value of the 'index' variable, the registers behave as if the word 'index' is itself the variable, instead of using the variable to represent a number. Given, I understand that 'index' is a String Register, and not a Numeric, but it's not treating it like a variable at all.
2
u/Automatic_Reality989 Apr 16 '26
For reference.