VB逐行读取TXT
VB逐行读取TXT,我需要vb能实现逐行读取txt文本,当读完第一行后,赋值在textbox中,再次单击command后,读第二行,赋值在textbox中,以此类推,直到...
VB逐行读取TXT,我需要vb能实现逐行读取txt文本,当读完第一行后,赋值在textbox中,再次单击command后,读第二行,赋值在textbox中,以此类推,直到读完txt文本。恳请同在一片蓝天下的中国人帮帮忙啊!
展开
2013-09-14
展开全部
Function GetLineStr(FileSpec As String) As String() '获取filespec路径下文件每一行内容,并写入数组函数中
Dim i As Integer
Dim TempStr As String, Temp() As String
Dim FileNum As Integer
FileNum = FreeFile
Open FileSpec For Input As #FileNum
Do While Not EOF(1)
Line Input #FileNum, TempStr
i = i + 1
ReDim Preserve Temp(1 To i) As String
Temp(i) = TempStr
Loop
GetLineStr = Temp
Close #FileNum
End FunctionPrivate Sub Command1_Click() '调用示例
Dim FileSpec As String 'txt路径
Static i As Integer
Dim LineStr() As String
i = 1
If i = UBound(LineStr) Then
MsgBox "文件已结束"
i = 1
End If
FileSpec = "d:\1.txt"
LineStr = GetLineStr(FileSpec)
text1.Text = LineStr(i)
i = i + 1
Next
Dim i As Integer
Dim TempStr As String, Temp() As String
Dim FileNum As Integer
FileNum = FreeFile
Open FileSpec For Input As #FileNum
Do While Not EOF(1)
Line Input #FileNum, TempStr
i = i + 1
ReDim Preserve Temp(1 To i) As String
Temp(i) = TempStr
Loop
GetLineStr = Temp
Close #FileNum
End FunctionPrivate Sub Command1_Click() '调用示例
Dim FileSpec As String 'txt路径
Static i As Integer
Dim LineStr() As String
i = 1
If i = UBound(LineStr) Then
MsgBox "文件已结束"
i = 1
End If
FileSpec = "d:\1.txt"
LineStr = GetLineStr(FileSpec)
text1.Text = LineStr(i)
i = i + 1
Next
2013-09-14
展开全部
既然同胞都出声了,我还不帮忙吗,兄弟,我刚写了一段代码,你看看能用不
Private Sub Form_Load()
Open "C:\123.txt" For Input As #1
End Sub
Private Sub Command1_Click()
On Error Resume Next
Dim str As String
Line Input #1, str
Text1.Text = str
End Sub
Private Sub Form_Load()
Open "C:\123.txt" For Input As #1
End Sub
Private Sub Command1_Click()
On Error Resume Next
Dim str As String
Line Input #1, str
Text1.Text = str
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-14
展开全部
Private Sub Command1_Click()
Dim s As String
While Not EOF(1)
Line Input #1, s
Text1.Text = s
Wend
End Sub
Private Sub Form_Load()
Open "d:\new\high.txt" For Input As #1
End Sub
Private Sub Form_Unload(Cancel As Integer)
Close #1
End
End Sub
Dim s As String
While Not EOF(1)
Line Input #1, s
Text1.Text = s
Wend
End Sub
Private Sub Form_Load()
Open "d:\new\high.txt" For Input As #1
End Sub
Private Sub Form_Unload(Cancel As Integer)
Close #1
End
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-14
展开全部
很简单 有很多办法的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询