VB读文件将其读入数组中
将fs.txt文件中的5个学生成绩顺序读入数组A,并在文本框text1中显示出来?单击"满分人数"按钮,在text1中显示数组成绩单100出现的次数?fs.txt文件中存...
将fs.txt文件中的5个学生成绩顺序读入数组A,并在文本框text1中显示出来?单击"满分人数"按钮,在text1中显示数组成绩单100出现的次数? fs.txt文件中存着 98 100 89 100 100
一楼:文件格式是txt,成绩间是空格..没其它的要求了. 展开
一楼:文件格式是txt,成绩间是空格..没其它的要求了. 展开
4个回答
展开全部
Dim 成绩(5) As Single
Private Sub Command1_Click()
Open "fs.txt" For Input As #1
Text1 = ""
For i = 1 To 5
Input #1, 成绩(i)
Text1 = Text1 & 成绩(i) & ","
Next i
Close #1
End Sub
Private Sub Command2_Click()
Dim 满分人数 As Integer
For i = 1 To 5
If 成绩(i) = 100 Then 满分人数 = 满分人数 + 1
Next i
Text1 = 满分人数
End Sub
Private Sub Form_Load()
Command1.Caption = "读入成绩"
Command2.Caption = "满分人数"
End Sub
Private Sub Command1_Click()
Open "fs.txt" For Input As #1
Text1 = ""
For i = 1 To 5
Input #1, 成绩(i)
Text1 = Text1 & 成绩(i) & ","
Next i
Close #1
End Sub
Private Sub Command2_Click()
Dim 满分人数 As Integer
For i = 1 To 5
If 成绩(i) = 100 Then 满分人数 = 满分人数 + 1
Next i
Text1 = 满分人数
End Sub
Private Sub Form_Load()
Command1.Caption = "读入成绩"
Command2.Caption = "满分人数"
End Sub
展开全部
100%你的要求
一个文本一个按钮,,fs.txt放到C盘,,一运行程序,,
文本将从大到小显示分数,,,按下按钮,将显示满分人数
Dim b As Integer
Private Sub Command1_Click()
Text1.Text = Text1.Text & "满分人数" & b
End Sub
Private Sub Form_Load()
Dim c As Double
Dim a() As String
Dim t1 As String
Text1.Text = ""
Open "c:\fs.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, t1
Loop
a = Split(t1, " ")
For i = 0 To UBound(a)
For j = i + 1 To UBound(a)
If Val(a(j)) > Val(a(i)) Then
c = a(i)
a(i) = a(j)
a(j) = c
End If
Next j
If Val(a(i)) = 100 Then b = b + 1
Text1.Text = Text1.Text & a(i) & ","
Next i
End Sub
一个文本一个按钮,,fs.txt放到C盘,,一运行程序,,
文本将从大到小显示分数,,,按下按钮,将显示满分人数
Dim b As Integer
Private Sub Command1_Click()
Text1.Text = Text1.Text & "满分人数" & b
End Sub
Private Sub Form_Load()
Dim c As Double
Dim a() As String
Dim t1 As String
Text1.Text = ""
Open "c:\fs.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, t1
Loop
a = Split(t1, " ")
For i = 0 To UBound(a)
For j = i + 1 To UBound(a)
If Val(a(j)) > Val(a(i)) Then
c = a(i)
a(i) = a(j)
a(j) = c
End If
Next j
If Val(a(i)) = 100 Then b = b + 1
Text1.Text = Text1.Text & a(i) & ","
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在窗体中添加一个text1,一个command1,把fs.txt放到c:\fs.txt
双击command1,添加如下代码:
Dim fs As Integer
Dim a() As String
fs = FreeFile
Open "c:\fs.txt" For Input As fs
Do While Not EOF(fs)
Line Input #fs, X
Y = Len(X) - Len(Replace(X, " ", ""))
If InStr(1, X, " ") > 0 Then
a = Split(X, " ")
For i = 0 To Y
Text1 = a(i) & " " & Text1
Next
End If
Loop
Close fn
For i = 0 To Y
If a(i) = 100 Then c = c + 1
Next
Text1 = Text1 & "满分共 " & c & " 人"
双击command1,添加如下代码:
Dim fs As Integer
Dim a() As String
fs = FreeFile
Open "c:\fs.txt" For Input As fs
Do While Not EOF(fs)
Line Input #fs, X
Y = Len(X) - Len(Replace(X, " ", ""))
If InStr(1, X, " ") > 0 Then
a = Split(X, " ")
For i = 0 To Y
Text1 = a(i) & " " & Text1
Next
End If
Loop
Close fn
For i = 0 To Y
If a(i) = 100 Then c = c + 1
Next
Text1 = Text1 & "满分共 " & c & " 人"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
首先问一下 文件内存储的格式,成绩和成绩之间是空格吗?全角/半角.制表符?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询