首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

VB读取文本行,该如何解决

2012-02-04 
VB读取文本行VB如何读取文本 每行显示在label标签上当读取到文本末尾是提示文本已结束一个commandclick事

VB读取文本行
VB如何读取文本 每行显示在label标签上 当读取到文本末尾是提示文本已结束 


  一个command click事件就是跳到指定行  




[解决办法]
放置一个label,一个command,C盘下面放一个包含内容的1.txt

VB code
Option ExplicitDim strLine As StringPrivate Sub Command1_Click()Do While Not EOF(1)Line Input #1, strLineLabel1.Caption = strLineExit DoLoopIf EOF(1) Then    Label1.Caption = "文章结束!"    Command1.Enabled = FalseEnd IfEnd SubPrivate Sub Form_Load()Label1.AutoSize = TrueCommand1.Enabled = FalseOpen "c:\1.txt" For Input As #1Do While Not EOF(1)Line Input #1, strLineLabel1.Caption = strLineExit DoLoopCommand1.Enabled = TrueEnd Sub
[解决办法]
用控件数组:

VB code
Option ExplicitPrivate Sub Command1_Click()  Dim strLine As String  Dim i As Integer  For i = 0 To 4    If EOF(1) Then      Label1(i).Caption = "文章结束!"      Command1.Enabled = False      Close #1      Exit Sub    End If    Line Input #1, strLine    Label1(i).Caption = strLine  Next iEnd SubPrivate Sub Form_Load()  Dim i As Integer  for i = 0 To 4    Label1(i).AutoSize = True  Next i  Open "c:\1.txt" For Input As #1  Command1_ClickEnd Sub 

热点排行