⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmtimer.frm

📁 回流焊监控系统-DCS,VB编写,对PLC进行通讯采集和控制,界面直观,操作方便,可以作为同类软件系统提供示范
💻 FRM
📖 第 1 页 / 共 2 页
字号:
         Left            =   2880
         TabIndex        =   27
         Top             =   600
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "关机设置5:"
         Height          =   255
         Index           =   9
         Left            =   2880
         TabIndex        =   26
         Top             =   1800
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "开机设置5:"
         Height          =   255
         Index           =   8
         Left            =   2880
         TabIndex        =   25
         Top             =   1440
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "关机设置3:"
         Height          =   255
         Index           =   5
         Left            =   240
         TabIndex        =   24
         Top             =   2520
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "开机设置3:"
         Height          =   255
         Index           =   4
         Left            =   240
         TabIndex        =   23
         Top             =   2160
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "关机设置2:"
         Height          =   255
         Index           =   3
         Left            =   240
         TabIndex        =   22
         Top             =   1680
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "开机设置2:"
         Height          =   255
         Index           =   2
         Left            =   240
         TabIndex        =   21
         Top             =   1320
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "关机设置1:"
         Height          =   255
         Index           =   1
         Left            =   240
         TabIndex        =   20
         Top             =   840
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "开机设置1:"
         Height          =   255
         Index           =   0
         Left            =   240
         TabIndex        =   19
         Top             =   480
         Width           =   1095
      End
   End
   Begin VB.CommandButton CancelButton 
      Caption         =   "取消"
      Height          =   375
      Left            =   3600
      TabIndex        =   17
      Top             =   4320
      Width           =   1215
   End
   Begin VB.CommandButton OKButton 
      Caption         =   "确定"
      Default         =   -1  'True
      Height          =   375
      Left            =   960
      TabIndex        =   16
      Top             =   4320
      Width           =   1215
   End
End
Attribute VB_Name = "frmTimer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Option Explicit
Dim IsNotFirst As Boolean

Private Sub CancelButton_Click()
 Me.Hide
 frmMain.Enabled = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
Call CancelButton_Click
Cancel = 1
End Sub


Private Sub cbDate_Click()

If bTimeEnd Then
 Exit Sub
End If
bTimeEnd = True
frmMain.sbStatusBar.Panels(1).Text = ""
OKButton.Enabled = False
Timer3.Enabled = True


End Sub

Private Sub ckTime_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If IsNotFirst Then
ckTime(Index).Tag = "1"
End If
End Sub

Private Sub Form_Load()
Dim i As Long
'For i = 0 To txtTime.UBound
'    txtTime(i).Text = ReadInIFiles("Timer", "Time1" & CStr(i), "00:00", iniFile)
'Next
'For i = 0 To ckTime.UBound
'    ckTime(i).Value = Val(ReadInIFiles("Timer", "Timer" & CStr(i), "0", iniFile))
'Next
'bTimeEnd = True
cbDate.AddItem "星期一"
cbDate.AddItem "星期二"
cbDate.AddItem "星期三"
cbDate.AddItem "星期四"
cbDate.AddItem "星期五"
cbDate.AddItem "星期六"
cbDate.AddItem "星期日"
'cbDate.ListIndex = 0


End Sub
Private Sub Form_Activate()
SetDlgBackColor Me

End Sub

Private Sub OKButton_Click()
If bTimeEnd Then
 Exit Sub
End If
frmMain.sbStatusBar.Panels(1).Text = ""
bTimeEnd = True
OKButton.Enabled = False
Timer2.Enabled = True

End Sub

Private Sub Timer1_Timer()
Timer1.Enabled = False
cbDate.ListIndex = 0
End Sub

Private Sub Timer2_Timer()
Dim i As Long, j As Long, k As Long
Dim ss As String
On Error GoTo Errhandle
If Not Ack Then
   Exit Sub
End If
Timer2.Enabled = False
frmInfo.Show , Me
frmInfo.ProgressBar1.Value = 0
For j = 0 To txtTime.UBound
   If txtTime(j).Tag = "1" Then
    i = InStr(1, txtTime(j).Text, ":", vbTextCompare)
    k = Val(Left(txtTime(j).Text, i - 1))
    k = k * 256 + Val(Right(txtTime(j).Text, Len(txtTime(j).Text) - i))
    For i = 0 To 1
      ss = frmMain.PLCCommand(1, 6, DeviceAbsAdd("D" & 513 + j + cbDate.ListIndex * 10), k, 0, "")
      If ss = "" Then
        TimeDelay 300
      Else
        txtTime(j).Tag = 0
        WritePrivateProfileString "Timer", "Time" & cbDate.ListIndex + 1 & CStr(j), txtTime(j).Text, iniFile
        Exit For
      End If
    Next
    If ss = "" Then
         frmMain.sbStatusBar.Panels(1).Text = Time & " D" & 513 + j & "下载失败!"
         Call frmMain.AddErrorLog(frmMain.sbStatusBar.Panels(1).Text)
    End If
   End If
   frmInfo.ProgressBar1.Value = (j + 1) * 1000 / (txtTime.Count + ckTime.Count)
Next
For j = 0 To ckTime.UBound
   If ckTime(j).Tag = "1" Then
    For i = 0 To 1
      ss = frmMain.PLCCommand(1, 6, DeviceAbsAdd("D" & 20 + j + cbDate.ListIndex * 5), ckTime(j).Value, 0, "")
      If ss = "" Then
        TimeDelay 300
      Else
        ckTime(j).Tag = 0
        WritePrivateProfileString "Timer", "Timer" & CStr(j), CStr(ckTime(j).Value), iniFile
        Exit For
      End If
    Next
    If ss = "" Then
         frmMain.sbStatusBar.Panels(1).Text = Time & " D" & 20 + j + cbDate.ListIndex * 5 & "下载失败!"
         Call frmMain.AddErrorLog(frmMain.sbStatusBar.Panels(1).Text)
    End If
   End If
   frmInfo.ProgressBar1.Value = (txtTime.Count + j + 1) * 1000 / (txtTime.Count + ckTime.Count)
Next
GoTo Out
Errhandle:
  frmMain.sbStatusBar.Panels(1).Text = Time & "-运行时间设置 错误:" & Err.description
  Call frmMain.AddErrorLog(frmMain.sbStatusBar.Panels(1).Text)
  Err.Clear
Out:
OKButton.Enabled = True
frmInfo.Hide
bTimeEnd = False
Ack = False
End Sub

Private Sub Timer3_Timer()

Dim i As Long, j As Long
Dim ss As String, tmp As String
If (Not Ack) Then
Exit Sub
End If
Timer3.Enabled = False
For i = 0 To txtTime.UBound
  txtTime(i).Tag = "0"
Next
For i = 0 To ckTime.UBound
  ckTime(i).Tag = "0"
Next
IsNotFirst = False
'For i = 0 To txtTime.UBound
'    txtTime(i).Text = ReadInIFiles("Timer", "Time" & cbDate.ListIndex + 1 & CStr(i), "00:00", iniFile)
'Next

For i = 0 To 1
  ss = frmMain.PLCCommand(1, 3, DeviceAbsAdd("D" & 513 + cbDate.ListIndex * 10), 10, 0, "")
  If ss <> "" Then
    tmp = Mid(ss, 8, 40)
     For j = 0 To 9
       txtTime(j).Text = Format(Hex2Dec(Mid(tmp, j * 4 + 1, 2)), "00") & ":" & Format(Hex2Dec(Mid(tmp, j * 4 + 3, 2)), "00")
     Next
'     Debug.Print tmp
     Exit For
  End If
  TimeDelay 300
Next


For i = 0 To 1
  ss = frmMain.PLCCommand(1, 3, DeviceAbsAdd("D" & 20 + cbDate.ListIndex * 5), 5, 0, "")
  If ss <> "" Then
    tmp = Mid(ss, 8, 20)
     For j = 0 To 4
       ckTime(j).Value = Hex2Dec(Mid(tmp, j * 4 + 1, 4)) Mod 2
     Next
'     Debug.Print tmp
     Exit For
  End If
  TimeDelay 300
Next

If ss = "" Then
     frmMain.sbStatusBar.Panels(1).Text = Time & " D" & 20 + j + cbDate.ListIndex * 5 & "读失败!"
     Call frmMain.AddErrorLog(frmMain.sbStatusBar.Panels(1).Text)
End If
OKButton.Enabled = True
bTimeEnd = False
IsNotFirst = True
Ack = False
'Debug.Print "cbdata"
End Sub

Private Sub txtTime_Change(Index As Integer)
If IsNotFirst Then
txtTime(Index).Tag = "1"
End If
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -