由于现场特殊需求,需把ABCD等多个16位变量在某个开关量为0时,分别对应赋值给变量A1B1C1D1,为1时,分别对应赋值给变量A2B2C2D2。这个在C脚本里面怎么实现,也可以提供VBS参考,谢谢。
之前有朋友提供的ifelse语句只能赋值一组,这样需要建四组才能实现目的。不知道大家有没有更简洁的命令语句。
最佳答案
c:
if(GetTagBIt("开关量"))
{
SetTagWord("A2",GetTagWord("A"));
SetTagWord("B2",GetTagWord("B"));
SetTagWord("C2",GetTagWord("C"));
SetTagWord("D2",GetTagWord("D"));
}
else
{
SetTagWord("A1",GetTagWord("A"));
SetTagWord("B1",GetTagWord("B"));
SetTagWord("C1",GetTagWord("C"));
SetTagWord("D1",GetTagWord("D"));
}
vbs:
dimtag(10)
tag(0)=HMIRUNtime.tags("开关量").Read
tag(1)=hmiruntime.tags("A").read
tag(2)=hmiruntime.tags("B").read
tag(3)=hmiruntime.tags("C").read
tag(4)=hmiruntime.tags("D").read
iftag(0)then
hmiruntime.tags("A2").writetag(1)
hmiruntime.tags("B2").writetag(2)
hmiruntime.tags("C2").writetag(3)
hmiruntime.tags("D2").writetag(4)
else
hmiruntime.tags("A1").writetag(1)
hmiruntime.tags("B1").writetag(2)
hmiruntime.tags("C1").writetag(3)
hmiruntime.tags("D1").writetag(4)
endif
提问者对于答案的评价:
ok,对C还是不熟悉,缺少{{}}符号,都是大神啊,真心感谢。!~谢谢两位的真情回答,因为量不多就6个变量,迷失中原你的方案我也会试一试,不过读了你的代码是可以走的同,希望以后能用上,先保留了。