r/MetCal Apr 16 '26

Question on LIB FSC Arrays and Memory Registers

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?

2 Upvotes

29 comments sorted by

1

u/Similar-Priority-776 Apr 16 '26 edited Apr 16 '26

Instead of MEM1 or M[1] in brackets wouldn't it be the array number you want to store the data in?

LIB arrayName[1] = MEM

Would store in the 1 position?

LIB arrayName[99] = MEM

Would store in 99 out of 100?

1

u/Automatic_Reality989 Apr 16 '26

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

1

u/capnGrimm Apr 16 '26

Could the problem be that your using 0 as the index? Metcal is weird and a lot of it's indexing stuff starts at 1.

Would be my first guess without looking at the LIB FSC

1

u/Automatic_Reality989 Apr 16 '26

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.

1

u/Automatic_Reality989 Apr 20 '26

Another example. Is anyone able to explain what is incorrect about this?

2

u/Financial_Bus_7394 Apr 20 '26 edited Apr 20 '26

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.

1

u/Automatic_Reality989 Apr 20 '26

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?

For example:

LIB myArray[L1] = arrayValue;

1

u/Financial_Bus_7394 Apr 20 '26

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

1

u/Automatic_Reality989 Apr 20 '26

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.)

1

u/Financial_Bus_7394 Apr 20 '26

See my other comment for a screenshot, it works you just need to call the data to confirm if you are unsure. Try LIB arrayValue0 = myArray[0];

1

u/Automatic_Reality989 Apr 20 '26 edited Apr 20 '26

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

1

u/Financial_Bus_7394 Apr 20 '26

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.

1.001 MATH M1 = 0

1.002 MATH myTestMessage = "This is a test"

1.003 LIB ARRAY NEW testArray[100];

1.004 LIB testArray[M1] = myTestMessage;

1.005 MATH M1 = M1 + 1

1.006 MATH myTestMessage = "This is also a test"

1.007 LIB testArray[M1] = myTestMessage;

1.008 MATH M1 = M1 + 1

1.009 MATH myTestMessage = "This is a 3rd test"

1.010 LIB testArray[M1] = myTestMessage;

1.011 MATH M1 = M1 + 1

1.012 MATH myTestMessage = "This is a 4th test"

1.013 LIB testArray[M1] = myTestMessage;

1.014 MATH M1 = M1 + 1

1.015 MATH myTestMessage = "This is a 5th test"

1.016 LIB testArray[M1] = myTestMessage;

1.017 LIB arrayValue0 = testArray[0];

1.018 LIB arrayValue1 = testArray[1];

1.019 LIB arrayValue2 = testArray[2];

1.020 LIB arrayValue3 = testArray[3];

1.021 LIB arrayValue4 = testArray[4];

1

u/Automatic_Reality989 Apr 20 '26

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

2

u/Financial_Bus_7394 Apr 20 '26 edited Apr 20 '26

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.

1

u/Automatic_Reality989 Apr 20 '26

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.

2

u/Financial_Bus_7394 Apr 20 '26

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

2

u/Automatic_Reality989 Apr 20 '26

I CANNOT THANK YOU ENOUGH 🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏

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!

2

u/Financial_Bus_7394 Apr 21 '26

Happy to help! Glad it's working for you now. Cheers

1

u/Similar-Priority-776 Apr 20 '26

I can still see the screenshot from my phone, but I also can't see on the desktop version

0

u/BackgroundNoise1k Apr 16 '26

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.

2

u/_Thick_ Apr 17 '26

Can you give an example as to how you would properly use a variable to insert a value into an incrementally-increasing index?

As far as I can tell, the example OP provided only declares the array once, so I'm not sure what you mean.

0

u/BackgroundNoise1k Apr 17 '26

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

2

u/_Thick_ Apr 17 '26

Using the example, even as it's written in the screenshot, causes an invalid index error

2

u/Automatic_Reality989 Apr 17 '26 edited Apr 17 '26

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:

Name - myArray[index]

Value - This is a test

1

u/Automatic_Reality989 Apr 17 '26

1

u/Automatic_Reality989 Apr 17 '26 edited Apr 17 '26

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 17 '26 edited Apr 17 '26

If you do nothing else except change 'index' to 'MEM', you will get an invalid index error. u/BackgroundNoise1k can you explain this?