sppk.net
当前位置:首页 >> vB读取文本文件某行的内容 >>

vB读取文本文件某行的内容

VB可以使用二进制方式打开文本文件,以Get 语句读到字节数组,再使用StrConv 函数将其转换为字符串,而后使用Split函数文本的字符串数组及总句数,使用InputBox 函数来输入需要读某行文本。 Get 语句 将一个已打开的磁盘文件读入一个变量之中。 ...

Private Sub Command1_Click() Open "C:\123.txt" For Input As #1 n = 0 Do While Not EOF(1) Line Input #1, a n = n + 1 If n = 3 Then Text1.Text = a Exit Do End If Loop Close #1 End Sub 这样就可以了。用n来控制行数。当到达了第三行,...

dim num() dim i as long i=0 ReDim ri(0) Open "C:\SAM.txt" For Input As #1 ' 打开文件。 Do While Not EOF(1) '循环至文件尾。 Line Input #1, TextLine '读入一行数据并将其赋予某变量。 num(i)=TextLine i=i+1 ReDim Preserve ri(i) Loop ...

Dim TextLine Dim ret as String Open "目录\a.txt" For Input As #1 ' 打开文件。 Do While Not EOF(1) ' 循环至文件尾。 Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。 '这时就是取到的第一行的值了,如果你确定每行都是这种格式...

用Open打开文件,然后用Line行读取即可。 代码如下: Dim tempStr as String '定义变量tempStr为字符串Open "C:\Test.txt" For Input As #1 '打开文件While Not EOF(1) '读取到结束 Line Input #1, tempStr '读取一行到变量tempStr'对应的处理We...

Dim xx() As String, aa As IntegerPrivate Sub Command1_Click()Text1.Text = "" '清空文本框,这样可以多次点击按钮得到不同的内容Dim zz As IntegerRandomizezz = Int(Rnd * aa + 1) '得到一个随机数Text1.Text = xx(zz) '在文本框显示随机数...

1个Split就能解决你的问题 Dim lie() As String Open App.Path & "\*.txt" For Input As #1 ' 打开你的*.txt文件。 Do While Not EOF(1) ' 循环至文件尾。 Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。 lie = Split(TextLine, ";"...

Private Sub command1_click() Dim s1 As String Dim s2 As String Dim ss As String Dim tem As String Open "D:\123.txt" For Input As #1 Line Input #1, s1 Do While Not EOF(1) Line Input #1, tem If tem = "" And s1 = "" Then Line Inpu...

Open "D:\123.txt" For Input As #1 While Not EOF(1) N = N + 1 Line Input #1, S If N = 3 Then Print S 'N=3 表示读取第3行 Wend Close #1

定义一个变量记录读到了第几行。 Dim txt As String, i As LongOpen "C:\a1.txt" For Input As #1Open "C:\a2.txt" For Output As #2Do While Not EOF(1) Line Input #1, txt i = i + 1 If i = 6 Then txt = "f=4888" Print #2, txtLoopClose

网站首页 | 网站地图
All rights reserved Powered by www.sppk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com