帮帮忙啊:如何在vb中打开一个文件,并使它在文本框中输出 10
比如说一下这个题怎么做啊?完成简单“学生信息管理系统”的设计,要求如下:1.“排序”、“查询”菜单初始设置为不可用,窗体界面中的文本框不可见2.当用户选择“打开”菜单时,...
比如说一下这个题怎么做啊?
完成简单“学生信息管理系统”的设计,要求如下:
1. “排序”、“查询”菜单初始设置为不可用,窗体界面中的文本框不可见
2. 当用户选择“打开”菜单时,窗体界面中的文本框可见,打开本程序附带的" info.txt"文件,读出该文件所有信息,并显示在文本框中。
3. 单击“录入成绩”时,为每个同学的四门课成绩赋值(通过随机函数设置),并计算每个同学三门课成绩的总分,将同学成绩及总成绩写入对应位置。同时设置“排序”和“查询”菜单为可用
4. 当单击“排序”时完成文件中学生信息按总成绩排序,并将排序后的同学信息追加保存在" info.txt"文件中
5. 若选择“查询”,用户输入要查询同学的姓名,若查找成功,在窗体标签中显示该同学的所有信息,否则给出查找失败信息。
6. 当选择“退出”菜单时,程序退出运行
这个程序代码怎么编啊,请教高手帮忙。 展开
完成简单“学生信息管理系统”的设计,要求如下:
1. “排序”、“查询”菜单初始设置为不可用,窗体界面中的文本框不可见
2. 当用户选择“打开”菜单时,窗体界面中的文本框可见,打开本程序附带的" info.txt"文件,读出该文件所有信息,并显示在文本框中。
3. 单击“录入成绩”时,为每个同学的四门课成绩赋值(通过随机函数设置),并计算每个同学三门课成绩的总分,将同学成绩及总成绩写入对应位置。同时设置“排序”和“查询”菜单为可用
4. 当单击“排序”时完成文件中学生信息按总成绩排序,并将排序后的同学信息追加保存在" info.txt"文件中
5. 若选择“查询”,用户输入要查询同学的姓名,若查找成功,在窗体标签中显示该同学的所有信息,否则给出查找失败信息。
6. 当选择“退出”菜单时,程序退出运行
这个程序代码怎么编啊,请教高手帮忙。 展开
1个回答
展开全部
请在C盘根目录下新建一个info.txt空文件,然后将以下全部内容另存为form1.frm文件,然后用VB打开直接运行吧。
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Form1"
ClientHeight = 5295
ClientLeft = 150
ClientTop = 720
ClientWidth = 6750
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 5295
ScaleWidth = 6750
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 3495
Left = 240
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 1
Top = 240
Width = 6135
End
Begin VB.CommandButton cmdEnterScore
Caption = "录入成绩"
Height = 375
Left = 4800
TabIndex = 0
Top = 4080
Width = 1695
End
Begin VB.Label Label1
Height = 1215
Left = 360
TabIndex = 2
Top = 3840
Width = 3855
End
Begin VB.Menu mnOpen
Caption = "打开"
End
Begin VB.Menu mnSort
Caption = "排序"
End
Begin VB.Menu mnQuery
Caption = "查找"
End
Begin VB.Menu mnExit
Caption = "退出"
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const stunum = 50 '学生总数
Dim score(stunum, 5)
Dim gText As String
Sub Form_Load()
mnSort.Enabled = False
mnQuery.Enabled = False
Text1.Visible = False
End Sub
Private Sub mnExit_Click()
Unload Me
End
End Sub
Sub mnOpen_Click()
Text1.Visible = True
Open "c:\info.txt" For Input As #1
While Not EOF(1)
Line Input #1, a$
gText = gText & vbCrLf & a$
Wend
Close #1
Text1.Text = gText
End Sub
Sub cmdEnterScore_Click()
score(0, 0) = "姓名"
score(0, 1) = "语文"
score(0, 2) = "数学"
score(0, 3) = "美术"
score(0, 4) = "音乐"
score(0, 5) = "总分"
For i = 1 To 50
score(i, 0) = ChrW(Int(Rnd * 20902) + 19968) & ChrW(Int(Rnd * 20902) + 19968) & ChrW(Int(Rnd * 20902) + 19968)
Next i
For i = 1 To stunum
For j = 1 To 4
score(i, j) = Int(Rnd * 100)
Next j
Next i
For i = 1 To stunum
s = 0
For j = 1 To 4
s = s + score(i, j)
Next j
score(i, 5) = s
Next i
gText = ""
For i = 0 To stunum
For j = 0 To 5
gText = gText & score(i, j) & vbTab
Next j
gText = gText & vbCrLf
Next i
Text1.Text = gText
Open "c:\info.txt" For Output As #1
Print #1, gText
Close #1
mnSort.Enabled = True
mnQuery.Enabled = True
End Sub
Private Sub mnQuery_Click()
nm = InputBox("输入姓名")
If nm = "" Then Exit Sub
s = 0
For i = 1 To 50
If score(i, 0) = nm Then
Label1.Caption = ""
For j = 0 To 5
Label1.Caption = Label1.Caption & score(0, j) & " " & score(i, j) & vbLf
Next j
s = 1
Exit For
End If
Next i
If s = 0 Then Label1.Caption = "查找失败"
End Sub
Private Sub mnSort_Click()
For i = 1 To stunum - 1
t = 0
Max = score(i, 5)
For j = i + 1 To stunum
If Max < score(j, 5) Then t = j: Max = score(j, 5)
Next j
If t <> 0 Then
For k = 0 To 5
tmp = score(i, k)
score(i, k) = score(t, k)
score(t, k) = tmp
Next k
End If
Next i
gText = gText & vbCrLf
For i = 0 To stunum
For j = 0 To 5
gText = gText & score(i, j) & vbTab
Next j
gText = gText & vbCrLf
Next i
Text1.Text = gText
Open "c:\info.txt" For Output As #1
Print #1, gText
Close #1
End Sub
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Form1"
ClientHeight = 5295
ClientLeft = 150
ClientTop = 720
ClientWidth = 6750
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 5295
ScaleWidth = 6750
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 3495
Left = 240
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 1
Top = 240
Width = 6135
End
Begin VB.CommandButton cmdEnterScore
Caption = "录入成绩"
Height = 375
Left = 4800
TabIndex = 0
Top = 4080
Width = 1695
End
Begin VB.Label Label1
Height = 1215
Left = 360
TabIndex = 2
Top = 3840
Width = 3855
End
Begin VB.Menu mnOpen
Caption = "打开"
End
Begin VB.Menu mnSort
Caption = "排序"
End
Begin VB.Menu mnQuery
Caption = "查找"
End
Begin VB.Menu mnExit
Caption = "退出"
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const stunum = 50 '学生总数
Dim score(stunum, 5)
Dim gText As String
Sub Form_Load()
mnSort.Enabled = False
mnQuery.Enabled = False
Text1.Visible = False
End Sub
Private Sub mnExit_Click()
Unload Me
End
End Sub
Sub mnOpen_Click()
Text1.Visible = True
Open "c:\info.txt" For Input As #1
While Not EOF(1)
Line Input #1, a$
gText = gText & vbCrLf & a$
Wend
Close #1
Text1.Text = gText
End Sub
Sub cmdEnterScore_Click()
score(0, 0) = "姓名"
score(0, 1) = "语文"
score(0, 2) = "数学"
score(0, 3) = "美术"
score(0, 4) = "音乐"
score(0, 5) = "总分"
For i = 1 To 50
score(i, 0) = ChrW(Int(Rnd * 20902) + 19968) & ChrW(Int(Rnd * 20902) + 19968) & ChrW(Int(Rnd * 20902) + 19968)
Next i
For i = 1 To stunum
For j = 1 To 4
score(i, j) = Int(Rnd * 100)
Next j
Next i
For i = 1 To stunum
s = 0
For j = 1 To 4
s = s + score(i, j)
Next j
score(i, 5) = s
Next i
gText = ""
For i = 0 To stunum
For j = 0 To 5
gText = gText & score(i, j) & vbTab
Next j
gText = gText & vbCrLf
Next i
Text1.Text = gText
Open "c:\info.txt" For Output As #1
Print #1, gText
Close #1
mnSort.Enabled = True
mnQuery.Enabled = True
End Sub
Private Sub mnQuery_Click()
nm = InputBox("输入姓名")
If nm = "" Then Exit Sub
s = 0
For i = 1 To 50
If score(i, 0) = nm Then
Label1.Caption = ""
For j = 0 To 5
Label1.Caption = Label1.Caption & score(0, j) & " " & score(i, j) & vbLf
Next j
s = 1
Exit For
End If
Next i
If s = 0 Then Label1.Caption = "查找失败"
End Sub
Private Sub mnSort_Click()
For i = 1 To stunum - 1
t = 0
Max = score(i, 5)
For j = i + 1 To stunum
If Max < score(j, 5) Then t = j: Max = score(j, 5)
Next j
If t <> 0 Then
For k = 0 To 5
tmp = score(i, k)
score(i, k) = score(t, k)
score(t, k) = tmp
Next k
End If
Next i
gText = gText & vbCrLf
For i = 0 To stunum
For j = 0 To 5
gText = gText & score(i, j) & vbTab
Next j
gText = gText & vbCrLf
Next i
Text1.Text = gText
Open "c:\info.txt" For Output As #1
Print #1, gText
Close #1
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询