如何用vb读取txt文件?

Yln 2012-04-17 02:50:16
5.481789e-002 5.487810e-002 -5.477694e-002
5.494057e-002 5.470093e-002 -5.459942e-002
5.500817e-002 5.447027e-002 -5.436759e-002
5.502017e-002 5.418678e-002 -5.408213e-002
5.497612e-002 5.385120e-002 -5.374379e-002
5.487564e-002 5.346429e-002 -5.335335e-002
5.471842e-002 5.302685e-002 -5.291167e-002
读取这样的数据,要每秒读取一行并显示到textbox中同时要用读取到的数据绘制曲线

高手们帮帮忙
...全文
511 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
Yln 2012-04-22
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 的回复:]

Sub Timer1_Timer()
mcurrent = mcurrent + 1
if mcurrent>ubound(Lines)then mcurrent=0

Text2.Text = cstr(mcurrent)
Dim D() As String

d = Split(lines(mcurrent), " ")

Text1.Text = D(0) ……
[/Quote]

可以了
谢谢了哥们
worldy 2012-04-22
  • 打赏
  • 举报
回复
Sub Timer1_Timer()
mcurrent = mcurrent + 1
if mcurrent>ubound(Lines)then mcurrent=0

Text2.Text = cstr(mcurrent)
Dim D() As String

d = Split(lines(mcurrent), " ")

Text1.Text = D(0) 'd(0),d(1),d(2) 既为每行的三个数,你自己决定怎么使用这三个数吧

End Sub
Yln 2012-04-22
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 的回复:]

此句有误:
D = Split(D(I), " ")

==>
dim dd as string
dd= Split(D(I), " ")
[/Quote]



Option Explicit
Dim t As Integer
Dim i As Integer
Dim Lines() As String
Dim mCurrent As Long

Sub Form_load()
Dim resim As Integer
Open "c:/G.txt" For Binary As #1
Dim L As Long
Dim D() As Byte
L = LOF(1)
If L = 0 Then
MsgBox "文件长度为0"
Exit Sub
End If
ReDim D(L - 1)
Get 1, , D
Dim s As String
s = StrConv(D, vbUnicode)
Lines = Split(s, vbCrLf)
End Sub

Sub Timer1_Timer()
t = t + 1
Text2.Text = t
Dim D() As String
Dim dd As String
dd = Split(D(i), " ")

Text1.Text = D(0) 'd(0),d(1),d(2) 既为每行的三个数,你自己决定怎么使用这三个数吧

End Sub
Yln 2012-04-22
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 的回复:]

此句有误:
D = Split(D(I), " ")

==>
dim dd as string
dd= Split(D(I), " ")
[/Quote]
还是下标越界
我qq 810097886
用这个交流吧
worldy 2012-04-22
  • 打赏
  • 举报
回复
此句有误:
D = Split(D(I), " ")

==>
dim dd as string
dd= Split(D(I), " ")
Yln 2012-04-22
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 的回复:]

打错字了,是redim
哪个地方下标越界?
[/Quote]


D = Split(D(I), " ")
Yln 2012-04-22
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 的回复:]
Sub Timer1_Timer()
mcurrent = mcurrent + 1
if mcurrent>ubound(Lines)then mcurrent=0

Text2.Text = cstr(mcurrent)
Dim D() As String

d = Split(lines(mcurrent), " ")

Text1.Text = D(0) '……
[/Quote]


没有多余的分数了,就这么点都给你了
不好意思
worldy 2012-04-21
  • 打赏
  • 举报
回复
打错字了,是redim
哪个地方下标越界?
Yln 2012-04-21
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]

引用 9 楼 的回复:
引用 8 楼 的回复:

修正LS
sub Timer1_Timer
dim D() as string
d=split(d(mCurrent)," ")
mCurrent=mCurrent+1
'd(0),d(1),d(2) 既为每行的三个数,你自己决定怎么使用这三个数吧
end sub


resim D(L-1)

这个出错了
麻烦帮……
[/Quote]

那个应该是redim吧???
还有就是运行的时候出现了下标越界的情况
帮忙解决了吧,然后我给你多加分
worldy 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 的回复:]
引用 8 楼 的回复:

修正LS
sub Timer1_Timer
dim D() as string
d=split(d(mCurrent)," ")
mCurrent=mCurrent+1
'd(0),d(1),d(2) 既为每行的三个数,你自己决定怎么使用这三个数吧
end sub


resim D(L-1)

这个出错了
麻烦帮改改
[/Quote]

估计你没有读到文件,L为0

dim Lines() as string
dim mCurrent as long

sub Form_load

open fName for binary as #1
dim L as long
dim D() as byte
L=lof(1)
if L=0 then
msgbox "文件长度为0"
exit sub
end if
resim D(L-1)
get 1,,D
dim s as string
s=strconv(d,vbunicode)

lines=split(s,vbcrlf)
end sub

sub Timer1_Timer
dim D() as string
d=split(d(i)," ")
'd(0),d(1),d(2) 既为每行的三个数,你自己决定怎么使用这三个数吧
end sub
Yln 2012-04-19
  • 打赏
  • 举报
回复
高手们帮看看啦
Yln 2012-04-17
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]

修正LS
sub Timer1_Timer
dim D() as string
d=split(d(mCurrent)," ")
mCurrent=mCurrent+1
'd(0),d(1),d(2) 既为每行的三个数,你自己决定怎么使用这三个数吧
end sub
[/Quote]

resim D(L-1)

这个出错了
麻烦帮改改
worldy 2012-04-17
  • 打赏
  • 举报
回复
修正LS
sub Timer1_Timer
dim D() as string
d=split(d(mCurrent)," ")
mCurrent=mCurrent+1
'd(0),d(1),d(2) 既为每行的三个数,你自己决定怎么使用这三个数吧
end sub
worldy 2012-04-17
  • 打赏
  • 举报
回复
dim Lines() as string
dim mCurrent as long

sub Form_load

open fName for binary as #1
dim L as long
dim D() as byte
L=lof(1)
resim D(L-1)
get 1,,D
dim s as string
s=strconv(d,vbunicode)

lines=split(s,vbcrlf)
end sub

sub Timer1_Timer
dim D() as string
d=split(d(i)," ")
'd(0),d(1),d(2) 既为每行的三个数,你自己决定怎么使用这三个数吧
end sub
Yln 2012-04-17
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

Line Input方法读取
[/Quote]
但是那个text中的数字不变是什么原因呢?
贝隆 2012-04-17
  • 打赏
  • 举报
回复
Line Input方法读取
Yln 2012-04-17
  • 打赏
  • 举报
回复
    Dim A, S As String
Dim FreeNum As Integer
FreeNum = FreeFile
'Freenum表示一个空闲的文件号
Open "c:\G.txt" For Input As #FreeNum
'这步是打开“date.txt”,for input表示以输入方式(即读取文件)打开。如果要写入文件则应该用output或append。

Do Until EOF(FreeNum) '循环,直到文件结尾。Eof函数用来判断文件是否读完
Line Input #FreeNum, A
S = S + vbNewLine + A 'S用来保存整个文件


If z>t And Not EOF(FreeNum) Then
Text1.Text = A
Line Input #FreeNum, A '读取下一行的内容
Exit Do '退出循环
End If
Loop
Close FreeNum

我用这段程序运行问什么text内容不变呢?
高手指点指点
Yln 2012-04-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

mschart.ocx
你找找看...
[/Quote]
什么意思?
cqq_chen 2012-04-17
  • 打赏
  • 举报
回复
mschart.ocx
你找找看...
Yln 2012-04-17
  • 打赏
  • 举报
回复
要是分数不够可以加分,高手们出手吧

7,763

社区成员

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

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