Compare incoming against List

Moderator: Moderator Group

Compare incoming against List

Postby azman » Mon Dec 07, 2015 4:49 am

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
azman
 
Posts: 92
Joined: Tue Feb 02, 2010 11:43 pm

Re: Compare incoming against List

Postby azman » Tue Dec 08, 2015 9:50 am

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
azman
 
Posts: 92
Joined: Tue Feb 02, 2010 11:43 pm

Re: Compare incoming against List

Postby Dennis Kuypers » Tue Dec 08, 2015 10:54 am

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
Dennis Kuypers
(former Product Developer, Software)
Dennis Kuypers
coolux Germany
 
Posts: 771
Joined: Thu Jul 05, 2012 12:18 pm

Re: Compare incoming against List

Postby malkuth23 » Tue Dec 08, 2015 11:07 am

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
Matthew Newman-Saul
Theatrical Concepts
mattns@theatrical.com
User avatar
malkuth23
 
Posts: 354
Joined: Tue Apr 20, 2010 7:14 pm
Location: New Orleans, LA


Return to Widget Designer V4.7

Who is online

Users browsing this forum: No registered users and 18 guests