用vb6.0读取txt文件中的一个数字,并对这个数字取倒数,代码怎么写?

2024-11-26 00:33:06
推荐回答(2个)
回答1:

很急是吧,现在你看好:假设你文本文件放在E盘下,名为aa.txt,你这个文本文件中的内容必须是在同一行(即就是不在同一行只要你没有使用回车换行就行)并使用空格隔开即可。然后再窗体上加一个按键command1,将以下代码复制过去即可运行。
Private Sub Command1_Click()
Dim StrLine As String, a() As String, i As Long, j As Long, N As Long, b As String
i = 0: j = 0: N = 0
Open "e:\aa.txt" For Input As #1
Line Input #1, StrLine
If StrLine <> "" Then
a() = Split(StrLine, " ")
N = UBound(a)
For i = 0 To N - 1 Step 1
For j = i + 1 To N Step 1
If Val(a(i)) < Val(a(j)) Then
b = a(i)
a(i) = a(j)
a(j) = b
End If
Next j
Next i
End If
Close #1
Print "总共有 " & N + 1 & "名"
For i = 0 To N
Print "第" & i + 1 & "名 = " & a(i)
Next i
End Sub

回答2:

有两个 0.00500,你要哪个?