|
楼主 |
发表于 2007-9-5 09:21:57
|
显示全部楼层
End Sub
Private Sub CmdSave_Click()
'保存文件
CommonDialog1.ShowSave
filename = CommonDialog1.filename
If filename = "" Then Exit Sub
Text2.Text = "正在保存文件...."
Open filename For Output As #2
form1.Caption = filename + "-文本替换工具"
Print #2, Text1.Text
TextSave = 1
TextChange = 0
Close #2
Text2.Text = "已经保存文件"
End Sub
Private Sub Command1_Click()
'替换操作
Dim string_1 As String
Dim txt_save As String
Text2.Text = "正在执行替换命令..."
'打开文件
Open filename For Input As #1
'逐行读取内容放入变量l_1
Do While EOF(1) = False
Line Input #1, string_1
'========================================================
'逐行修改内容
'l_12 = l_12 + l_1 + "asd" + Chr(13) + Chr(10)
'获得该行的长度
string_len = Len(string_1)
'利用for循环查找手机号码的该行开始位置
string_Find = False
string_Findnum = 0
If string_len >= 11 Then
For j = 1 To string_len
'判断其后是否还有10个字符
If j + 10 > string_len Then
Exit For
End If
string_Mid = Mid(string_1, j, 1)
'检查该字是否是数字
If IsNumeric(string_Mid) = True Then
'检查其后10个字符是否是数字
string_Mid2 = Mid(string_1, j + 10, 1)
If IsNumeric(string_Mid2) = True Then
'找到手机号码
string_Find = True
string_Findnum = j
Exit For
End If
End If
Next
End If
'-------------------------------------------------
'处理数据
For j1 = 1 To 1
If string_Find = True Then
'屏蔽手机末四位数字
If OptionPho(0).Value = True Then
string_mid3 = Mid(string_1, j + 7, 4)
'替换数字
string_1 = Replace(string_1, string_mid3, "****")
Exit For
End If
'只保留手机号码
If OptionPho2.Value = True Then
string_mid3 = Mid(string_1, j, 11)
string_1 = string_mid3
Exit For
End If
'自定义替换
If OptionFree.Value = True Then
rep1 = txtFind.Text
rep2 = txtReplace.Text
string_1 = Replace(string_1, rep1, rep2)
Exit For
End If
End If
Next
'---------------------------------------------------
txt_save = txt_save + string_1 + Chr(13) + Chr(10)
'======================================================
Loop
'关闭文件
Close #1
'保存文件
Open filename For Output As #2
Print #2, txt_save
Text2.Text = "替换完成"
'========================================================
'************显示替换的内容************
Text2.Text = "正在加载文件...."
Open filename For Input As #5
form1.Caption = filename + "-文本替换工具"
'逐行读取内容
Do While Not EOF(5)
Line Input #5, curstring
Text1.Text = Text1.Text + curstring + Chr(13) + Chr(10)
Loop
'关闭文件
Close #5
Text2.Text = "已经打开文件"
TextSave = 1
TextChange = 0
'******************************************
'==============================================================
End Sub
Private Sub Command2_Click()
'取消替换操作
'OptionPho(0).Value = false
OptionPho(0).Enabled = False
'OptionPho2.Value = False
OptionPho2.Enabled = False
'OptionFree.Value = False
OptionFree.Enabled = False
Command1.Enabled = False
Command2.Enabled = False
txtFind.Enabled = False
txtReplace.Enabled = False
'禁止新建,打开,保存按钮的使用
CmdNew.Enabled = True
CmdOpen.Enabled = True
CmdSave.Enabled = True
Text2.Text = "已经取消替换命令"
End Sub
Private Sub Command4_Click()
Unload Me
Form2.Show
End Sub
Private Sub Form_Load()
Text1.Text = ""
TextSave = 1
TextChange = 0
'打开文件
'Open "c:\11.txt" For Input As #1
'逐行读取内容放入变量l_1
'Do While EOF(1) = False
'Line Input #1, l_1
'逐行修改内容
'l_12 = l_12 + l_1 + "asd" + Chr(13) + Chr(10)
'rint #1, l_12
'Loop
'关闭文件
'Close #1
'保存文件
'Open "c:\11.txt" For Output As #2
'rint #2, l_12
End Sub
Private Sub OptionFree_Click()
txtFind.Enabled = True
txtReplace.Enabled = True
End Sub
Private Sub OptionPho_Click(Index As Integer)
txtFind.Enabled = False
txtReplace.Enabled = False
End Sub
Private Sub OptionPho2_Click()
txtFind.Enabled = False
txtReplace.Enabled = False
End Sub
Private Sub Text1_Change()
TextChange = 1
TextSave = 0
End Sub
Private Sub txtFind_GotFocus()
'获得焦点,清除默认值
txtFind.Text = ""
End Sub
Private Sub txtReplace_GotFocus()
txtReplace.Text = ""
End Sub |
|