VB编写一个随机文件程序

1.建立一个具有5个学生的学号,姓名和成绩的随机文件(RANDOM.DAT)2.读出RANDOM.DAT文件中的内容,然后按成绩排序,最后按顺序写入另一个随机文件(RAN... 1.建立一个具有5个学生的学号,姓名和成绩的随机文件(RANDOM.DAT)
2.读出RANDOM.DAT文件中的内容,然后按成绩排序,最后按顺序写入另一个随机文件(RANDOM1.DAT)
3.再次读出文件的内容,按文件中的顺序将学生的信息显示在屏幕上,检查正确性
展开
 我来答
VB编程解放双手
2018-03-19 · 个人VB爱好者专注vb编程_时效软件
VB编程解放双手
采纳数:1204 获赞数:2391

向TA提问 私信TA
展开全部

Private Type stu

num As String * 10

name As String * 20

cj As Long

End Type

Private Sub Command1_Click()

Dim f As String, f1 As String, stud As stu, studd(5) As stu

'    Print Len(stud)

f = App.Path & "\RANDOM.DAT"

Open f For Random As #1 Len = 35

For j = 1 To 5

stud.num = Format(Now(), "yyyymmdd") & Format(j, "00")

stud.name = "学生" & j

stud.cj = 90 + j

Put #1, j, stud

Next

Close #1

Print "原始数据:"

Open f For Random As #1 Len = 35

For j = 1 To 5

Get #1, j, studd(j)

Print studd(j).num; studd(j).name; studd(j).cj

Next

Close #1

For j = 1 To 5

For k = j + 1 To 5

If studd(j).cj <= studd(k).cj Then

stud = studd(j)

studd(j) = studd(k)

studd(k) = stud

End If

Next

Next

f = App.Path & "\RANDOM1.DAT"

Open f For Random As #1 Len = 35

For j = 1 To 5

Put #1, j, studd(j)

Next

Close #1

Print "排序后数据:"

Open f For Random As #1 Len = 35

For j = 1 To 5

Get #1, j, studd(j)

Print studd(j).num; studd(j).name; studd(j).cj

Next

Close #1

End Sub

匿名用户
推荐于2018-03-19
展开全部
Private Sub Command1_Click()

If Trim(Text1.Text) = "" Or Trim(Text2.Text) = "" Or Trim(Text3.Text) = "" Then
MsgBox "学生信息不能为空!"
Exit Sub
End If

Open App.Path & "\Random.dat" For Append As #1
Write #1, Text1.Text, Text2.Text, CSng(Text3.Text)
Close #1
i = 0
paixu
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End Sub

Private Sub paixu()
Dim a() As String
Dim n() As String
Dim t As Integer
Dim k As Integer
Dim u As String
i = 0
List1.Clear
Open App.Path & "\Random.dat" For Input As #1
Do While Not EOF(1)
Line Input #1, textline
i = i + 1
Loop
Close #1
If i = 0 Then
Exit Sub
End If
ReDim a(i - 1)
i = 0
Open App.Path & "\Random.dat" For Input As #1
Do While Not EOF(1)
Line Input #1, textline
a(i) = textline
i = i + 1
Loop
Close #1
For i = 0 To UBound(a) - 1
For j = i + 1 To UBound(a)
n = Split(a(i), ",")
t = n(2)
n = Split(a(j), ",")
k = n(2)
If t > k Then
u = a(i)
a(i) = a(j)
a(j) = u
End If
Next
Next
Open App.Path & "\Random1.dat" For Output As #1
For i = 0 To UBound(a)
List1.AddItem a(i)
Print #1, a(i)
Next
Close #1
End Sub

Private Sub Form_Load()
paixu
End Sub
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
xtuiop4
2018-03-15 · TA获得超过219个赞
知道答主
回答量:152
采纳率:0%
帮助的人:53.5万
展开全部
这 是练习题还是作业?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
微标防伪防窜货标签定制

2018-02-01 · TA获得超过2016个赞
知道大有可为答主
回答量:1512
采纳率:87%
帮助的人:552万
展开全部
交卷了吧?挂科了吧?重修了吧?认真学吧!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式