Option Explicit
Private Type 数据类型
名称 As String
范围1 As Long
范围2 As Long
最大值(1 To 3) As Double
最小值(1 To 3) As Double
End Type
Dim dd() As 数据类型
Dim 总数 As Long
Const 文件1 = "1.txt"
'原始数据
Const 文件2 = "2.txt"
'分组规则
Const 文件3 = "结果.txt"
'结果文件
Private Sub Command1_Click()
Dim fr As Long
fr = FreeFile
Dim i As Long, o As Long
Dim j As String
Dim fj() As String
'分组计数
总数 = 0
Open 文件2 For Input As fr
Do While Not EOF(fr)
Line Input #fr, j
总数 = 总数 + 1
Loop
Close fr
ReDim dd(1 To 总数)
'取分组内容
Open 文件2 For Input As fr
i = 0
Do While Not EOF(fr)
Line Input #fr, j
i = i + 1
fj() = Split(j, ",")
dd(i).名称 = fj(0)
dd(i).范围1 = fj(1)
dd(i).范围2 = fj(2)
Loop
Close fr
'初始化最大值,最小值
For i = 1 To 总数
For o = 1 To 3
dd(i).最大值(o) = -99999
dd(i).最小值(o) = 99999
Next o
Next i
'打开数据,查找最大值\最小值
Open 文件1 For Input As fr
Do While Not EOF(fr)
Line Input #fr, j
fj() = Split(j, ",")
For i = 1 To 总数
If fj(0) > dd(i).范围1 And fj(0) < dd(i).范围2 Then
For o = 1 To 3
If fj(o) > dd(i).最大值(o) Then
dd(i).最大值(o) = fj(o)
End If
If fj(o) < dd(i).最小值(o) Then
dd(i).最小值(o) = fj(o)
End If
Next o
Exit For
End If
Next i
Loop
Close fr
'保存结果
Open 文件3 For Output As fr
For i = 1 To 总数
Print #fr, dd(i).名称; ","; dtos(dd(i).最大值(1)); ","; dtos(dd(i).最大值(2)); ","; dtos(dd(i).最大值(3)); ", ,";
Print #fr, dtos(dd(i).最小值(1)); ","; dtos(dd(i).最小值(2)); ","; dtos(dd(i).最小值(3))
Next i
Close fr
'显示结果
Open 文件3 For Input As fr
Do While Not EOF(fr)
Line Input #fr, j
Text1.Text = Text1.Text & j & vbCrLf
Loop
Close fr
MsgBox "整理完成"
End Sub
Private Function dtos(cs As Double) As String
'补小数前导零
dtos = Format(cs, "#0.#########")
End Function
--------------------------------------------
结果是:
nv01,0.192,0.256,0.303, ,-0.165,-0.139,0.023
nv02,0.164,0.139,0.217, ,-0.199,-0.152,0.023
nv03,0.074,0.152,0.155, ,-0.1,-0.101,0.028
nv04,0.138,-0.021,0.157, ,0.064,-0.074,0.067
nv05,0.161,0.149,0.161, ,-0.156,-0.117,0.06
--------------------------------------------
工程不传了,如果连工程都传的话,那真是专门求答案的人了.
这全部的代码都给了,工程自己建吧.也就是2个控件的问题
代码尽量少给注释,自己看吧.代码是分块的
所用到的知识比较深.相对BASIC 的语言来说,并不是相对WINDOWS 来说.