VB怎样读取指定的文本并显示?

d:尀1.txt内容是这样的:35746515748-16545158-正常74865415684-56468465-正常98465163879-16874961-正常...怎么实现把 35746515748 74865415684 98465163879 ...显示在test1把 16545158 56468465 16874961 ...显示在test2把 正常 正常 正常 ...显示在test3打错字了,显示在test应该是text,不好意思完成了,谢谢三位的热心帮助,最终代码如下:Private Sub Form_Load()Open "d:尀1.txt" For Input As #1End SubPrivate Sub Command1_Click()On Error Resume NextDim str As String, tmpstr() As StringDim i As IntegerLine Input #1, strtmpstr = Split(str, vbCrLf)Text1.Text = Split(tmpstr(i), "-")(0) & vbCrLfText2.Text = Split(tmpstr(i), "-")(1) & vbCrLfText3.Text = Split(tmpstr(i), "-")(2) & vbCrLfEnd Sub点评一下:首先 橡皮树的博客 |给我的启发很大(加一句On Error Resume Next就不会出错了,呵呵)wqfanmail | 的也很好,但有个缺点就是随机字符就会显示不正确<
2026年09月27日 16:28
有3个网友回答
网友(1):

'楼上的代码,当文件最后有空行时会下标越界。
Dim Lines As String
Dim NextLine As String
Dim i As Integer
Open "d:\1.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, NextLine
Text1 = Text1 & Mid(NextLine, 1, 11) & vbCrLf
Text2 = Text2 & Mid(NextLine, 13, 8) & vbCrLf
Text3 = Text3 & Mid(NextLine, 22, 2) & vbCrLf
Loop
Close #1

网友(2):

dim tmptxt as string ,tmpstr() as string
dim i as integer

open "d:\1.txt" for input as #1
tmptxt=strconv(inputb(lof(1),#1),vbunicode)
close #1
tmpstr=split(tmptxt,vbcrlf)

for i=0 to ubound(tmpstr)
text1=text1 & split(tmpstr(i),"-")(0) & vbcrlf
text2=text2 & split(tmpstr(i),"-")(1) & vbcrlf
text3=text3 & split(tmpstr(i),"-")(2) & vbcrlf
next i

网友(3):

这个可以把一行读出来,然后按“-”分割成三部分,最后把每一行的各个部分连起来