将fs.txt文件中的5个学生成绩顺序读入数组A,并在文本框text1中显示出来?单击"满分人数"按钮,在text1中显示数组成绩单100出现的次数? fs.txt文件中存着 98 100 89 100 100
一楼:文件格式是txt,成绩间是空格..没其它的要求了.
VB读文件将其读入数组中
答案:4 悬赏:30
解决时间 2021-04-06 15:40
- 提问者网友:相思瘸子
- 2021-04-06 05:38
最佳答案
- 二级知识专家网友:晨与橙与城
- 2021-04-06 06:16
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
全部回答
- 1楼网友:迷人小乖乖
- 2021-04-06 07:55
如果需要读入不定个数,那就在程序中再加一句输入n的语句,或添加一text1,其中内容表示元素个数。
private sub form_click()
dim a(1 to 10000) as integer,n as integer
n = inputbox("请输入数组元素个数", "输入框")
' n=val(text1.text)
open "e:\vbprogram\input\0.txt" for input as #1
for i = 1 to n
input #1, a(i)
next
close #1
for i = 1 to n
print a(i)
next
end sub
- 2楼网友:魅世女王
- 2021-04-06 06:48
在窗体中添加一个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 & " 人"
- 3楼网友:啵啵桃汀
- 2021-04-06 06:43
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
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
• 手机登qq时,显示手机磁盘不足,清理后重新登 |
• 刺客的套装怎么选啊? |