有C脚本按照下面做,脚本变量lss1可以正常动作,如下
#include "apdefap.h"
int gscAction( void )
{
#pragma option(mbcs)
#pragma code ()
char FileName[20] = " ";
double row=GetTagDouble("行数"); //Return-Type: double
double lsj=GetTagWord("ls");
double lsjj1=GetTagWord("lsjj");
double aa=lsj-lsjj1;
__object* pExcel = NULL;
row=row+1;
lsjj1=lsj;
pExcel = __object_create("Excel.Application");
pExcel->Workbooks ->Open ("e:\\JILU.xlsx");
pExcel->Worksheets("sheet1")->Cells(row,2)->Value=aa;
pExcel->ActiveWorkbook->Save;
pExcel->Workbooks->Close();
pExcel->Quit();
__object_delete(pExcel);
SetTagDouble("行数",row); //Return-Type: BOOL
SetTagDouble("lsjj",lsjj1);
return 0;
}
一旦我把double lsjj1=GetTagWord("lsjj");不与外部变量lsjj链接,改成double lsjj1;并且删除SetTagDouble("lsjj",lsjj1);这一行,内部变量lsjj1在脚本里始终不动作,就是不能执行lsjj1=lsj;,一直都是0.请高手解答,万分感谢!!!
问题补充:
我想执行的脚本是内容是 aa=lsj-lsjj1 然后使lsjj1=lsj,再把aa写到EXCEL里,lsjj1只是脚本中的中间变量,lsj连接着外部的WINCC变量LS,这个变量始终变化,我就想算WINCC外部变量ls在我规定的触发器时间内有了多少变化(增加了多少)。当我把脚本改成如下的时候,我发现lsjj1不动作,,请高人指点,谢谢
#include "apdefap.h"
int gscAction( void )
{
#pragma option(mbcs)
#pragma code ()
char FileName[20] = " ";
double row=GetTagDouble("行数"); //Return-Type: double
double lsj=GetTagWord("ls");
double lsjj1;
double aa=lsj-lsjj1;
__object* pExcel = NULL;
row=row+1;
lsjj1=lsj;
pExcel = __object_create("Excel.Application");
pExcel->Workbooks ->Open ("e:\\JILU.xlsx");
pExcel->Worksheets("sheet1")->Cells(row,2)->Value=aa;
pExcel->ActiveWorkbook->Save;
pExcel->Workbooks->Close();
pExcel->Quit();
__object_delete(pExcel);
SetTagDouble("行数",row); //Return-Type: BOOL
return 0;
}
我已经做过实验了,就是不行,aa始终都是 lsj的值,没有执行在下一次执行脚本时候应该执行的lsjj1=lsj;,就好像aa=lsj-0;一样的效果,请高手帮助解答,谢谢
最佳答案
你的脚本里没有输出lsjj1,你怎么知道“不能执行lsjj1=lsj,一直都是0”。
你是不是把脚本的变量和WinCC的内部变量混淆了。
————————————————————————————————————————
明白你的意思了,你是想lsjj1保持上一次的值,你应该声明为静态变量,即数据类型double 前面加上静态变量声明标识static。
提问者对于答案的评价:
真乃高人也!!! 万分感谢 ,我的QQ是46684613, 期待高人youhm您的帮助! 谢谢了
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc263352.html