又看了很久,很多看不懂,请ouzhiguang兄再帮下忙,注释一下吧.
可以计算了,但不知道你是提取哪几个数出来计算的
Private Sub Command1_Click()
Dim strfilename As String
Dim strline As String
Dim filenum As String
CommonDialog1.Filter = "所有文件(*.*)|*.*"
CommonDialog1.FilterIndex = 1
CommonDialog1.ShowOpen
strfilename = CommonDialog1.FileName
Text1.Text = ""
filenum = FreeFile
If strfilename <> "" Then
Open strfilename For Input As filenum
Do While Not EOF(filenum)
Line Input #filenum, strline
Text1.Text = Text1.Text + strline + Chr(13) + Chr(10)
Loop
Close filenum
End If
'本过程为读入文件的数据 在text1中显示
End Sub
Private Sub Command2_Click()
Dim a(1000) As String
strfilename = CommonDialog1.FileName
Text1.Text = ""
filenum = FreeFile '下一个文件?
If strfilename <> "" Then '如果文件名不为空就写入filenum
Open strfilename For Input As filenum '打开文件 (这是可以读多个文件的吗?)
Do While Not EOF(filenum)
Line Input #filenum, strline
n = LTrim(strline)
'以上为把读入的文件数据连成一串,存给n?
s1: '行号
For i = 1 To Len(n)
If Mid(n, i, 1) = " " Then '循环一次,如果这次的字符是空格,k就加1
k = k + 1
a(k) = Mid(n, 1, i - 1) 'a(k)就等于空格前的字符串,(这样是不是每个数值存给各个a(k)了)
n = LTrim(Mid(n, i))
GoTo s1
End If
Next i ''以上看不懂,请帮注释一下
For j = 1 To Len(RTrim(strline))
If Mid(RTrim(strline), Len(RTrim(strline)) - j, 1) = " " Then
k = k + 1
a(k) = Mid(RTrim(strline), Len(RTrim(strline)) - j + 1, Len(RTrim(strline)))
Exit For
End If
Next j
Text1.Text = Text1.Text + strline + Chr(13) + Chr(10)
Loop
Close filenum
End If
For i = 1 To k
Text2.Text = Text2.Text & " " & Trim(a(i))
If i Mod 6 = 0 Then
Text2.Text = Text2.Text & Chr(13) & Chr(10)
End If
Next i
'以下为预防忘记输入要比较的值
If Text3.Text = "" Then ''如果text3=""
MsgBox "请输入要比较的值!" '提示输入
Text3.SetFocus '将焦点移动到text3
Exit Sub
End If
Dim o, v As Single
Dim m As Single
m = Val(Text3.Text) 'k,m都等于比较值
k = Val(Text3.Text)
For i = 1 To k - 5 Step 6
If Val(a(i)) > m Then ' 如果每行的第一个数大于比较值就停止
Exit For
End If
Next i
If i = 1 Then Exit Sub
v = (Val(a(i + 1)) - Val(a(i - 6 + 1))) / (Val(a(i + 3)) - Val(a(i - 6 + 3)))
o = (Val(a(i - 1)) - Val(a(i + 5))) * m
Text4.Text = Str(v) & Str(o)
End Sub