Help with sequence
- Posted by "David Jarvis" <davidj at ultrasmart.org> Apr 14, 2005
- 414 views
Hope you can help Pls refer to the EU code below. A system has 2 different types of inputs: INPUT1 and INPUT2 The system is made up of 4 inputs of type INPUT1, and 4 inputs of type INPUT2. The sequence INPUT1i holds the status values of the 4 inputs of type INPUT1 to the system. INPUTi[1] holds the value of the first input of type INPUT1 ...... etc In the case below the values of each input of type INPUT1 is initially set at 0. Similar explanation for sequence INPUT2i. Sequence InputTypes holds information: 1. the name of the input that is printed to the screen eg "input1" 2. the TYPE of the input eg INPUT1. This is really the primary key for sorting 3. The name of the sequence that hold the values for each input type eg INPUT1i Sequence ChangeStatus is read from a database and depending upoon the values in the sequence, the values in INPUT1i and/or INPUT2i should be changed. The sequence ChangeStatus defines only those inputs which should have their status changed. And it defines what the status shold be changed to. The sequence Chnage Status is made up of sequences. Each of these sequences defines a specific Input: ChangeStatus[1] = type of INPUT to have status changed ChangeStatus[2] = The number of that type of sequence ChangeStatus[3] = The value to change the status to So for ChangeStatus = { {INPUT1, 1, 1} } then this means that INPUT1i[1] should be changed to value 1. If ChangeStatus = { {INPUT1, 1, 1}, {INPUT2, 2, 1} } the this means INPUT1i[1] should be changed to value 1; and INPUT2i[2] should be changed to value 1 The below code changes the values of INPUT1i and INPUT2i elements using a longhand way. But there must be a better and easier way ... which one it know the Input type it picks up the sequence name that holds the current values (InputTypes[j][3]) and then uses this to modify the value representing the current status of the input. -- EU code follows integer INPUT1, INPUT2 INPUT1 = 1 INPUT2 = 2 sequence InputTypes sequence seqText InputTypes = { {"input1", INPUT1, "INPUT1i"}, {"input2", INPUT2, "INPUT2i"}, } sequence INPUT1i, INPUT2i INPUT1i = {0,0,0,0} INPUT2i = {0,0,0,0} sequence ChangeStatus ChangeStatus = { {INPUT1, 1, 1} } -- ******************************** -- longhand code to change values in INPUT1i and/or INPUT2i -- depending upon ChangeStatus -- in this case INPUT1i would change to {1,0,0,0} for i = 1 to length(ChangeStatus) do if ChangeStatus[i][1] = INPUT1 then INPUT1i[2] = ChangeStatus[i][3] elsif ChangeStatus[i][1] = INPUT2 then INPUT2i[2] = ChangeStatus[i][3] end if end for -- end code to change values in INPUT1i to {1,0,0,0} -- better code to change values in INPUT1i, and/or INPUT2i ???? for i = 1 to length(ChangeStatus) do for j = 1 to length(ChangeTypes) do if ChangeStatus[i][1] = InputTypes[j][2] then -- code ?? -- look up value of InputTypes[j][3] this tells us the name of the -- sequence to change the value in and ChangeStatus[i][2] -- tells us the position in the sequence, and -- ChangeStatus[i][3] tells us what to change the value to. end if end for end for -- end better code code to change values in INPUT1i and/or INPUT2i?? -- ******************************** ? INPUT1i -- end Eu code Thanks for your help David