7,785
社区成员




'在Form1上添加两个文本框Text1、Text2,一个命令按钮command1
'在设计程序时,将以下设置好。设计时才有效。不能在运行时设置。
'Text1.MultiLine = true
'Text2.MultiLine = true
'Text1.ScrollBars = 3
'Text2.ScrollBars = 3
Option Explicit
Private Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""
ReadFile_GetWord ("d:\cjl.txt")
End Sub
'传送TXT文件,取得“[]”中的内容,并保存为文件
Private Function ReadFile_GetWord(cFile As String) As Boolean
Dim FileCount% ', cFileCount%
Dim cTXTValue$, FileNumber&, U$, B$, M$
Dim S$, ARR$()
Dim IsBBBBB22 As Boolean, TT%
U = "uuuuu": B = "bbbbb": M = "mmmmm" '每个段落中的标识符,字符数可自定
IsBBBBB22 = False: TT = 22 'BBBBB后面的[]内字符数大于22
'FileCount = 0
FileNumber = FreeFile
Open (cFile) For Input As #FileNumber '打开文件
Do While Not EOF(FileNumber)
Line Input #FileNumber, cTXTValue '读取一行文本到变量cTXTValue
cTXTValue = Trim(cTXTValue)
If Len(cTXTValue) = 0 And Len(Text1.Text) = 0 Then '迈开文件开头多余的空行
GoTo chenjl1031
Else
'开始读取每一段的内容
If Len(cTXTValue) = 0 And Len(Text1.Text) <> 0 Then '表示一段读取完毕
'FileCount = FileCount + 1 '统计段落数
Text1.Text = Text1.Text & vbCrLf '每显示完一个段落换行
Text2.Text = Text2.Text & vbCrLf '每一段规定内容显示完毕后换行
'Text2.Text = Text2.Text & "(第" & Trim(FileCount) & "段)" & vbCrLf '每一段规定内容显示完毕后换行
Else
Text1.Text = Text1.Text & cTXTValue & vbCrLf '每读一行都复制到文本框Text1
'以下6行是将uuuuu bbbbb mmmmm 后 []内 的 内 容保存到文本框Text2中
If InStr(1, cTXTValue, LCase(U)) > 0 And InStr(1, cTXTValue, "[") > 0 Then
S = Mid(cTXTValue, InStr(1, cTXTValue, LCase(U)) + Len(LCase(U)), Len(cTXTValue) - InStr(1, cTXTValue, LCase(U)) - Len(LCase(U)))
S = Mid(S, InStr(1, S, "[") + 1, InStr(1, S, "]") - InStr(1, S, "[") - 1)
Text2.Text = Text2.Text & S & " "
End If
If InStr(1, cTXTValue, LCase(B)) > 0 And InStr(1, cTXTValue, "[") > 0 Then
S = Mid(cTXTValue, InStr(1, cTXTValue, LCase(B)) + Len(LCase(B)), Len(cTXTValue) - InStr(1, cTXTValue, LCase(B)) - Len(LCase(B)))
S = Mid(S, InStr(1, S, "[") + 1, InStr(1, S, "]") - InStr(1, S, "[") - 1)
If Len(B) > TT Then IsBBBBB22 = True '标识符BBBBB后面[]内容长度大于22
Text2.Text = Text2.Text & S & " "
End If
If InStr(1, cTXTValue, LCase(M)) > 0 And InStr(1, cTXTValue, "[") > 0 Then
S = Mid(cTXTValue, InStr(1, cTXTValue, LCase(M)) + Len(LCase(M)), Len(cTXTValue) - InStr(1, cTXTValue, LCase(M)) - Len(LCase(M)))
S = Mid(S, InStr(1, S, "[") + 1, InStr(1, S, "]") - InStr(1, S, "[") - 1)
Text2.Text = Text2.Text & S & " "
End If
If InStr(1, cTXTValue, UCase(U)) > 0 And InStr(1, cTXTValue, "[") > 0 Then
S = Mid(cTXTValue, InStr(1, cTXTValue, UCase(U)) + Len(UCase(U)), Len(cTXTValue) - InStr(1, cTXTValue, UCase(U)) - Len(UCase(U)))
S = Mid(S, InStr(1, S, "[") + 1, InStr(1, S, "]") - InStr(1, S, "[") - 1)
Text2.Text = Text2.Text & S & " "
End If
If InStr(1, cTXTValue, UCase(B)) > 0 And InStr(1, cTXTValue, "[") > 0 Then
S = Mid(cTXTValue, InStr(1, cTXTValue, UCase(B)) + Len(UCase(B)), Len(cTXTValue) - InStr(1, cTXTValue, UCase(B)) - Len(UCase(B)))
S = Mid(S, InStr(1, S, "[") + 1, InStr(1, S, "]") - InStr(1, S, "[") - 1)
If Len(B) > TT Then IsBBBBB22 = True '标识符BBBBB后面[]内容长度大于22
Text2.Text = Text2.Text & S & " "
End If
If InStr(1, cTXTValue, UCase(M)) > 0 And InStr(1, cTXTValue, "[") > 0 Then
S = Mid(cTXTValue, InStr(1, cTXTValue, UCase(M)) + Len(UCase(M)), Len(cTXTValue) - InStr(1, cTXTValue, UCase(M)) - Len(UCase(M)))
S = Mid(S, InStr(1, S, "[") + 1, InStr(1, S, "]") - InStr(1, S, "[") - 1)
Text2.Text = Text2.Text & S & " "
End If
End If
End If
'cFileCount = cFileCount + 1
chenjl1031:
Loop
Close #FileNumber
Text2.Text = Text2.Text & vbCrLf '多加一回车换行
ARR = Split(Text2.Text, vbCrLf) '每一段规定内容转换到数组ARR中
'Debug.Print ARR(0), ARR(1), ARR(2), ARR(3)
If Dir("d:\cjl_1.txt") <> "" Then Kill ("d:\cjl_1.txt")
FileNumber = FreeFile
Open ("d:\cjl_1.txt") For Output Shared As #FileNumber '打开文件,准备保存
If IsBBBBB22 Then
For FileCount = 0 To UBound(ARR)
If Len(ARR(FileCount)) <> 0 Then Print #FileNumber, Trim(ARR(FileCount))
Next
End If
Close #FileNumber
End Function
'在Form1上添加两个文本框Text1、Text2,一个命令按钮command1
'在设计程序时,将以下设置好。设计时才有效。不能在运行时设置。
'Text1.MultiLine = true
'Text2.MultiLine = true
'Text1.ScrollBars = 3
'Text2.ScrollBars = 3
Option Explicit
Private Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""
ReadFile_GetWord ("d:\cjl.txt")
End Sub
'传送TXT文件,取得“[]”中的内容,并保存为文件
Private Function ReadFile_GetWord(cFile As String) As Boolean
Dim FileCount% ', cFileCount%
Dim cTXTValue$, FileNumber&, U$, B$, M$
Dim S$, ARR$()
Dim IsBBBBB22 As Boolean, TT%
Dim V1%, V2%
U = "uuuuu": B = "bbbbb": M = "mmmmm" '每个段落中的标识符,字符数可自定
IsBBBBB22 = False: TT = 22 'BBBBB后面的[]内字符数大于22
'FileCount = 0
FileNumber = FreeFile
Open (cFile) For Input As #FileNumber '打开文件
Do While Not EOF(FileNumber)
Line Input #FileNumber, cTXTValue '读取一行文本到变量cTXTValue
cTXTValue = Trim(cTXTValue)
If Len(cTXTValue) = 0 And Len(Text1.Text) = 0 Then '迈开文件开头多余的空行
GoTo chenjl1031
Else
'开始读取每一段的内容
If Len(cTXTValue) = 0 And Len(Text1.Text) <> 0 Then '表示一段读取完毕
'FileCount = FileCount + 1 '统计段落数
Text1.Text = Text1.Text & vbCrLf '每显示完一个段落换行
Text2.Text = Text2.Text & vbCrLf '每一段规定内容显示完毕后换行
'Text2.Text = Text2.Text & "(第" & Trim(FileCount) & "段)" & vbCrLf '每一段规定内容显示完毕后换行
Else
Text1.Text = Text1.Text & cTXTValue & vbCrLf '每读一行都复制到文本框Text1
'以下6行是将uuuuu bbbbb mmmmm 后 []内 的 内 容保存到文本框Text2中
If InStr(1, cTXTValue, LCase(U)) > 0 And InStr(1, cTXTValue, "[") > 0 Then
V1 = InStr(1, cTXTValue, LCase(U)) + Len(LCase(U))
V2 = Len(cTXTValue) - InStr(1, cTXTValue, LCase(U)) - Len(LCase(U))
S = Mid(cTXTValue, V1, V2)
V1 = InStr(1, S, "[") + 1
V2 = InStr(1, S, "]") - InStr(1, S, "[") - 1
S = Mid(S, V1, V2)
Text2.Text = Text2.Text & S & " "
End If
If InStr(1, cTXTValue, LCase(B)) > 0 And InStr(1, cTXTValue, "[") > 0 Then
V1 = InStr(1, cTXTValue, LCase(B)) + Len(LCase(B))
V2 = Len(cTXTValue) - InStr(1, cTXTValue, LCase(B)) - Len(LCase(B))
S = Mid(cTXTValue, V1, V2)
V1 = InStr(1, S, "[") + 1
V2 = InStr(1, S, "]") - InStr(1, S, "[") - 1
S = Mid(S, V1, V2)
If Len(B) > TT Then IsBBBBB22 = True '标识符BBBBB后面[]内容长度大于22
Text2.Text = Text2.Text & S & " "
End If
If InStr(1, cTXTValue, LCase(M)) > 0 And InStr(1, cTXTValue, "[") > 0 Then
V1 = InStr(1, cTXTValue, LCase(M)) + Len(LCase(M))
V2 = Len(cTXTValue) - InStr(1, cTXTValue, LCase(M)) - Len(LCase(M))
S = Mid(cTXTValue, V1, V2)
V1 = InStr(1, S, "[") + 1
V2 = InStr(1, S, "]") - InStr(1, S, "[") - 1
S = Mid(S, V1, V2)
Text2.Text = Text2.Text & S & " "
End If
If InStr(1, cTXTValue, UCase(U)) > 0 And InStr(1, cTXTValue, "[") > 0 Then
V1 = InStr(1, cTXTValue, UCase(U)) + Len(UCase(U))
V2 = Len(cTXTValue) - InStr(1, cTXTValue, UCase(U)) - Len(UCase(U))
S = Mid(cTXTValue, V1, V2)
V1 = InStr(1, S, "[") + 1
V2 = InStr(1, S, "]") - InStr(1, S, "[") - 1
S = Mid(S, V1, V2)
Text2.Text = Text2.Text & S & " "
End If
If InStr(1, cTXTValue, UCase(B)) > 0 And InStr(1, cTXTValue, "[") > 0 Then
V1 = InStr(1, cTXTValue, UCase(B)) + Len(UCase(B))
V2 = Len(cTXTValue) - InStr(1, cTXTValue, UCase(B)) - Len(UCase(B))
S = Mid(cTXTValue, V1, V2)
V1 = InStr(1, S, "[") + 1
V2 = InStr(1, S, "]") - InStr(1, S, "[") - 1
S = Mid(S, V1, V2)
If Len(B) > TT Then IsBBBBB22 = True '标识符BBBBB后面[]内容长度大于22
Text2.Text = Text2.Text & S & " "
End If
If InStr(1, cTXTValue, UCase(M)) > 0 And InStr(1, cTXTValue, "[") > 0 Then
V1 = InStr(1, cTXTValue, UCase(M)) + Len(UCase(M))
V2 = Len(cTXTValue) - InStr(1, cTXTValue, UCase(M)) - Len(UCase(M))
S = Mid(cTXTValue, V1, V2)
V1 = InStr(1, S, "[") + 1
V2 = InStr(1, S, "]") - InStr(1, S, "[") - 1
S = Mid(S, V1, V2)
Text2.Text = Text2.Text & S & " "
End If
End If
End If
'cFileCount = cFileCount + 1
chenjl1031:
Loop
Close #FileNumber
Text2.Text = Text2.Text & vbCrLf '多加一回车换行
ARR = Split(Text2.Text, vbCrLf) '每一段规定内容转换到数组ARR中
'Debug.Print ARR(0), ARR(1), ARR(2), ARR(3)
If Dir("d:\cjl_1.txt") <> "" Then Kill ("d:\cjl_1.txt")
FileNumber = FreeFile
Open ("d:\cjl_1.txt") For Output Shared As #FileNumber '打开文件,准备保存
If IsBBBBB22 Then
For FileCount = 0 To UBound(ARR)
If Len(ARR(FileCount)) <> 0 Then Print #FileNumber, Trim(ARR(FileCount))
Next
End If
Close #FileNumber
End Function