sppk.net
当前位置:首页 >> VB如何指定读取文本文件的某一行 >>

VB如何指定读取文本文件的某一行

'添加 Command1 Command2 Text1 Text2 Label1 '在Text2输入欲读取第几行的行号,再点击Command1 'Command2是倒数第二行的内容 Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long...

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

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

Private Sub Form_click() Print ReadSomeLine("z:\1.txt", 3) End Sub Function ReadSomeLine(Str1 As String, LineN As Integer) Dim temp As String Dim a() As Variant, x As Integer Open Str1 For Input As #1 Do While Not EOF(1) Line I...

'这个代码有要求:每个数据不能大于8个字符(tab键默认的所占的字符长度) Private Sub Form_Click() '请点击窗体 Me.Cls Dim xRow, yLine, i, j As Long, Temp As String, Arr(1 To 99) As String xRow = Val(InputBox("输入行数:")) yLine = ...

定义一个变量记录读到了第几行。 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

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, ";"...

Dim A, S As String Dim FreeNum As Integer FreeNum = FreeFile 'Freenum表示一个空闲的文件号 open "D:\date.txt" for input as #FreeNum '这步是打开“date.txt”,for input表示以输入方式(即读取文件)打开。如果要写入文件则应该用output或...

Private Sub Command1_Click() Open App.Path & "\1.txt" For Binary As #1 T = Input(LOF(1), 1) Close #1 T1 = Split(T, vbCrLf) Dim T2(1 To 2) As String For i = 0 To UBound(T1) If InStr(1, T1(i), "a") > 0 Then i1 = i1 + 1 If i1 > UB...

代码: Private Sub Command_Click() Dim a As String Open "C:\\mytext.txt" For Input As #1 Do While Not EOF(1) Line Input #1, a Text1.Text=Text & a & vbCrLf Loop Close #1

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