请å¨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
温馨提示:答案为网友推荐,仅供参考