VB 快速读取文件内容的方法
发布时间:2020-12-16 22:16:31 所属栏目:大数据 来源:网络整理
导读:读取text文件的最快方法是使用Input$函数,就象下面的过程: Function FileText(ByVal filename As String) As String Dim handle As Integer' 判断文件存在性 If Len(Dir$(filename)) = 0 Then Err.Raise 53 '文件没有找到 End If ' 以binary模式打开文件 ha
读取text文件的最快方法是使用Input$函数,就象下面的过程:
Function FileText(ByVal filename As String) As String Dim handle As Integer' 判断文件存在性 If Len(Dir$(filename)) = 0 Then Err.Raise 53 '文件没有找到 End If ' 以binary模式打开文件 handle = FreeFile Open filename$ For Binary As #handle ' 读取内容,关闭文件 FileText = Space$(LOF(handle))Get #handle,FileText Close #handle End Function 使用上述方法要比使用Input命令读取文件每一行的方法快很多。下面是应用这个函数读取Autoexec.bat的内容到多行textbox控件的例子: Text1.Text = FileText("c:autoexec.bat") 无闪烁地快速附加字符串到TextBox控件 附加文本到TextBox或者RichTextBox控件的通常方法是在当前内容上连接上新的字符串: Text1.Text = Text1.Text & newString 但还有一个更快的方法,并且会减少连接操作的闪烁感,代码如下: Text1.SelStart = Len(Text1.Text) Text1.SelText = newString (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |