多个变量为一个数值时,来改变颜色有没有简单的写法。我有50个变量

#include "apdefap.h"
 long _main(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
// WINCC:TAGNAME_SECTION_START
// syntax: #define TagNameInAction "DMTagName"
// next TagID : 1
#define TAG_1 "座椅1接收数据块_r_r9"
#define TAG_2 "座椅2接收数据块_r_r9"
#define TAG_3 "座椅3接收数据块_r_r9"

#define TAG_7 "座椅7接收数据块_r_r9"


// WINCC:PICNAME_SECTION_START
// syntax: #define PicNameInAction "PictureName"
// next PicID : 1
// WINCC:PICNAME_SECTION_END

if  ( GetTagWord(TAG_1)==1401 || GetTagWord(TAG_1)==1500 || GetTagWord(TAG_1)==1510 || GetTagWord(TAG_1)==1600|| GetTagWord(TAG_1)==1700 || GetTagWord(TAG_1)==2200 || GetTagWord(TAG_1)==2500|| GetTagWord(TAG_1)==2501 || GetTagWord(TAG_1)==2502|| GetTagWord(TAG_1)==2510|| GetTagWord(TAG_1)==2520 || GetTagWord(TAG_1)==2530 || GetTagWord(TAG_1)==2600|| GetTagWord(TAG_1)==2610 || GetTagWord(TAG_1)==2620 || GetTagWord(TAG_1)==2630|| GetTagWord(TAG_1)==2631 || GetTagWord(TAG_1)==2640|| GetTagWord(TAG_1)==2645|| GetTagWord(TAG_1)==2650 || GetTagWord(TAG_1)==2660|| GetTagWord(TAG_1)==2661 || GetTagWord(TAG_1)==2900 || GetTagWord(TAG_1)==3000 || GetTagWord(TAG_1)==3100 || GetTagWord(TAG_1)==3110 || GetTagWord(TAG_1)==3600 || GetTagWord(TAG_1)==3601 || GetTagWord(TAG_2)==1401 || GetTagWord(TAG_2)==1500 || GetTagWord(TAG_2)==1510 || GetTagWord(TAG_2)==1600|| GetTagWord(TAG_2)==1700 || GetTagWord(TAG_2)==2200 || GetTagWord(TAG_2)==2500|| GetTagWord(TAG_2)==2501 || GetTagWord(TAG_2)==2502|| GetTagWord(TAG_2)==2510|| GetTagWord(TAG_2)==2520 || GetTagWord(TAG_2)==2530 || GetTagWord(TAG_2)==2600|| GetTagWord(TAG_2)==2610 || GetTagWord(TAG_2)==2620 || GetTagWord(TAG_2)==2630|| GetTagWord(TAG_2)==2631 || GetTagWord(TAG_2)==2640|| GetTagWord(TAG_2)==2645|| GetTagWord(TAG_2)==2650 || GetTagWord(TAG_2)==2660|| GetTagWord(TAG_2)==2661 || GetTagWord(TAG_2)==2900 || GetTagWord(TAG_2)==3000 || GetTagWord(TAG_2)==3100 || GetTagWord(TAG_2)==3110 || GetTagWord(TAG_2)==3600 || GetTagWord(TAG_2)==3601 ||GetTagWord(TAG_3)==1401 || GetTagWord(TAG_3)==1500 || GetTagWord(TAG_3)==1510 || GetTagWord(TAG_3)==1600|| GetTagWord(TAG_3)==1700 || GetTagWord(TAG_3)==2200 || GetTagWord(TAG_3)==2500|| GetTagWord(TAG_3)==2501 || GetTagWord(TAG_3)==2502|| GetTagWord(TAG_3)==2510|| GetTagWord(TAG_3)==2520 || GetTagWord(TAG_3)==2530 || GetTagWord(TAG_3)==2600|| GetTagWord(TAG_3)==2610 || GetTagWord(TAG_3)==2620 || GetTagWord(TAG_3)==2630|| GetTagWord(TAG_3)==2631 || GetTagWord(TAG_3)==2640|| GetTagWord(TAG_3)==2645|| GetTagWord(TAG_3)==2650 || GetTagWord(TAG_3)==2660|| GetTagWord(TAG_3)==2661 || GetTagWord(TAG_3)==2900 || GetTagWord(TAG_3)==3000 || GetTagWord(TAG_3)==3100 || GetTagWord(TAG_3)==3110 || GetTagWord(TAG_3)==3600 || GetTagWord(TAG_3)==3601  )
  return 255;

else
  return 65280;
}

问题补充:
能不能直接用wincc来写,因为plc是别人做的。

最佳答案

定义一个变量数组和数值的数组
使用for循环判断,一旦判断有等于的,直接返回就好了
工作量就是定义变量数组和数值数组的工作了,毕竟这个是少不了的
晚上写个大概的程序~
char *tag[4]={"TEST1","TEST2","TEST3","TEST4"};
int value[5]={1401,1500,1501,1600,1700};
int i,j;

for (i=0;i<4;i++)
{
  for(j=0;j<5;j++)
  {
    if( (GetTagWord(tag[i]))==value[j] )
      {
      return 255;
      } 
   }
}
return 65280;

经测试好使~,有数值相等是红色,否则是绿色

提问者对于答案的评价:
先谢谢了,我试试

原创文章,作者:ximenziask,如若转载,请注明出处:https://www.zhaoplc.com/plc361516.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2021年7月5日
下一篇 2021年7月5日

相关推荐

发表回复

登录后才能评论