如何用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中同时要用读取到的数据绘制曲线

高手们帮帮忙
...全文
540 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
  • 打赏
  • 举报
回复
要是分数不够可以加分,高手们出手吧
内容概要:本文提出了一种基于非合作博弈理论的居民负荷分层调度模型,并结合双层鲸鱼优化算法(Two-level Whale Optimization Algorithm)进行高效求解,模型与算法均通过Matlab代码实现。研究针对电力系统中居民侧用电负荷的复杂调度问题,引入非合作博弈机制刻画各用户之间的利益竞争关系,实现负荷的分层优化分配;同时设计双层优化架构,上层优化资源配置,下层模拟用户自主决策行为,提升了模型的实用性与合理性。通过智能优化算法求解多层级、非凸非线性的博弈模型,有效提高了调度方案的收敛性与全局寻优能力,适用于现代智能电网中的需求侧管理与能源优化场景。; 适合人群:具备电力系统基础理论知识和Matlab编程能力,从事智能电网、能源优化调度、需求侧管理、博弈论应用等方向的科研人员、高校研究生及工程技术人员。; 使用场景及目标:①应用于居民区电力负荷的分层优化调度系统设计与仿真分析;②为非合作博弈在多主体能源系统建模中的应用提供方法论支持;③利用双层鲸鱼算法解决具有嵌套结构的复杂双层优化问题,提升求解效率与调度方案的可行性。; 阅读建议:建议读者结合提供的Matlab代码深入理解模型构建逻辑与算法实现流程,重点关注博弈模型的效用函数设计、纳什均衡求解思路以及双层优化结构的迭代机制,宜配合实际用电数据开展复现实验以验证模型有效性与鲁棒性。

7,788

社区成员

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

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