📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "数据处理"
ClientHeight = 3225
ClientLeft = 1590
ClientTop = 1335
ClientWidth = 8715
Icon = "Form1.frx":0000
LinkTopic = "Form1"
ScaleHeight = 3225
ScaleWidth = 8715
Begin VB.CommandButton Command2
Caption = "退出"
Height = 375
Left = 7200
TabIndex = 17
Top = 2640
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "计算"
Height = 375
Left = 5760
TabIndex = 16
Top = 2640
Width = 1215
End
Begin VB.Frame Frame1
Caption = "仪器误差分布类型:"
Height = 1095
Left = 120
TabIndex = 10
Top = 600
Width = 5175
Begin VB.OptionButton Option3
Caption = "其它"
Height = 255
Left = 120
TabIndex = 13
Top = 720
Width = 975
End
Begin VB.OptionButton Option2
Caption = "游标卡尺,秒表,电表,电阻箱 [均匀分布C=1.46]"
Height = 255
Left = 120
TabIndex = 12
Top = 480
Width = 4815
End
Begin VB.OptionButton Option1
Caption = "千分尺,米尺,物理天平,温度计 [正态分布C=3] "
Height = 195
Left = 120
TabIndex = 11
Top = 240
Width = 4515
End
End
Begin VB.TextBox Text3
Height = 285
Left = 1200
TabIndex = 9
Top = 120
Width = 1335
End
Begin VB.TextBox Text2
Height = 765
Left = 1200
MultiLine = -1 'True
TabIndex = 4
Top = 2280
Width = 3735
End
Begin VB.TextBox Text1
Height = 285
Left = 1200
TabIndex = 3
Top = 1800
Width = 975
End
Begin VB.Label Label9
AutoSize = -1 'True
Caption = "结果表示:"
Height = 195
Left = 5760
TabIndex = 15
Top = 2040
Width = 900
End
Begin VB.Label Label8
AutoSize = -1 'True
Caption = "不确定度U :"
Height = 195
Left = 5760
TabIndex = 14
Top = 1560
Width = 1065
End
Begin VB.Label Label7
Caption = "仪器误差限:"
Height = 255
Left = 120
TabIndex = 0
Top = 120
Width = 1095
End
Begin VB.Label Label6
AutoSize = -1 'True
Caption = "B类不确定度:"
Height = 195
Left = 5760
TabIndex = 8
Top = 1200
Width = 1185
End
Begin VB.Label Label5
AutoSize = -1 'True
Caption = "A类不确定度:"
Height = 195
Left = 5760
TabIndex = 7
Top = 840
Width = 1185
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "标准差:"
Height = 195
Left = 5760
TabIndex = 6
Top = 480
Width = 720
End
Begin VB.Line Line1
X1 = 5520
X2 = 5520
Y1 = 0
Y2 = 6360
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "最佳值:"
Height = 195
Left = 5760
TabIndex = 5
Top = 120
Width = 720
End
Begin VB.Label Label2
Caption = "输入数据 以空格隔 开:"
Height = 735
Left = 120
TabIndex = 2
Top = 2280
Width = 855
End
Begin VB.Label Label1
Caption = "数据个数:"
Height = 255
Left = 120
TabIndex = 1
Top = 1800
Width = 1215
End
Begin VB.Menu menu
Caption = "菜单(&M)"
Begin VB.Menu js
Caption = "计算"
End
Begin VB.Menu huifu
Caption = "恢复上次数据"
End
Begin VB.Menu clear
Caption = "双击清空数据"
End
Begin VB.Menu exit
Caption = "退出"
End
End
Begin VB.Menu help
Caption = "帮助(&h)"
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim N As Integer
Dim best As Double
Dim sx As Double
Dim Ua As Double
Dim Ub As Double
Dim U As Double
Dim t As Double
Dim a() As String
Dim b() As Double
Dim T1_old As String * 20
Dim T2_old As String * 1024
Dim T3_old As String * 20
Dim l3_old As String * 20
Dim N_old As Integer
Dim b_old() As Double
Dim table
Private Sub Command1_Click()
On Error GoTo 0
Call js_click
End Sub
Private Sub Command2_Click()
On Error GoTo 0
Call exit_Click
End Sub
Private Sub exit_Click()
On Error GoTo 0
If (MsgBox("请注意记录结果数据" & vbCrLf & "确认退出?", vbYesNo, "退出程序")) = vbYes Then
End
Else
Exit Sub
End If
End Sub
Private Sub Form_Load()
On Error GoTo 0
Command2.TabIndex = 0
Text1.TabIndex = 1
Text2.TabIndex = 2
N = 0
N_old = 0
best = 0
sx = 0
Ua = 0
Ub = 0
table = Array(0#, 0#, 1.32, 1.2, 1.14, 1.11, 1.09, 1.08, 1.07, 1.06, 1.04, 1.03, 1#)
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error GoTo 0
If (MsgBox("请注意记录结果数据" & vbCrLf & "确认退出?", vbYesNo, "退出程序")) = vbYes Then
End
Else
Cancel = True
End If
End Sub
Private Sub help_Click()
On Error GoTo 0
MsgBox "按提示输入数据,点击计算进行计算,计算中需要人工进行辅助,结果的小数位请自行修正(如 2±0.2 ,需要修正为 2.0±0.2)", vbInformation, "提示"
End Sub
Private Sub js_click()
On Error GoTo endd
Dim i As Integer
Dim sum As Double
Dim tmp As Double
sum = 0
Call Text1_LostFocus
Call Text2_LostFocus
sum = 0
For i = 0 To N - 1
tmp = b(i) - best
tmp = tmp * tmp
sum = sum + tmp
Next i
sum = sum / (N - 1)
sx = sum ^ (1 / 2)
Ua = sum / N
Ua = Ua ^ (1 / 2)
Ua = Ua * t
Ua = InputBox("保留两位有效数字" & vbCrLf & "Ua=" & Ua, "数据修正 Ua", Ua)
U = Ua * Ua
U = U + Ub * Ub
U = U ^ (1 / 2)
U = InputBox("保留一位有效数字" & vbCrLf & "U=" & U, "数据修正 U", U)
Label4.Caption = "标准差:" & sx
Label5.Caption = "A类不确定度:" & Ua
Label6.Caption = "B类不确定度:" & Ub
Label8.Caption = "不确定度U :" & U
Label9.Caption = "结果表示:" & best & " ± " & U
endd:
Exit Sub
End Sub
Private Sub clear_Click()
On Error GoTo 0
If (N > 0) Then
ReDim b_old(0 To N - 1) As Double
b_old = b
N_old = N
T1_old = Text1.Text
T2_old = Text2.Text
T3_old = Text3.Text
l3_old = Label3.Caption
Me.Caption = "数据处理"
Text1.Text = ""
Text2.Text = ""
Label3.Caption = ""
Else
MsgBox "没有输入数据"
End If
End Sub
Private Sub Form_DblClick()
On Error GoTo 0
If (N > 0) Then
ReDim b_old(0 To N - 1) As Double
b_old = b
N_old = N
T1_old = Text1.Text
T2_old = Text2.Text
T3_old = Text3.Text
l3_old = Label3.Caption
Me.Caption = "数据处理"
Text1.Text = ""
Text2.Text = ""
Label3.Caption = ""
Else
MsgBox "没有输入数据", vbOKOnly, "保存数据"
End If
End Sub
Private Sub huifu_Click()
On Error GoTo 0
If N_old > 0 Then
N = N_old
ReDim b(0 To N - 1) As Double
b = b_old
Form1.Caption = "数据处理" & " N=" & N
Text1.Text = T1_old
Text2.Text = T2_old
Text3.Text = T3_old
Label3.Caption = l3_old
Else
MsgBox "没有数据可供恢复", vbOKOnly, "数据恢复"
End If
End Sub
Private Sub Option1_Click()
On Error GoTo 0
Ub = Val(Text3.Text) / 3
Ub = InputBox("保留两位有效数字" & vbCrLf & "Ub=" & Ub, "数据修正 Ub", Ub)
'MsgBox Ub
End Sub
Private Sub Option2_Click()
Ub = Val(Text3.Text) / 1.46
Ub = InputBox("保留两位有效数字" & vbCrLf & "Ub=" & Ub, "数据修正 Ub", Ub)
'MsgBox Ub
End Sub
Private Sub Text1_LostFocus()
On Error GoTo 0
If Not IsNumeric(Text1.Text) Then
If (MsgBox("输入的不是数字!", vbRetryCancel, Label1.Caption) = vbRetry) Then Text1.SetFocus
Else
N = Val(Text1.Text)
If N >= 3 Then
If N <= 10 Then
t = table(N - 1)
ElseIf N = 15 Then t = table(10)
ElseIf N = 20 Then t = table(11)
ElseIf N > 20 Then t = table(12)
Else
MsgBox "表中无对应t"
End
End If
Form1.Caption = "数据处理" & " N=" & N
'MsgBox t
ReDim a(0 To N - 1) As String
ReDim b(0 To N - 1) As Double
Else
If (MsgBox("输入个数不正确!", vbRetryCancel, Label1.Caption) = vbRetry) Then Text1.SetFocus
End If
End If
End Sub
Private Sub Text2_LostFocus()
On Error GoTo 0
Dim i As Integer
Dim sum As Double
sum = 0
If (UBound(Split(Trim(Text2.Text))) = N - 1) And N >= 1 Then
a = Split(Trim(Text2.Text))
For i = 0 To N - 1
b(i) = Val(a(i))
'Print b(i)
sum = sum + b(i)
Next i
best = sum / N
Label3.Caption = "最佳值:" & best
Else
If N >= 1 Then
If (MsgBox("输入数据个数不正确,请检查!", vbRetryCancel, Label2.Caption) = vbRetry) Then
Text2.SetFocus
End If
Else
Text1.SetFocus
End If
End If
End Sub
Private Sub Text3_LostFocus()
On Error GoTo 0
If Not IsNumeric(Text3.Text) Then
If (MsgBox("输入的不是数字!", vbRetryCancel, Label7.Caption) = vbRetry) Then Text3.SetFocus
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -