📄 form1.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "湿度计"
ClientHeight = 3150
ClientLeft = 150
ClientTop = 720
ClientWidth = 6135
Icon = "Form1.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
Picture = "Form1.frx":492A
ScaleHeight = 3150
ScaleWidth = 6135
StartUpPosition = 3 '窗口缺省
Begin VB.Timer Timer1
Left = 5160
Top = 2760
End
Begin MSCommLib.MSComm MSComm1
Left = 5520
Top = 2640
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin MSComctlLib.StatusBar StatusBar1
Align = 2 'Align Bottom
Height = 375
Left = 0
TabIndex = 2
Top = 2775
Width = 6135
_ExtentX = 10821
_ExtentY = 661
_Version = 393216
BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
NumPanels = 3
BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Object.Width = 7091
MinWidth = 7091
EndProperty
BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Object.Width = 1834
MinWidth = 1834
EndProperty
BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628}
Object.Width = 1834
MinWidth = 1834
EndProperty
EndProperty
End
Begin VB.PictureBox Picture1
BackColor = &H80000000&
Height = 2775
Left = 0
ScaleHeight = 2715
ScaleWidth = 6075
TabIndex = 0
Top = 0
Width = 6135
Begin VB.PictureBox Picture4
Height = 1215
Left = 120
ScaleHeight = 1155
ScaleWidth = 2475
TabIndex = 17
Top = 1440
Width = 2535
Begin VB.CommandButton Command1
Caption = "刷新一次"
Height = 375
Left = 1080
TabIndex = 18
Top = 600
Width = 975
End
Begin VB.Label Label1
Caption = "刷新频率:"
Height = 255
Left = 120
TabIndex = 20
Top = 720
Width = 1095
End
Begin VB.Label Label3
Caption = "手动测量:"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 19
Top = 240
Width = 1215
End
End
Begin VB.TextBox Text5
Height = 495
Left = 600
TabIndex = 16
Text = "1"
Top = 1800
Width = 1335
End
Begin VB.PictureBox Picture5
Height = 2535
Left = 2760
ScaleHeight = 2475
ScaleWidth = 3075
TabIndex = 6
Top = 120
Width = 3135
Begin VB.TextBox Text4
Height = 375
Left = 1080
TabIndex = 15
Top = 1920
Width = 1815
End
Begin VB.TextBox Text3
Height = 375
Left = 1080
TabIndex = 14
Top = 1440
Width = 1815
End
Begin VB.TextBox Text2
Height = 375
Left = 1080
TabIndex = 13
Top = 960
Width = 1815
End
Begin VB.TextBox Text1
Height = 375
Left = 1080
TabIndex = 12
Top = 480
Width = 1815
End
Begin VB.Label Label9
Caption = "平均等级:"
Height = 255
Left = 120
TabIndex = 11
Top = 2160
Width = 975
End
Begin VB.Label Label8
Caption = "平均湿度:"
Height = 255
Left = 120
TabIndex = 10
Top = 1680
Width = 975
End
Begin VB.Label Label7
Caption = "等 级:"
Height = 255
Left = 120
TabIndex = 9
Top = 1200
Width = 1095
End
Begin VB.Label Label6
Caption = "湿 度:"
Height = 255
Left = 120
TabIndex = 8
Top = 720
Width = 1095
End
Begin VB.Label Label5
Caption = "湿度情况:"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 7
Top = 240
Width = 1215
End
End
Begin VB.PictureBox Picture2
Height = 1215
Left = 120
ScaleHeight = 1155
ScaleWidth = 2475
TabIndex = 1
Top = 120
Width = 2535
Begin VB.ComboBox Combo2
Height = 300
Left = 1080
TabIndex = 5
Text = "5s/次"
Top = 720
Width = 1215
End
Begin VB.Label Label4
Caption = "刷新频率:"
Height = 255
Left = 120
TabIndex = 4
Top = 840
Width = 975
End
Begin VB.Label Label2
Caption = "自动测量:"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 120
TabIndex = 3
Top = 240
Width = 1095
End
End
End
Begin VB.Menu File
Caption = "文件"
Begin VB.Menu Start
Caption = "启动"
End
Begin VB.Menu Search
Caption = "查询"
End
Begin VB.Menu Cut
Caption = "-"
End
Begin VB.Menu Quit
Caption = "退出"
End
End
Begin VB.Menu Exit
Caption = "退出"
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
'Private Sub Command1_Click()
'If MSComm1.PortOpen = False Then
'MSComm1.PortOpen = True
'End If
'MSComm1.Output = "0"
'MSComm1.PortOpen = False
'End Sub
Private Sub Form_Load()
Combo2.AddItem "5s/次"
Combo2.AddItem "10s/次"
Combo2.AddItem "0.5m/次"
Combo2.AddItem "1m/次"
Combo2.AddItem "5m/次"
Timer1.Interval = 200
End Sub
'Private Sub Form_Unload(Cancel As Integer)
'Form2.Hide
'End Sub
Private Sub MSComm1_OnComm()
Dim BytesReceived() As Byte
Dim buffer As String
Dim screen, hData, deplay, grade As String
Dim i, d As Integer
Dim l As Single
Select Case MSComm1.CommEvent
Case comEvReceive
buffer = MSComm1.Input
BytesReceived() = buffer
For i = 0 To UBound(BytesReceived) 'LBoud()数组下标上界,返回一个 Long 型数据,其值为指定的数组维可用的最大下标
If Len(Hex(BytesReceived(i))) = 1 Then 'Hex()返回十六进制数值的 String
hData = 0 & Hex(BytesReceived(i))
Else
hData = Hex(BytesReceived(i))
End If
screen = screen & hData
Next
deplay = Mid$(screen, 1, 2) & Mid$(screen, 5, 2) 'Mid$(C,M,N)从第M个字符起,取C中N个字符
deplay = "&h" & deplay
d = Val(deplay) - 248
l = d * 3.3 * 100 / 3.1 / 1024
Text1.Text = Str(l)
If l < 10 Then grade = "过干"
If l >= 10 Then grade = "干燥"
If l >= 20 Then grade = "适宜"
If l >= 50 Then grade = "湿润"
If l >= 90 Then grade = "过湿"
Text2.Text = grade
End Select
MSComm1.InBufferCount = 0 '清除接收缓冲区
MSComm1.OutBufferCount = 0 '清除发送缓冲区
End Sub
'Private Sub Search_Click()
'Form2.Show
'End Sub
Private Sub Start_Click()
If MSComm1.CommPort <> 2 Then MSComm1.CommPort = 2 '选用COM2口通讯
MSComm1.Settings = "9600,E,8,1 " '设置通讯参数
MSComm1.InputLen = 0 '读取缓冲区全部内容
MSComm1.InBufferSize = 50 '设置接收缓冲区大小
MSComm1.OutBufferSize = 50 '设置发送缓冲区大小
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0 '清除接收缓冲区
MSComm1.OutBufferCount = 0 '清除发送缓冲区
MSComm1.RThreshold = 1 '设置接收到一个字节就触发MsComm1.OnCom()事
End Sub
Private Sub Text1_Change()
Dim strn, strm, strl As String
Dim sdata As String
Dim j As Integer
Dim s, r As Single
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Persist Security Info=False;Data Source=" & App.Path & "\mymdb.mdb"
Set rs = New ADODB.Recordset
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
rs.Open "select * from 历史", cn
'If rs.RecordCount >= 30 Then
'rs.MoveFirst
'rs.Delete
'End If
'rs.MoveFirst
'For i = 1 To rs.RecordCount
'strn = rs.Fields("序号")
'j = Val(strn)
'j = j - 1
'strm = Str(j)
'rs.Fields("序号") = strm
'rs.Update
'rs.MoveNext
'If rs.EOF = True Then rs.MoveFirst
'Next
'rs.AddNew
'rs.Fields("序号") = "30"
'rs.Fields("日期") = StatusBar1.Panels(2) & " " & StatusBar1.Panels(3)
'rs.Fields("湿度") = Text1.Text
'rs.Fields("等级") = Text2.Text
'rs.Update
'rs.MoveFirst
's = 0
'For i = 1 To rs.RecordCount
'strl = rs.Fields("湿度")
's = s + Val(strl)
'rs.MoveNext
'If rs.EOF = True Then rs.MoveFirst
'Next
'r = s / 30
'Text3.Text = Str(r)
'If r < 10 Then Text4.Text = "过干"
'If 10 <= r < 20 Then Text4.Text = "干燥"
'If 20 <= r < 50 Then Text4.Text = "适宜"
'If 50 <= r < 90 Then Text4.Text = "湿润"
'If r >= 90 Then Text4.Text = "过湿"
rs.Close
cn.Close
'If Combo2.Text = "5s/次" Then
'sdata = "1"
'End If
'If Combo2.Text = "10s/次" Then
'sdata = "2"
'End If
'If Combo2.Text = "0.5m/次" Then
'sdata = "3"
'End If
'If Combo2.Text = "1m/次" Then
'sdata = "4"
'End If
'If Combo2.Text = "5m/次" Then
' sdata = "5"
'End If
'If MSComm1.PortOpen = False Then
' MSComm1.PortOpen = True
'End If
'MSComm1.Output = sdata
'MSComm1.PortOpen = False
End Sub
Private Sub Timer1_Timer()
StatusBar1.Panels(1) = "欢迎使用简易湿度计!"
StatusBar1.Panels(2) = Date
StatusBar1.Panels(3) = Time
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -