📄 form2.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form2
Caption = "组态王OPC-Server客户端"
ClientHeight = 9060
ClientLeft = 2115
ClientTop = 975
ClientWidth = 10860
Icon = "Form2.frx":0000
LinkTopic = "Form2"
MaxButton = 0 'False
ScaleHeight = 9060
ScaleWidth = 10860
Begin VB.CommandButton CmdDelItem
Enabled = 0 'False
Height = 495
Left = 3000
Picture = "Form2.frx":27A2
Style = 1 'Graphical
TabIndex = 13
ToolTipText = "删除项目"
Top = 0
Width = 495
End
Begin MSHierarchicalFlexGridLib.MSHFlexGrid MSHFlexGrid1
Height = 8055
Left = 3480
TabIndex = 9
ToolTipText = "数据区"
Top = 600
Width = 7335
_ExtentX = 12938
_ExtentY = 14208
_Version = 393216
MergeCells = 1
AllowUserResizing= 1
RowSizingMode = 1
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
BeginProperty FontFixed {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_NumberOfBands = 1
_Band(0).Cols = 2
End
Begin VB.CommandButton CmdExit
Height = 495
Left = 6000
Picture = "Form2.frx":2BE4
Style = 1 'Graphical
TabIndex = 8
ToolTipText = "退出"
Top = 0
Width = 495
End
Begin VB.CommandButton CmdWrite
Height = 495
Left = 2400
Picture = "Form2.frx":3026
Style = 1 'Graphical
TabIndex = 7
ToolTipText = "写项目"
Top = 0
Width = 495
End
Begin VB.CommandButton CmdHelp
Height = 495
Left = 5280
Picture = "Form2.frx":3468
Style = 1 'Graphical
TabIndex = 6
ToolTipText = "帮助"
Top = 0
Width = 495
End
Begin VB.CommandButton CmdAdd
Height = 495
Left = 1800
Picture = "Form2.frx":38AA
Style = 1 'Graphical
TabIndex = 5
ToolTipText = "添加项目"
Top = 0
Width = 495
End
Begin VB.CommandButton Cmdunconnect
Height = 495
Left = 720
Picture = "Form2.frx":3CEC
Style = 1 'Graphical
TabIndex = 4
ToolTipText = "断开服务器"
Top = 0
Width = 495
End
Begin VB.CommandButton Cmdconnect
Height = 495
Left = 120
Picture = "Form2.frx":412E
Style = 1 'Graphical
TabIndex = 3
ToolTipText = "连接服务器"
Top = 0
Width = 495
End
Begin MSComctlLib.Toolbar Toolbar1
Align = 1 'Align Top
Height = 495
Left = 0
TabIndex = 2
ToolTipText = "工具栏"
Top = 0
Width = 10860
_ExtentX = 19156
_ExtentY = 873
ButtonWidth = 609
ButtonHeight = 714
Appearance = 1
_Version = 393216
BorderStyle = 1
Begin VB.Timer Timer2
Interval = 1000
Left = 7440
Top = 120
End
Begin VB.CommandButton Command1
Height = 495
Left = 3840
Picture = "Form2.frx":4570
Style = 1 'Graphical
TabIndex = 10
ToolTipText = "修改采集频率"
Top = 0
Width = 495
End
Begin VB.Timer Timer1
Interval = 1000
Left = 6600
Top = 120
End
End
Begin MSComctlLib.StatusBar StatusBar1
Align = 2 'Align Bottom
Height = 375
Left = 0
TabIndex = 1
ToolTipText = "状态栏"
Top = 8685
Width = 10860
_ExtentX = 19156
_ExtentY = 661
_Version = 393216
BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
NumPanels = 4
BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Object.Width = 5292
MinWidth = 5292
EndProperty
BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Object.Width = 3528
MinWidth = 3528
EndProperty
BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Object.Width = 6703
MinWidth = 6703
EndProperty
BeginProperty Panel4 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Object.Width = 3070
MinWidth = 3070
EndProperty
EndProperty
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Times New Roman"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin VB.ListBox List1
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 7020
Left = 0
TabIndex = 0
Top = 1080
Width = 3375
End
Begin VB.Label Label2
BorderStyle = 1 'Fixed Single
Caption = "项目的数量为: 个"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 405
Left = 0
TabIndex = 12
Top = 8160
Width = 3375
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "当前选择的变量列表:"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00C00000&
Height = 240
Left = 120
TabIndex = 11
Top = 720
Width = 2400
End
Begin VB.Menu mnufile
Caption = "文件(&F)"
Begin VB.Menu mnusave
Caption = "保存"
End
Begin VB.Menu mnuprint
Caption = "打印"
End
Begin VB.Menu mnud1
Caption = "-"
End
Begin VB.Menu mnuexit
Caption = "退出(&X)"
End
End
Begin VB.Menu mnuedit
Caption = "编辑(&E)"
Begin VB.Menu mnuchange
Caption = "修改采集频率"
End
End
Begin VB.Menu mnuopc
Caption = "OPC"
Begin VB.Menu mnuconnect
Caption = "连接服务器"
End
Begin VB.Menu mnuread
Caption = "读变量"
Begin VB.Menu mnureadstart
Caption = "开始"
End
Begin VB.Menu mnureadstop
Caption = "停止"
End
End
Begin VB.Menu mnuwrite
Caption = "写变量"
End
Begin VB.Menu mnugetitemname
Caption = "获取项目名"
End
Begin VB.Menu mnudelitem
Caption = "删除项目"
Enabled = 0 'False
End
Begin VB.Menu mnud3
Caption = "-"
End
Begin VB.Menu mnuunconnect
Caption = "断开服务器"
End
End
Begin VB.Menu mnuhel
Caption = "帮助(&H)"
Begin VB.Menu mnuhelp
Caption = "帮助主题"
End
Begin VB.Menu mnud2
Caption = "-"
End
Begin VB.Menu mnuabout
Caption = "关于"
End
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub CmdAdd_Click()
If biaozhi = 0 Then
MsgBox "服务器已被断开,请先连接服务器" + Chr(13) + Chr(10) + "然后再试。", 48, "警告"
Exit Sub
End If
Form3.Show
End Sub
Private Sub Cmdconnect_Click() '连接服务器
Dim pNode As String
Dim ret As Integer
Timer1.Enabled = True
ret = StartCliend(pNode)
If ret <> 0 Then
MsgBox "连接服务器错误!错误号=" + Str(ret), 48, "错误"
End If
If ret = 0 Then
StatusBar1.Panels(1).Text = "连接服务器成功"
biaozhi = 10
End If
End Sub
Private Sub CmdDelItem_Click()
Form6.Show
End Sub
Private Sub CmdExit_Click()
Dim ret As Integer
Timer1.Enabled = False
ret = StopCliend()
If ret <> 0 Then
MsgBox "断开服务器失败,错误号=" + Str(ret), 48, "警告"
Exit Sub
End If
End
End Sub
Private Sub CmdHelp_Click()
Form5.Show
End Sub
Private Sub Cmdunconnect_Click() '断开服务器
Dim ret As Integer
Timer1.Enabled = False
ret = StopCliend()
If ret <> 0 Then
MsgBox "断开服务器错误!错误号=" + Str(ret), 48, "错误"
End If
If ret = 0 Then
StatusBar1.Panels(1).Text = "服务器断开"
biaozhi = 0
MSHFlexGrid1.Cols = 4
MSHFlexGrid1.Rows = 2
MSHFlexGrid1.TextMatrix(1, 0) = " "
MSHFlexGrid1.TextMatrix(1, 1) = " "
MSHFlexGrid1.TextMatrix(1, 2) = " "
MSHFlexGrid1.TextMatrix(1, 3) = " "
TagNo = 0
List1.Clear
End If
End Sub
Private Sub CmdWrite_Click()
Dim ret, i As Integer
Dim bVal As Boolean
Dim lVal As Long
Dim fVal As Single
Dim sVal As String
'ret = WriteTag(i, bVal, lal, fVal, sVal)
Form4.Show
End Sub
Private Sub Command1_Click()
Timer1.Enabled = False
Dialog.Show
End Sub
Private Sub Form_Load() '初始化表格
mnusave.Enabled = False
mnureadstart.Enabled = False
MSHFlexGrid1.Rows = 2
MSHFlexGrid1.Cols = 4
MSHFlexGrid1.TextMatrix(0, 0) = "变量ID号"
MSHFlexGrid1.TextMatrix(0, 1) = "变量名称"
MSHFlexGrid1.TextMatrix(0, 2) = "变量类型"
MSHFlexGrid1.TextMatrix(0, 3) = "变量数值"
StatusBar1.Panels(1).Text = "未连接服务器"
StatusBar1.Panels(2).Text = "就 绪"
biaozhi = 0 '服务器是否连接
End Sub
Private Sub mnuabout_Click()
frmAbout.Show
End Sub
Private Sub mnuchange_Click()
Timer1.Enabled = False
Dialog.Show
End Sub
Private Sub mnuconnect_Click()
Cmdconnect_Click
End Sub
Private Sub mnudelitem_Click()
'CmdDelItem_Click
End Sub
Private Sub mnuexit_Click()
Dim ret As Integer
ret = StopCliend()
If ret <> 0 Then
MsgBox "断开服务器失败,错误号=" + Str(ret), 48, "警告"
Exit Sub
End If
End
End Sub
Private Sub mnugetitemname_Click()
CmdAdd_Click
End Sub
Private Sub mnuhelp_Click()
Form5.Show
End Sub
Private Sub mnureadstart_Click()
Timer1.Enabled = True
mnureadstart.Enabled = False
mnureadstop.Enabled = True
End Sub
Private Sub mnureadstop_Click()
Timer1.Enabled = False
mnureadstart.Enabled = True
mnureadstop.Enabled = False
End Sub
Private Sub mnuunconnect_Click()
Cmdunconnect_Click
End Sub
Private Sub mnuwrite_Click()
CmdWrite_Click
End Sub
Private Sub Timer1_Timer()
Dim bVal As Boolean
Dim lVal As Long
Dim fVal As Single
Dim sVal As String * 255
Dim i, ret As Integer
For i = 1 To TagNo Step 1
ret = ReadTag(i, bVal, lVal, fVal, sVal)
If ret <> 0 Then
Timer1.Enabled = False
MsgBox "读取数据失败,错误号=" + Str(ret), 48, "错误"
StatusBar1.Panels(2).Text = "读数据" + Str(TagNo) + "失败"
Exit Sub
Else
StatusBar1.Panels(2).Text = "读数据" + Str(TagNo) + "成功"
End If
Select Case Typ(i - 1)
Case 11
Form2.MSHFlexGrid1.TextMatrix(i, 3) = bVal
Case 3
Form2.MSHFlexGrid1.TextMatrix(i, 3) = lVal
Case 4
Form2.MSHFlexGrid1.TextMatrix(i, 3) = fVal
Case 8
Form2.MSHFlexGrid1.TextMatrix(i, 3) = sVal
Case Else
Form2.MSHFlexGrid1.TextMatrix(i, 3) = "读失败"
End Select
Next i
End Sub
Private Sub Timer2_Timer()
StatusBar1.Panels(4).Text = Str(Hour(Now)) + "时" + Str(Minute(Now)) + "分" + Str(Second(Now)) + "秒"
Label2.Caption = "项目的数量为: " + Str(List1.ListCount) + " 个"
StatusBar1.Panels(3).Text = "当前的采集频率为:" + Str(Timer1.Interval) + " 毫秒"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -