Page 1 of 1

Compare incoming against List

PostPosted: Mon Dec 07, 2015 4:49 am
by azman
Hello,

I have a project involving incoming TCP string commands,
I am looking for a way to have WD check or recognise whether the incoming string command exists within an existing list (or excel doc?),
If so, then respond with 1 or a True response, if not a 0 or a False response.

The answer is probably right in front of me but lack of sleep is slowing the brain to slow shuffle...

Any suggestions would be helpful,

Regards

Az

Re: Compare incoming against List

PostPosted: Tue Dec 08, 2015 9:50 am
by azman
SOLVED:
I found solution by using the code below, which I placed inside a Macro to make it easier to deal with,
CRES is a variable string which is updated by incoming TCP String from a Crestron device
ACK is a variable that I've used to determine whether existing command exists or not, giving a result of either 1 (if True) or 0 (if False).
The recognised commands are AA, BB or CC.

I'm fairly new to using code, so if anyone can see any issues or more efficient way of doing it please feel to post but its doing what I need it to do at present.
The code is below, feel free to use.

Cheers
Az

Code: Select all
SWITCH VGet CRES
Select Case CRES
Case AA
{
ACK = 1
}
Case Else
Select Case CRES
Case BB
{
ACK = 1
}
Case Else
Select Case CRES
Case CC
{
ACK = 1
}
Case Else
{
ACK = 0
}
End Select

Re: Compare incoming against List

PostPosted: Tue Dec 08, 2015 10:54 am
by Dennis Kuypers
Hello,

I think select case is meant to be used like this:

Code: Select all
Select Case CRES
Case AA
{
ACK = 1
}
Case BB
{
ACK = 1
}
Case CC
{
ACK = 1
}
Case Else
{
ACK = 0
}
End Select

Does that work?

Dennis

Re: Compare incoming against List

PostPosted: Tue Dec 08, 2015 11:07 am
by malkuth23
How about this?
Make an array variable that is something like this: checkArray = AA | BB | CC
Code: Select all
ACK = 0
for 0 to 2
if checkArray[for.index] = CRES
{
ACK = 1
}
Next


Or even a bit better because it will automagically update if you add more commands to your array:

Code: Select all
//check the length of your array
VGetArraySize,checkArraySize,checkArray
//subtract 1 because array counts start at 0
checkArraySize -= 1
ACK = 0
for 0 to checkArraySize
if checkArray[for.index] = CRES
{
ACK = 1
}
Next