比如说有一个文件1.txt,内容是:
1 0.6
2 0.3
4 0.7
。
。
。
有多少行是不知道的,将其读到一个二维的数组中。
要求第一列放在下标1,第二列放在下标2.
多谢,急需要!!!
再以二维数组的下标一为横轴,以数组的下标二为纵轴,画出折线图
新手提问:如何用VB编程将*.txt文件中的数据读入到二维的数组?
答案:2 悬赏:40 手机版
解决时间 2021-03-05 12:03
- 提问者网友:疯子也有疯子的情调
- 2021-03-04 12:05
最佳答案
- 五星知识达人网友:老鼠爱大米
- 2021-03-04 13:33
Private Sub Command1_Click()
Dim s() As String, r() As String, i As Long, t As String
Open "c:\1.txt" For Input As #1
i = 0
Do Until EOF(1)
Line Input #1, t
Do While InStr(t, " ")
t = Replace(t, " ", " ")
Loop
r = Split(t, " ")
If UBound(r) = 1 Then
ReDim Preserve s(1 To 2, i)
s(1, i) = r(0)
s(2, i) = r(1)
i = i + 1
End If
Loop
Close #1
For i = 0 To UBound(s, 2)
Print s(1, i), s(2, i)
Next
End Sub
Dim s() As String, r() As String, i As Long, t As String
Open "c:\1.txt" For Input As #1
i = 0
Do Until EOF(1)
Line Input #1, t
Do While InStr(t, " ")
t = Replace(t, " ", " ")
Loop
r = Split(t, " ")
If UBound(r) = 1 Then
ReDim Preserve s(1 To 2, i)
s(1, i) = r(0)
s(2, i) = r(1)
i = i + 1
End If
Loop
Close #1
For i = 0 To UBound(s, 2)
Print s(1, i), s(2, i)
Next
End Sub
全部回答
- 1楼网友:长青诗
- 2021-03-04 14:58
如果需要读入不定个数,那就在程序中再加一句输入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
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯