Option Explicit
Dim strFileApart As StringPrivate Sub CmdOpen_Click()
Dim strFileName As String
Dim strFileNum As Double
strFileName = "f:\小说\庆余年\文本文档.txt"
strFileNum = FileLen(strFileName)
Open strFileName For Input As #1
strFileApart = Input(strFileNum / 2, #1)
Close #1
End SubPrivate Sub CmdWrite_Click() Dim strFileName As String
strFileName = "f:\小说\庆余年\文本文档1.txt"
Open strFileName For Output As #1
Write #1, strFileApart
Close #1
End Sub
我想把一个文本文件分成2段
结果按上面弄出来的文本文件远大于原文本的一半
为什么呢?
还有就是怎么从文本的一半长度开始读取呢?
Dim strFileApart As StringPrivate Sub CmdOpen_Click()
Dim strFileName As String
Dim strFileNum As Double
strFileName = "f:\小说\庆余年\文本文档.txt"
strFileNum = FileLen(strFileName)
Open strFileName For Input As #1
strFileApart = Input(strFileNum / 2, #1)
Close #1
End SubPrivate Sub CmdWrite_Click() Dim strFileName As String
strFileName = "f:\小说\庆余年\文本文档1.txt"
Open strFileName For Output As #1
Write #1, strFileApart
Close #1
End Sub
我想把一个文本文件分成2段
结果按上面弄出来的文本文件远大于原文本的一半
为什么呢?
还有就是怎么从文本的一半长度开始读取呢?
Dim strFileName As String
static k as long
dim strFileApart as string strFileName = "f:\小说\庆余年\文本文档.txt"
strFileApart = space(FileLen(strFileName)/2)
k=1
Open strFileName For binary As #1
get #1,k,strFileApart
k = Seek(h) '定位到下一个读写位置
Close #1
Dim strFileName As String
static k as long
dim strFileApart as string
dim h as long strFileName = "f:\小说\庆余年\文本文档.txt"
strFileApart = space(FileLen(strFileName)/2)
k=1
h=freefile
Open strFileName For binary As h
get #h,k,strFileApart
k = Seek(h) '定位到下一个读写位置
Close
可考虑用富文本框一次读取(选择多行显示,左右滚动条):
richtextbox1.filename="f:\小说\庆余年\文本文档.txt"
然后,用split过滤到一个数组中(分界符vbcrlf),看看有多少个元素。再取元素个数的一半存到另外一个文件中。
Dim sFile As String
Dim Cont As Long, i As Long, s As Long
Dim strTxt1 As String, strTxt2 As String
Dim arr1() As String, arr2() As String, arr() As String Open "c:\1.txt" For Binary As #1
strFile = Space(LOF(1))
Get #1, , strFile
Close #1
arr = Split(strFile, vbCrLf)
For l = 0 To UBound(arr)
Cont = Cont + 1
Next l
If Cont Mod 2 Then
Cont = Cont - 1
End If
For i = 0 To Cont / 2
arr1 = Split(strFile, vbCrLf)
strTxt1 = strTxt1 & arr1(i) & vbCrLf
Next i
For s = (Cont / 2) + 1 To UBound(arr)
arr2 = Split(strFile, vbCrLf)
strTxt2 = strTxt2 & arr2(s) & vbCrLf
Next s
Open "c:\文本文件.TXT" For Output As #2
Print #2, strTxt1
Close #2
Open "c:\文本文件1.txt" For Output As #3
Print #3, strTxt2
Close #3
End Sub