FET_Destroyer Posted January 19, 2015 Report Posted January 19, 2015 (edited) Hello guys, I've got a problem that is driving me crazy and I'm prety sure the solution is simple :s So, ive got some strucutres and I'm parsing values from one to the other (same strucutre scheme) in ST language. But if I put all the code in a FOR cicle it give me the error 'Invalid array index'. If instead of an index i put a real value, i've got no error. Can somebody help me with this? what I'm I doeing wrong? -----CODE------ ----DATA TYPES---- ----SYMBOLS----- Regards Edited January 19, 2015 by FET_Destroyer Quote
tashinz Posted January 19, 2015 Report Posted January 19, 2015 Yes, if you use constant instead of symbol index, it will work. If you search cx-programmer help for struct key word you'll get a topic named Structure Symbols, and there you will find the following: Subscripts of Array Data Structures The subscripts must be constants. Symbols, addresses, and formulas cannot be used. I think this is referring to your problem. regards Quote
FET_Destroyer Posted January 19, 2015 Author Report Posted January 19, 2015 Thanks tashinz, I found what you are talking about. Is there any other way to do this? Otherwise I will have to put my FOR cicle into a long code :s Quote
tashinz Posted January 19, 2015 Report Posted January 19, 2015 (edited) Well, Gama_Temporary and Gama_Memory are identical structures. you need only one structure of a kind and then create variables memory and temporary that are types of that structure of yours. then try to simply assign one variable to another, e.g. temporary := memory; I didn't test, I can only see that no error is reported on compiling. the question is if all the data from the structure variable memory is transferred to a temporary structure variable. you should test this. Edited January 19, 2015 by tashinz Quote
tashinz Posted January 19, 2015 Report Posted January 19, 2015 (edited) It works in simulator. And as I can see, now you can use FOR to address a structure variable array, not a member of a structure variable (now you don't need to parse all members to assign values). I've created a simple program (not a FB) in ST: FOR index := 0 TO 4 DO temp_1 := test_1[index]; END_FOR; where temp_1 and test_1 are structure variables. in this example, temp_1 members get values from members of test_1[4], (it works in simulator). regards Edited January 19, 2015 by tashinz Quote
FET_Destroyer Posted January 19, 2015 Author Report Posted January 19, 2015 Thanks tashinz, Another question not completly related with this. I want a array of strings? Is it possible? I simply cannot create an array of strings :s Regards Quote
tashinz Posted January 19, 2015 Report Posted January 19, 2015 indeed, an array of strings is not possible. regards Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.