请教版主,怎样分类求平均?
原文件1988 4
1988 3
1988 24
1988 4
1987 3
1987 9
1987 53
1984 9
1984 19
1984 39
.
.
.
代码
Private Sub Command4_Click()
Dim s As String
Dim flag As Integer
Sum = 0: flag = 0
myfile1 = App.Path & "\" & "2.txt"
myfile2 = App.Path & "\" & "4.txt"
Open myfile1 For Input As #1
Open myfile2 For Output As #2
Do While Not EOF(1)
Line Input #1, s
Dim arr
While InStr(s, " ")
s = Replace(s, " ", " ")
Wend
arr = Split(s, " ")
Sum = Sum + Val(arr(1))
if arr(0)<>!!then
Print #2, arr(0); Spc(2); Round(Sum / flag, 1)
Sum = 0:flag = 0
End If
flag = flag + 1
!! = arr(0)
Loop
Close #2
Close #1
End Sub
请教如何修改代码才能正确运算
[ 本帖最后由 菜鸟新上路 于 2010-3-25 20:13 编辑 ]