主题:我正尝试着编一个TXT分割程序,受阻,附上有错的代码,求助!
程序目的是将TXT在含特定字符的行分割。例如一部小说,将它在“第×章”处分开。
我的想法是使用LINE INPUT逐行将原文件读入,再写入预先创建的空文件里。使用LIKE检查是否含有指定的字(编程时为了方便,直接写在了代码里,没有使用文本框输入),若有,则另开文件,继续写入。可实际运行时,只能生成一个文件,且其中多出了很多乱码,这是怎么回事?鄙人只学了一学期VB,肯请指教!
我写的错误代码:
Private mubiao As String, chuan As String, haoma As Integer
Private Sub Command1_Click()
Dim i As Integer
haoma = 2
Open "D:\" & i + 2 & ".txt" For Append As #haoma
Do While Not EOF(1)
Line Input #1, chuan
If chuan Like "小说名称" Then
Close #haoma
haoma = haoma + 1
Open "D:\" & i + 3 & ".txt" For Append As #haoma
Print #haoma, chuan
Else
Print #haoma, chuan
End If
i = i + 1
Loop
Close
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub drive1_change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
mubiao = File1.Path & "\" & File1.FileName
Open mubiao For Input As #1
End Sub
我的想法是使用LINE INPUT逐行将原文件读入,再写入预先创建的空文件里。使用LIKE检查是否含有指定的字(编程时为了方便,直接写在了代码里,没有使用文本框输入),若有,则另开文件,继续写入。可实际运行时,只能生成一个文件,且其中多出了很多乱码,这是怎么回事?鄙人只学了一学期VB,肯请指教!
我写的错误代码:
Private mubiao As String, chuan As String, haoma As Integer
Private Sub Command1_Click()
Dim i As Integer
haoma = 2
Open "D:\" & i + 2 & ".txt" For Append As #haoma
Do While Not EOF(1)
Line Input #1, chuan
If chuan Like "小说名称" Then
Close #haoma
haoma = haoma + 1
Open "D:\" & i + 3 & ".txt" For Append As #haoma
Print #haoma, chuan
Else
Print #haoma, chuan
End If
i = i + 1
Loop
Close
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub drive1_change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
mubiao = File1.Path & "\" & File1.FileName
Open mubiao For Input As #1
End Sub