1。以二进制方式打开文本文件,将其内容全部或分段读入字串变量;
2。用instr语句搜索“tab”的位置,以确定行次(或以搜索相应的分行标志确定行次);
3。以mid$读取指定位置的数据。
你的程序只读了123txt中的第一行文字,可以肯定,这一行文字中少于2个逗号,也就是说a(2)是不存在的,所以下标越界。
如果你需要读取123txt中的全部文字,且123txt中有多行文字,你的程序是有问题的。
以下的代码演示了如何将一个文本文件一次性读到一个字符串变量中,方法是采用了一个和文本文件等长的字符串变量来接收文本
Dim
s
As
String
Open
"d:\123txt"
For
Binary
As
#1
s
=
Space(LOF(1))
Get
#1,
,
s
Close
#1
Text1Text
=
s
只要能弄懂控件的大体属性就可以了,这个要查MSDN,不需要弄太懂否则会花费很多额外的时间,看下主要的属性,举个例子,学习ADO很麻烦,但是只要弄懂ADO中的recordset和connection就可以了,对这两个又主要弄懂movefirst,movenext,open等几个就行,全弄懂得头疼死你
补充一下,rsfiled属性最重要忘了说了,弄好这几个属性基本上ADO的一般小 *** 作就OK了,VB的其它程序的学习也类似,80%的功能20%的控件完成,掌握好这20%就行了
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _
ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, _
ByVal uExitCode As Long) As Long
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String 1024
End Type
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Dim pid As Long
Dim pname As String
Private Sub Command1_Click()
Dim my As PROCESSENTRY32
Dim l As Long
Dim l1 As Long
Dim flag As Boolean
Dim mName As String
Dim i As Integer
l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If l Then
mydwSize = 1060
If (Process32First(l, my)) Then '遍历第一个进程
Do
i = InStr(1, myszExeFile, Chr(0))
mName = LCase(Left(myszExeFile, i - 1))
List1AddItem mName
' If mName = "1exe" Then
' pid = myth32ProcessID
' pname = mName
' MsgBox "找到word"
' If MsgBox("你想删除 " & mName & " 进程", vbYesNo + vbQuestion) <> vbYes Then
' Exit Sub
' End If
'
' Dim mProcID As Long
' mProcID = OpenProcess(1&, -1&, pid)
' TerminateProcess mProcID, 0&
'
' flag = True
' Exit Sub
' Else
' flag = False
' End If
Loop Until (Process32Next(l, my) < 1) '遍历所有进程知道返回值为False
End If
l1 = CloseHandle(l)
End If
' If flag = False Then
' MsgBox "没有找到word"
' Shell "c:\windows\notepadexe", vbNormalFocus
' End If
End Sub
以上就是关于vb程序中如何读取文本文件指定行指定位置的数据全部的内容,包括:vb程序中如何读取文本文件指定行指定位置的数据、VB怎么读取文件中的全部信息、如何看懂VB程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)