不好意思,老是粘贴错,再改一下,源代码我调试好了以后给你粘贴错了,这段代码我没有调试,不过应该可以的,你试试,不可以的话给我追问,我调试
你在vb的安装路径下新建一个text1.txt,用来输入学生成绩和姓名,一个text2.txt,用来保存结果。注意text1.txt格式是这样的,
张3,10
李四,30
王二,40
private sub cmd_click()
dim scount as integer'用来存储学生的个数
scount=inputbox("请输入学生的个数")
dim a() as integer'用来存储文件里的所有数据
redim a(1 to 2*scount)
open app.path&"\"&"text1.txt" for input as#1
for i=1 to 2*scount
input#1,a(i)
next i
close#1
dim b() as integer'用来存储学生成绩
redim b(1 to scount)
dim c() as integer'用来存储学生姓名
redim c(1 to scount)
for i=1 to scount'读入学生成绩
b(i)=a(2*I)
next i
for i=1 to scount'读入学生姓名
c(i)=a(1+2*(i-1))
next i
for i=1 to scount-1'给成绩排序
max=b(i)
for j=i+1 to scount
if b(j)>max then
max=b(j)
p=j
temp=b(i)
b(i)=b(p)
b(p)=temp
end if
next j
next i
for i=1 to scount
for j=1 to scount
if b(i)=a(2*j) then
c(i)=a(2*j)
end if
next j
next i
open app.path&"\"&"text2.text" for append as#1
for i=1 to scount
print#1,c(i),b(i)
next i
close#1
end sub
追问不行啊,有3行代码是红色的啊
追答Private Sub cmd_click()
Dim scount As Integer '用来存储学生的个数
scount = InputBox("请输入学生的个数")
Dim a() As String '用来存储文件里的所有数据
ReDim a(1 To 2 * scount)
Open App.Path & "\" & "text1.txt" For Input As 1
For I = 1 To 2 * scount
Input #1, a(I)
Next I
Close #1
Dim b() As Integer '用来存储学生成绩
ReDim b(1 To scount)
Dim c() As String '用来存储学生姓名
ReDim c(1 To scount)
For I = 1 To scount '读入学生成绩
b(I) = Val(a(2 * I))
Next I
For I = 1 To scount '读入学生姓名
c(I) = a(1 + 2 * (I - 1))
Next I
For I = 1 To scount - 1 '给成绩排序
Max = b(I)
For j = I + 1 To scount
If b(j) > Max Then
Max = b(j)
p = j
temp = b(I)
b(I) = b(p)
b(p) = temp
End If
Next j
Next I
For I = 1 To scount
For j = 1 To scount
If b(I) = a(2 * j) Then
c(I) = a(2 * j - 1)
End If
Next j
Next I
Open App.Path & "\" & "txt2.text" For Output As 1
For I = 1 To scount
Print #1, c(I), b(I)
Next I
Close #1
RE = 0
For I = 1 To scount
If b(I) > 60 Or b(I) = 60 Then
RE = RE + 1
End If
Next I
Text1.Text = RE
Text2.Text = scount - RE
End Sub
这下绝对行啦,我给你运行过了
这......不行啊
追答已发送至邮箱[email protected],密码是198731111.你自己下载吧,呵呵
程序界面就像表格一样,还要成绩全班平均分
追答要求不明,无法编程
是,还要成绩全班平均分