Sub SetControlButton (iIndex,sTag,sText, iForeColor, iBackColor) Dim s1,s2,s3 s1=sText s2="" s3="" If(InStr(1,s1,vbLf)>0) Then s2=Mid(s1,InStr(1,s1,vbLf)+1) s1=Left(s1,InStr(1,s1,vbLf)-1) End If If(InStr(1,s2,vbLf)>0) Then s3=Mid(s2,InStr(1,s2,vbLf)+1) s2=Left(s2,InStr(1,s2,vbLf)-1) End If s1=Replace(s1,vbCr,"") s2=Replace(s2,vbCr,"") s3=Replace(s3,vbCr,"") $PMControlButton[iIndex].Tag=sTag $PMControlButton[iIndex].BackColor=iBackColor $PMControlButton[iIndex].ForeColor=iForeColor $PMControlButton[iIndex].Text0=s1 $PMControlButton[iIndex].Text1=s2 $PMControlButton[iIndex].Text2=s3 End Sub Sub ShowControlButtons() $Close("ctrl01") $Close("ctrl02") $Close("ctrl03") $Open("ctrl00") End Sub Sub ShowControlNumeric(sTarget,sExpression) $Close("ctrl02") $Close("ctrl03") $Close("ctrl00") $Open("ctrl01") $PMControlKeyPad.Title=" Enter"+vbCr+vbLf+" New Value:" $PMControlKeyPad.Text="" $PMControlKeyPad.Done=False $PMControlKeyPad.Type="Number" If(Len(sTarget)>0 And Mid(sTarget,1,1)="$") Then $PMControlKeyPad.Tag=Mid(sTarget,2) Else $PMControlKeyPad.Tag=sTarget End If $PMControlKeyPad.Expression=sExpression $PMControlKeyPad.Label0="CLEAR" $PMControlKeyPad.Cmd0="ControlKeypad_Clear" $PMControlKeyPad.Label1="ENTER" $PMControlKeyPad.Cmd1="ControlKeypad_Enter" $PMControlKeyPad.Label2="" $PMControlKeyPad.Cmd2="" $PMControlKeyPad.Label3="CANCL" $PMControlKeyPad.Cmd3="ControlKeypad_Cancel" End Sub Sub ShowControlPage() $PMControlKeyPad.Title=" Press Page"+vbCr+vbLf+"Number Below" $PMControlKeyPad.Text="" $PMControlKeyPad.Done=False $PMControlKeyPad.Type="Page" $PMControlKeyPad.Tag="" $PMControlKeyPad.Expression="" $PMControlKeyPad.Label0="ALARM" $PMControlKeyPad.Cmd0="ControlKeypad_AlarmPage" $PMControlKeyPad.Label1="MORE" $PMControlKeyPad.Cmd1="ControlKeypad_MorePages" $PMControlKeyPad.Label2="DIR" $PMControlKeyPad.Cmd2="ControlKeypad_DirPage" $PMControlKeyPad.Label3="" $PMControlKeyPad.Cmd3="" $PMControlKeyPad.Dir=-1 $Open("ctrl01") $Close("ctrl03") $Close("ctrl00") $Close("ctrl02") End Sub Sub ShowControlTrend(SourceControl) Dim nPens,nPenFlags,i nPenFlags=SourceControl.GetPenFlags() nPens=0 For i=1 To 6 nPens=nPens+(1 And nPenFlags) nPenFlags=CInt(nPenFlags/2) Next If(nPens<2) Then ShowControl SourceControl, "" Else $PMControlTrend.Trend=SourceControl.GetID() $PMControlTrend.CurrentPen=SourceControl.CurrentPen $PMControlTrend.Tag=SourceControl.ControlNumericTarget $PMControlTrend.Expression=SourceControl.ControlNumericExpression $PMControlTrend.Flags=SourceControl.GetPenFlags() $PMControlTrend.ControlType=SourceControl.ControlType If SourceControl.ControlType=1 Then Call SetControlButton (0,SourceControl.ControlButton1Tag, SourceControl.ControlButton1Label, SourceControl.ControlButton1ForeColor, SourceControl.ControlButton1BackColor) Call SetControlButton (1,SourceControl.ControlButton2Tag, SourceControl.ControlButton2Label, SourceControl.ControlButton2ForeColor, SourceControl.ControlButton2BackColor) Call SetControlButton (2,SourceControl.ControlButton3Tag, SourceControl.ControlButton3Label, SourceControl.ControlButton3ForeColor, SourceControl.ControlButton3BackColor) Call SetControlButton (3,SourceControl.ControlButton4Tag, SourceControl.ControlButton4Label, SourceControl.ControlButton4ForeColor, SourceControl.ControlButton4BackColor) Call SetControlButton (4,SourceControl.ControlButton5Tag, SourceControl.ControlButton5Label, SourceControl.ControlButton5ForeColor, SourceControl.ControlButton5BackColor) End If $Open("ctrl02") $Close("ctrl03") $Close("ctrl01") $Close("ctrl00") End If End Sub Sub ShowControlAlarm() $Open("ctrl03") $Close("ctrl02") $Close("ctrl01") $Close("ctrl00") End Sub Sub ShowControl(SourceControl, ControlName) On Error Resume Next $PMSelectedControl = "" If SourceControl.ControlType=1 Then Call SetControlButton (0,SourceControl.ControlButton1Tag, SourceControl.ControlButton1Label, SourceControl.ControlButton1ForeColor, SourceControl.ControlButton1BackColor) Call SetControlButton (1,SourceControl.ControlButton2Tag, SourceControl.ControlButton2Label, SourceControl.ControlButton2ForeColor, SourceControl.ControlButton2BackColor) Call SetControlButton (2,SourceControl.ControlButton3Tag, SourceControl.ControlButton3Label, SourceControl.ControlButton3ForeColor, SourceControl.ControlButton3BackColor) Call SetControlButton (3,SourceControl.ControlButton4Tag, SourceControl.ControlButton4Label, SourceControl.ControlButton4ForeColor, SourceControl.ControlButton4BackColor) Call SetControlButton (4,SourceControl.ControlButton5Tag, SourceControl.ControlButton5Label, SourceControl.ControlButton5ForeColor, SourceControl.ControlButton5BackColor) $PMSelectedControl = ControlName ShowControlButtons() ElseIf SourceControl.ControlType=2 Then $PMSelectedControl = ControlName ShowControlNumeric SourceControl.ControlNumericTarget,SourceControl.ControlNumericExpression End If End Sub Sub ControlKeypad_OnDown(sKey) $PMControlKeyPad.Key=sKey End Sub Sub ControlKeypad_OnUp(sKey) $PMControlKeyPad.Key="" If(Left(sKey,1)="K") Then Dim sCommand If sKey="K0" Then sCommand=$PMControlKeyPad.Cmd0 ElseIf sKey="K1" Then sCommand=$PMControlKeyPad.Cmd1 ElseIf sKey="K2" Then sCommand=$PMControlKeyPad.Cmd2 ElseIf sKey="K3" Then sCommand=$PMControlKeyPad.Cmd3 End If Execute(sCommand) Else If $PMControlKeyPad.Type="Number" Then If $PMControlKeyPad.Done Then $PMControlKeyPad.Done=False $PMControlKeyPad.Text="" End If If Len($PMControlKeyPad.Text)>=11 Then Exit Sub End If If sKey="." And InStr(1,$PMControlKeyPad.Text,".")>0 Then Exit Sub End If If sKey="-" And Len($PMControlKeyPad.Text)>0 Then Exit Sub End If $PMControlKeyPad.Text=$PMControlKeyPad.Text+sKey ElseIf $PMControlKeyPad.Type="Page" Then If $PMControlKeyPad.Done Then $PMControlKeyPad.Done=False $PMControlKeyPad.Text="" End If If sKey="." Or sKey="-" Then Exit Sub End If If Len($PMControlKeyPad.Text)>=2 Then Exit Sub End If $PMControlKeyPad.Text=$PMControlKeyPad.Text+sKey If Len($PMControlKeyPad.Text)=2 Then ControlKeypad_EnterPage End If $PMControlKeyPad.Cmd0="ControlKeypad_ClearPage" $PMControlKeyPad.Label0="CLEAR" $PMControlKeyPad.Cmd1="ControlKeypad_EnterPage" $PMControlKeyPad.Label1="ENTER" End If End If End Sub Sub ControlKeypad_Clear $PMControlKeyPad.Text="" End Sub Sub ControlKeypad_Enter Dim sValue sValue=$PMControlKeyPad.Text If Trim(sValue)<>"" Then $@PMControlKeyPad.Tag=EvalExp($PMControlKeyPad.Expression,sValue) $PMControlKeyPad.Done=True End If End Sub Sub ControlKeypad_Cancel $PMSelectedControl ="" $PMControlKeyPad.Text="" $Close("ctrl01") End Sub Sub ControlKeypad_ClearPage $PMControlKeyPad.Text="" $PMControlKeyPad.Label0="ALARM" $PMControlKeyPad.Cmd0="ControlKeypad_AlarmPage" $PMControlKeyPad.Label1="MORE" $PMControlKeyPad.Cmd1="ControlKeypad_MorePages" End Sub Sub ControlKeypad_EnterPage Dim sScreenNum sScreenNum=$PMControlKeyPad.Text If Len(sScreenNum)<2 Then sScreenNum="0"+sScreenNum End If If sScreenNum<>"" Then $PMControlKeyPad.Done=True $Close("ScreenDir") $Close("Ctrl01") If Not $IsScreenOpen("Screen"+sScreenNum) Then If $PMIsWebClient>0 Then $Open("Screen"&sScreenNum) ElseIf $FindFile($GetAppPath()&"\Screen\Screen"&sScreenNum+".sc*")>0 Then $Open("Screen"&sScreenNum) End If End If End If End Sub Sub ControlKeypad_AlarmPage $Open("ScreenAlarm") End Sub Sub ControlKeypad_MorePages $Open("ScreenConfig") End Sub Sub ControlKeypad_DirPage If $PMControlKeyPad.Dir<0 Then $PMControlKeyPad.Dir=0 Else $PMControlKeyPad.Dir=$PMControlKeyPad.Dir+10 End If If $PMControlKeyPad.Dir>99 Then $PMControlKeyPad.Dir=0 End If $Open("ScreenDir") End Sub Sub ControlTrend_Next Dim sCurrentTrend,nCurrentPen,nUsedPens,i sCurrentTrend=$PMControlTrend.Trend nCurrentPen=$PMControlTrend.CurrentPen nUsedPens=$PMControlTrend.Flags For i=1 To 6 nCurrentPen=nCurrentPen+1 If(nCurrentPen>6) Then nCurrentPen=1 End If If (2^(nCurrentPen-1) And nUsedPens)>0 Then Exit For End If Next $PMControlTrend.CurrentPen=nCurrentPen $PMControlTrend.Msg=sCurrentTrend+","+CStr(nCurrentPen) End Sub Sub ControlTrend_Previous Dim sCurrentTrend,nCurrentPen,nUsedPens,i sCurrentTrend=$PMControlTrend.Trend nCurrentPen=$PMControlTrend.CurrentPen nUsedPens=$PMControlTrend.Flags For i=1 To 6 nCurrentPen=nCurrentPen-1 If(nCurrentPen<1) Then nCurrentPen=6 End If If (2^(nCurrentPen-1) And nUsedPens)>0 Then Exit For End If Next $PMControlTrend.CurrentPen=nCurrentPen $PMControlTrend.Msg=sCurrentTrend+","+CStr(nCurrentPen) End Sub Sub ControlTrend_ChangeValue Dim sTarget, sExpression If $PMControlTrend.ControlType=2 Then sTarget=$PMControlTrend.Tag sExpression=$PMControlTrend.Expression ShowControlNumeric sTarget,sExpression ElseIf $PMControlTrend.ControlType=1 Then ShowControlButtons() End If End Sub Sub ControlAlarm_AckAllAlarms If $PMControlKeyPad.AckAll=0 Then $PMControlKeyPad.AckAll=1 Else $PMControlKeyPad.AckAll=0 End If End Sub Sub ControlAlarm_AckCurrAlarm If $PMControlKeyPad.AckTag<>"" Then If $@PMControlKeyPad.AckTag->Ack=1 Then $@PMControlKeyPad.AckTag->Ack=0 Else $@PMControlKeyPad.AckTag->Ack=0 End If End If End Sub Function EvalExp(sExpression,sValue) Dim vExpression1, vExpression2 Dim Length, PosTag, Pos,vChar vExpression1=Replace(sExpression,"?","("+sValue+")") Length = Len(vExpression1) vExpression2="" Pos =1 While (InStr(Pos,vExpression1, "$")<>0) PosTag=InStr(Pos,vExpression1, "$") vExpression2=vExpression2+ Mid(vExpression1,Pos,PosTag-Pos) Pos=PosTag Do Pos=Pos+1 vChar= Mid(vExpression1, Pos, 1) Loop While ( ( (vChar>="A" And vChar<="Z") Or (vChar>="a" And vChar<="z") Or (vChar>="0" And vChar<="9") Or vChar="_") And Pos<=Length) If(Pos>PosTag+1) Then $PMControlKeyPad.Pointer= Mid(vExpression1, PosTag+1, Pos-PosTag-1) vExpression2=vExpression2 +"("+ Replace(CStr($@PMControlKeyPad.Pointer),",",".")+")" End If Wend If(Pos<=Length) Then vExpression2=vExpression2+Mid(vExpression1,Pos,Length-Pos+1) End If EvalExp=CDbl(Eval(vExpression2)) End Function Function To01(val) If(val=0) Then To01=0 Else To01=1 End If End Function Function UW(X) If X<0 Then UW=Int(X)+2^32 Else UW=Int(X) End If End Function Function SW(X) If X>=2^31 Then SW=Int(X)-2^32 Else SW=Int(X) End If End Function Function bitnot(X) bitnot=SW(Not(UW(X))) End Function Function bitand(a,b) bitnot=SW(UW(a) And UW(b)) End Function Function bitxor(a,b) bitxor=SW(UW(a) Xor UW(b)) End Function Function bitor(a,b) bitor=SW(UW(a) Or UW(b)) End Function Function shiftR(a,b) shiftR=SW(UW(a)/(2^b)) End Function Function shiftL(a,b) shiftL=SW(UW(a)*(2^b)) End Function Function acos(X) If X>=1 Then acos=0 ElseIf X <= -1 Then acos= 4 * Atn(1) Else acos=Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1) End If End Function Function asin(X) If X>=1 Then asin= 2 * Atn(1) ElseIf X <= -1 Then asin= - 2 * Atn(1) Else asin=Atn(X / Sqr(-X * X + 1)) End If End Function