当前位置:编程学习 > VB >>

用VB 把文本文件转换成HTML文件

用VB 把文本文件转换成HTML文件
追问:太乱了不行 

答案:Option Explicit
Private Sub Form_Load()
CommonDialog1.CancelError = True
Text3.Visible = False
Command1.Capti = "打开"
Command2.Caption = "转换==$#@62;"
Command3.Caption = "保存"
End Sub
Private Sub Command1_Click() On Error Resume Next
Dim TextLine As String
CommonDialog1.Filter = "网页|*.htm;*.html"
CommonDialog1.ShowOpen
If err $#@60;$#@62; 32755 Then
Text1 = ""
"打开文件
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Line Input #1, TextLine
Text1 = Text1 & Trim(TextLine)
Loop
Close #1
Else
MsgBox "不能打开文件"
End If
End Sub
Private Sub Command3_Click()
On Error Resume Next
CommonDialog1.Filter = "文本文件|*.txt"
CommonDialog1.ShowSave
If err $#@60;$#@62; 32755 Then
Open CommonDialog1.FileName For Output As #1
Print #1, Text3
Close #1
Else
MsgBox "不能保存文件"
End If
End Sub
Private Sub Command2_Click()
Dim txtStr As String
On Error GoTo err
Form1.MousePointer = 11
Text3.Text = Text1.Text
DoEvents
Form1.Caption = "正在去掉$#@60;head$#@62;部分..."
"去掉$#@60;head$#@62;部分
Do While InStr(1, LCase(Text3.Text), "$#@60;/head$#@62;") $#@60;$#@62; 0
Text3.SelStart = 0
Text3.SelLength = InStr(1, LCase(Text3.Text), "$#@60;/head$#@62;") + 6
Text3.SelText = ""
Loop
Form1.Caption = "正在去掉$#@60;script$#@62;部分..."
"去掉$#@60;script$#@62;部分
Do While InStr(1, LCase(Text3.Text), "$#@60;/script$#@62;") $#@60;$#@62; 0
Text3.SelStart = InStr(1, LCase(Text3.Text), "$#@60;script") - 1
Text3.SelLength = InStr(1, LCase(Text3.Text), "$#@60;/script$#@62;") - Text3.SelStart + 9
Text3.SelText = ""
Loop
Form1.Caption = "正在转换$#@60;br$#@62;为换行符..."
"转换$#@60;br$#@62;为换行符
Do While InStr(1, LCase(Text3.Text), "$#@60;br$#@62;") $#@60;$#@62; 0
Text3.SelStart = InStr(1, LCase(Text3.Text), "$#@60;br$#@62;") - 1
Text3.SelLength = 4
Text3.SelText = "" + vbCrLf
Loop
Form1.Caption = "正在转换$#@60;p$#@62;$#@60;/p$#@62;为换行符..."
"转换$#@60;/p$#@62;为换行符
Do While InStr(1, LCase(Text3.Text), "$#@60;/p$#@62;") $#@60;$#@62; 0
Text3.SelStart = InStr(1, LCase(Text3.Text), "$#@60;/p$#@62;") - 1
Text3.SelLength = 4
Text3.SelText = "" + vbCrLf
Loop
Form1.Caption = "正在删除Html标记..."
"去掉其它的Html标记
Do While InStr(1, LCase(Text3.Text), "$#@60;") $#@60;$#@62; 0
Text3.SelStart = InStr(1, LCase(Text3.Text), "$#@60;") - 1
Text3.SelLength = InStr(1, LCase(Text3.Text), "$#@62;") - Text3.SelStart
Text3.SelText = ""
Loop
Form1.Caption = "正在转换"$#@60;"为"$#@60;"..."
"转换"$#@60;"为"$#@60;"
Do While InStr(1, LCase(Text3.Text), "$#@60;") $#@60;$#@62; 0
Text3.SelStart = InStr(1, LCase(Text3.Text), "$#@60;") - 1
Text3.SelLength = 4
Text3.SelText = "$#@60;"
Loop
Form1.Caption = "正在转换"$#@62;"为"$#@62;"..."
"转换"$#@62;"为"$#@62;"
Do While InStr(1, LCase(Text3.Text), "$#@62;") $#@60;$#@62; 0
Text3.SelStart = InStr(1, LCase(Text3.Text), "$#@62;") - 1
Text3.SelLength = 4
Text3.SelText = "$#@62;"
Loop
Form1.Caption = "正在转换"&"为"&"..."
"转换"&"为"&"
Do While InStr(1, LCase(Text3.Text), "&") $#@60;$#@62; 0
Text3.SelStart = InStr(1, LCase(Text3.Text), "&") - 1
Text3.SelLength = 5
Text3.SelText = "&"
Loop
Form1.Caption = "正在转换" "为空格符..."
"转换" "为" "
Do While InStr(1, LCase(Text3.Text), " ") $#@60;$#@62; 0
Text3.SelStart = InStr(1, LCase(Text3.Text), " ") - 1
Text3.SelLength = 6
Text3.SelText = " "
Loop
Form1.Caption = "正在转换"""为引号..."
"转换"""为引号
Do While InStr(1, LCase(Text3.Text), """) $#@60;$#@62; 0
Text3.SelStart = InStr(1, LCase(Text3.Text), """) - 1
Text3.SelLength = 6
Text3.SelText = """"
Loop
"去掉前后空格符
Text2.Text = Trim$(Text3.Text)
Form1.Caption = "转换成功!"
Form1.MousePointer = 0
Exit Sub
err:
Form1.Caption = "转换错误"
Form1.MousePointer = 0
MsgBox "转换时出错,请检查你的源文件!"
Exit Sub
End Sub
下面相关内容里面有好多链接和这个差不多,你好好看看吧!!!

上一个:vb中的start和shell的区别
下一个:vb 代码 最好能对应翻译 谢谢

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,