如何将.txt文件的数据读到两个数组中

Tonyhj 2003-03-05 11:02:19
温度/时间 数据存放在一个temp.txt的 文本文档里面。温度要在10到30摄氏度之间,时间的范围是0到4000分钟,时间要列在第一列,温度列在第二列。例如:
12 0
12 1
12 2
13 3
13 4
。。。
22 4000
...全文
109 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xkdh 2003-03-05
  • 打赏
  • 举报
回复
如果换成do until 可能会好点。
dim stm as string
dim i as integer
open "temp.txt" for input as #1
redim s1(1 to lof(1)) as string
redim s2(1 to lof(1)) as string
do until eof(1)
line input #1, stm
i=i+1
s1(i)=left(stm,2)
s2(i)=right(stm,len(stm)-3)
loop
close #1

xkdh 2003-03-05
  • 打赏
  • 举报
回复
dim stm as string
dim i as integer
open "temp.txt" for input as #1
redim s1(1 to lof(1)) as string
redim s2(1 to lof(1)) as string
for i=1 to lof(1)
line input #1, stm
s1(i)=left(stm,2)
s2(i)=right(stm,len(stm)-3)
next i
close #1
cotaxyp 2003-03-05
  • 打赏
  • 举报
回复
Dim Num1, Num2
dim array1(),array2()
dim arrnum as integer '记录数组长度
arrnum=0
redim array1(arrnum)
redim array2(arrnum)
Open "temp.txt" For Input As #1 ' 打开输入文件。
Do While Not EOF(1) ' 循环至文件尾。
Input #1, Num1, Num2 ' 将数据读入两个变量。
arrnum=arrnum+1
redim preserve array1(arrnum)
redim preserve array2(arrnum)
array1(arrnum-1)=val(num1)
array2(arrnum-1)=val(num2)
Loop
Close #1 ' 关闭文件。
northwolves 2003-03-05
  • 打赏
  • 举报
回复
dim filetxt as string,wendu(1 to 4000) as integer,shijian(1 to 4000)as integer
dim temps,lines
filetxt = String(FileLen("temp.txt" ), " ")
Open txtpath For Binary As 1
Get #1, , filetxt
Close 1
temps=split(filetxt,vbcrlf)
for i=1 to 4000
lines=split(temps(i-1)," ")
wendu(i)=lines(0)
shijian=lines(1)
set lines=nothing
next

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧