Current Array Status
Hi,
Hope someone can help me here, or at least tell me what I am trying to do is not possible. I've scoured the forum, but found nothing to help.
I am using an array to determine the current open/closed status of 6 room partitions:
INTEGER PART_ARRAY[6] //1 or 0 to state open or closed
INTEGER PANEL_ARRAY[5] //1 or 0 to state which panels in use
All I want to do is read the current status so I can set which slave panels are in use. I assumed the following to work fine, but unfortunately does not:
IF (PART_ARRAY[] = {0,1,1,1,1,1})
{
MASTER_ARRAY[] = {1,0,1,1,1}
}
Can anyone offer any solution to stop my hair falling out.
Much appreciated,
Paul
Hope someone can help me here, or at least tell me what I am trying to do is not possible. I've scoured the forum, but found nothing to help.
I am using an array to determine the current open/closed status of 6 room partitions:
INTEGER PART_ARRAY[6] //1 or 0 to state open or closed
INTEGER PANEL_ARRAY[5] //1 or 0 to state which panels in use
All I want to do is read the current status so I can set which slave panels are in use. I assumed the following to work fine, but unfortunately does not:
IF (PART_ARRAY[] = {0,1,1,1,1,1})
{
MASTER_ARRAY[] = {1,0,1,1,1}
}
Can anyone offer any solution to stop my hair falling out.
Much appreciated,
Paul
Comments
My guess is that if you run 'MSG ON ALL' in terminal you'll see a 'zero index' error when the line runs. Hope that help
e
IF ((!PART_ARRAY[1])&(PART_ARRAY[2])&(PART_ARRAY[3])&(PART_ARRAY[4])&(PART_ARRAY[5])&(PART_ARRAY[6]))
{
MASTER_ARRAY[1]=1
MASTER_ARRAY[2]=0
MASTER_ARRAY[3]=1
MASTER_ARRAY[4]=1
MASTER_ARRAY[5]=1
}
I assumed would work fine as:
IF(PART_ARRAY[]={0,1,1,1,1,1}) MASTER_ARRAY[]={1,0,1,1,1}
or:
IF(PART_ARRAY={0,1,1,1,1,1}) MASTER_ARRAY={1,0,1,1,1}
But unfortunately does not.
If it can't be done, I'll just have to do it the long way
But now that you mention it - I am not sure that I know how to setup that statement with out doing multiple ifs and &&.
have you tried
if(PART_ARRAY = (1,1,1,0,0)) no square brackets no curley brakets? (for the reason that Eric mentioned previously)
if(PART_ARRAY = "1,1,1,0,0"), etc.
Here is a quick attempt at a function:
define_function integer fnCompareMyArray(integer ArrayIn[],integer CompareToThisArray[]){ stack_var integer x; if(max_length_array(CompareToThisArray) > max_length_array(ArrayIn)) return 0; for(x=max_length_array(CompareToThisArray);x;x--){ if(ArrayIn[x] <> CompareToThisArray[x]) return 0; } return 1; } button_event[dvTp,202]{ push:{ local_var integer nMainArray[6]; local_var integer nTestArray[6]; local_var integer nTestArray2[5]; on[nMainArray[1]]; off[nMainArray[2]]; on[nMainArray[3]]; on[nMainArray[4]]; off[nMainArray[5]]; on[nMainArray[6]]; on[nTestArray[1]]; off[nTestArray[2]]; on[nTestArray[3]]; on[nTestArray[4]]; off[nTestArray[5]]; on[nTestArray[6]]; send_string 0,"'Function returned: ',itoa(fnCompareMyArray(nMainArray,nTestArray))"; off[nTestArray[6]]; send_string 0,"'Function returned: ',itoa(fnCompareMyArray(nMainArray,nTestArray))"; on[nTestArray2[1]]; off[nTestArray2[2]]; on[nTestArray2[3]]; on[nTestArray2[4]]; off[nTestArray2[5]]; send_string 0,"'Function returned: ',itoa(fnCompareMyArray(nMainArray,nTestArray2))"; off[nTestArray2[4]]; send_string 0,"'Function returned: ',itoa(fnCompareMyArray(nMainArray,nTestArray2))"; } }But, it seems that Dave's code will do what you want
Jeff
Quality, thanks for that. That sorts out the first part, but unfortunately doesn't work when trying to set the second arrays contents, i.e:
IF (PART_ARRAY = "1,1,1,0,0") // WORKS FINE
{
MASTER_ARRAY="0,0,1,0,1" // Does not work. Sees as string.
MASTER_ARRAY={0,0,1,0,1} // Also, does not work.
MASTER_ARRAY=(0,0,1,0,1) // Also, does not work.
}
Any ideas?
A CHAR variable is actually an 8-bit integer and you can use CHAR variables as flags and such so long as you pay attention. If you do, then such things as
MASTER_ARRAY="0,0,1,0,1"
will work just fine.
Cheers,
Paul
define_constant zone1 = $01 zone2 = $02 zone3 = $04 zone4 = $08 zone5 = $10 zone6 = $20 zone7 = $40 zone8 = $80 define_variable integer PART_STATUS integer MASTER_STATUS . . . if(PART_STATUS & (zone1 + zone3 + zone5)) MASTER_STATUS = zone 2 + zone5; if(PART_STATUS BAND (zone1 + zone3 + zone5)) //same thing using keyword instead of operator. MASTER_STATUS = zone 2 + zone5;This also allows you to easily see if any zone is on (if(PART_STATUS) send_string 0,"'Atleast one zone is ON'")Jeff