msms_pzUt7Y8i 发表于 2019-3-16 13:44:04

求助,关于IF语句的问题

macro_command main()
short m,n
bool a,b,c,d,e
unsigned short shi,fen
unsigned short shiq1,fenq1,shiq2,fenq2,dl

GetData(shi, "Local HMI", LW, 9019, 1)
GetData(fen, "Local HMI", LW, 9018, 1)
GetData(shiq1, "Local HMI", RW, 44, 1)
GetData(fenq1, "Local HMI", RW, 45, 1)

ifshi==shiq1 and fen==fenq1 and m<5 then

    m=m+1
    SetData(m, "Local HMI", LW, 6000, 1)//加1送显,看程序是否执行
   
    else if shi<>shiq1 and fen<>fenq1then

   
    m=0
   

    end if
    end macro_command
当ifshi==shiq1 and fen==fenq1把m<5删了时,能加1,但当当shi<>shiq1 and fen<>fenq1时不归零,这是什么原因,各位老师帮我看看

文鸿旭 发表于 2019-3-23 09:59:53

修改如下:
macro_command main()
short m,n
bool a,b,c,d,e
unsigned short shi,fen
unsigned short shiq1,fenq1,shiq2,fenq2,dl

GetData(shi, "Local HMI", LW, 9019, 1)
GetData(fen, "Local HMI", LW, 9018, 1)
GetData(shiq1, "Local HMI", RW, 44, 1)
GetData(fenq1, "Local HMI", RW, 45, 1)

ifshi==shiq1 and fen==fenq1 and m<5 then

   m=m+1   
   else if shi<>shiq1 and fen<>fenq1then

   
   m=0
   
   
   end if

   SetData(m, "Local HMI", LW, 6000, 1)//加1送显,看程序是否执行

   end macro_command

pcsms_z6P1mUJD 发表于 2019-4-17 23:02:33



macro_command main()
short m,n
bool a,b,c,d,e
unsigned short shi,fen
unsigned short shiq1,fenq1,shiq2,fenq2,dl

GetData(shi, "Local HMI", LW, 9019, 1)
GetData(fen, "Local HMI", LW, 9018, 1)
GetData(shiq1, "Local HMI", RW, 44, 1)
GetData(fenq1, "Local HMI", RW, 45, 1)
GetData(m, "Local HMI", RW, 46, 1)

ifshi==shiq1 and fen==fenq1 and m<5 then

      m=m+1   
      else if shi<>shiq1 and fen<>fenq1then

   
      m=0
   
   
      end if

      SetData(m, "Local HMI", LW, 6000, 1)//加1送显,看程序是否执行

   end macro_command
页: [1]
查看完整版本: 求助,关于IF语句的问题