📄 滑动平均f2.frm
字号:
VERSION 5.00
Begin VB.Form frmCalculate
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "滑动平均"
ClientHeight = 1335
ClientLeft = 165
ClientTop = 555
ClientWidth = 4455
LinkTopic = "Form1"
ScaleHeight = 2.355
ScaleMode = 7 'Centimeter
ScaleWidth = 7.858
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox txtData
Alignment = 2 'Center
Appearance = 0 'Flat
Height = 270
Index = 0
Left = 120
TabIndex = 7
Text = "txtData"
Top = 1080
Visible = 0 'False
Width = 855
End
Begin VB.CommandButton cmdSaveE
Caption = "保存残差"
Height = 375
Left = 2280
TabIndex = 6
Top = 720
Width = 975
End
Begin VB.OptionButton opt3_5
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "三次五点"
ForeColor = &H80000008&
Height = 375
Left = 3240
TabIndex = 5
Top = 240
Width = 1095
End
Begin VB.OptionButton opt1_5
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "一次五点"
ForeColor = &H80000008&
Height = 375
Left = 1680
TabIndex = 4
Top = 240
Value = -1 'True
Width = 1095
End
Begin VB.OptionButton opt1_3
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "一次三点"
ForeColor = &H80000008&
Height = 375
Left = 120
TabIndex = 3
Top = 240
Width = 1095
End
Begin VB.CommandButton cmdExit
Caption = "退 出"
Height = 375
Left = 3360
TabIndex = 2
Top = 720
Width = 975
End
Begin VB.CommandButton cmdSaveR
Caption = "保存结果"
Height = 375
Left = 1200
TabIndex = 1
Top = 720
Width = 975
End
Begin VB.CommandButton cmdCalculate
Caption = "计 算"
Height = 375
Left = 120
TabIndex = 0
Top = 720
Width = 975
End
Begin VB.Label lblCol
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
Caption = "lblCol"
ForeColor = &H80000008&
Height = 255
Index = 0
Left = 2280
TabIndex = 9
Top = 1080
Visible = 0 'False
Width = 975
End
Begin VB.Label lblRow
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 1 'Fixed Single
Caption = "lblRow"
ForeColor = &H80000008&
Height = 255
Index = 0
Left = 1200
TabIndex = 8
Top = 1080
Visible = 0 'False
Width = 975
End
End
Attribute VB_Name = "frmCalculate"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'滑动平均的计算窗体
Dim intI As Integer, intJ As Integer
'保存文件过程
Private Sub FileSave(strName As String)
Dim intNumber As Integer
Dim vntA As Variant
MsgBox "现在存盘,请耐心等待!"
intNumber = FreeFile '取得空闲的文件号
Open strName For Output As intNumber '打开文件
'保存数据
For intI = 1 To intRowAll
For intJ = 1 To intCol
Write #intNumber, txtData((intI - 1) * intCol + intJ);
Next intJ
Next intI
'保存上部标签
For intI = 1 To intCol
Write #intNumber, lblCol(intI).Caption;
Next intI
'保存左边标签
For intI = 1 To intRowAll
Write #intNumber, lblRow(intI).Caption;
Next intI
Close '关闭文件
MsgBox "存盘完成,请继续进行!"
End Sub
Private Sub Form_Load()
cmdSaveR.Visible = False '“保存数据”命令按钮不可视
cmdSaveE.Visible = False '“保存残差”命令按钮不可视
Dim vntA As Variant
intFileNumber = FreeFile '取得文件号码
Open strFileName For Input As intFileNumber '打开文件
'形成文本框数组
For intI = 1 To intRowAll
For intJ = 1 To intCol
Input #intFileNumber, vntA
Load txtData((intI - 1) * intCol + intJ)
txtData((intI - 1) * intCol + intJ).Text = vntA
Next intJ
Next intI
'形成上部标签
For intI = 1 To intCol
Input #intFileNumber, vntA
Load lblCol(intI)
lblCol(intI).Caption = vntA
Next intI
'形成左边标签
For intI = 1 To intRowAll
Input #intFileNumber, vntA
Load lblRow(intI)
lblRow(intI).Caption = vntA
Next intI
Close
End Sub
'调用滑动平均过程计算
Private Sub cmdCalculate_Click()
If opt1_3 Then Smooth_1_3 P, R, E '一次三点
If opt1_5 Then Smooth_1_5 P, R, E '一次五点
If opt3_5 Then Smooth_3_5 P, R, E '三次五点
cmdSaveR.Visible = True '“保存结果”命令按钮可视
cmdSaveE.Visible = True '“保存残差”命令按钮可视
End Sub
'将平滑结果保存为数据文件
Private Sub cmdSaveR_Click()
Dim sngR As Single
For intI = intRowAll - intRow + 1 To intRowAll
For intJ = 1 To intCol
sngR = R(intI - intRowAll + intRow, intJ)
txtData((intI - 1) * intCol + intJ) = sngR
Next intJ
Next intI
FileSave (strSmo_Name)
End Sub
'将平滑残差保存为数据文件
Private Sub cmdSaveE_Click()
Dim sngE As Single
For intI = intRowAll - intRow + 1 To intRowAll
For intJ = 1 To intCol
sngE = E(intI - intRowAll + intRow, intJ)
txtData((intI - 1) * intCol + intJ) = sngE
Next intJ
Next intI
FileSave (strErr_Name)
End Sub
'退出
Private Sub cmdExit_Click()
Unload Me
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -