Imports System.IO Imports System.Text Module GOOGLE翻譯 Public Class MyModule2 Friend Shared Sub 執行翻譯() Dim 判斷 As Boolean : Dim strDirName As String : Dim FilePath As String If TW = True And EN = False Then : 判斷 = True : ElseIf TW = False And EN = True Then : 判斷 = False : Else 翻譯 = StrConv(翻譯, VbStrConv.TraditionalChinese, 1033) For i = 1 To Len(翻譯) If Asc(Mid(翻譯, i, 1)) < 0 Or Asc(Mid(翻譯, i, 1)) > 255 Then 判斷 = True : Exit For Else : 判斷 = False End If Next End If Dim Str2 As String = Application.StartupPath If File.Exists("A.txt") Then : File.Delete("A.txt") : ElseIf File.Exists(Str2 & "\A.txt") Then : strDirName = Str2 & "\A.txt" : End If If File.Exists("C.txt") Then : File.Delete("C.txt") : ElseIf File.Exists(Str2 & "\C.txt") Then : strDirName = Str2 & "\C.txt" : End If If File.Exists("ch.txt") Then : File.Delete("ch.txt") : ElseIf File.Exists(Str2 & "\ch.txt") Then : strDirName = Str2 & "\ch.txt" : End If If File.Exists("en.txt") Then : File.Delete("en.txt") : ElseIf File.Exists(Str2 & "\en.txt") Then : strDirName = Str2 & "\en.txt" : End If If File.Exists("in.txt") Then : File.Delete("in.txt") : ElseIf File.Exists(Str2 & "\in.txt") Then : strDirName = Str2 & "\in.txt" : End If If File.Exists(My.Computer.FileSystem.SpecialDirectories.Desktop & "\A.txt") Then : File.Delete(My.Computer.FileSystem.SpecialDirectories.Desktop & "\A.txt") : End If If File.Exists(My.Computer.FileSystem.SpecialDirectories.Desktop & "\C.txt") Then : File.Delete(My.Computer.FileSystem.SpecialDirectories.Desktop & "\C.txt") : End If If File.Exists(My.Computer.FileSystem.SpecialDirectories.Desktop & "\ch.txt") Then : File.Delete(My.Computer.FileSystem.SpecialDirectories.Desktop & "\ch.txt") : End If If File.Exists(My.Computer.FileSystem.SpecialDirectories.Desktop & "\en.txt") Then : File.Delete(My.Computer.FileSystem.SpecialDirectories.Desktop & "\en.txt") : End If If File.Exists(My.Computer.FileSystem.SpecialDirectories.Desktop & "\in.txt") Then : File.Delete(My.Computer.FileSystem.SpecialDirectories.Desktop & "\in.txt") : End If Dim utf8 As UTF8Encoding = New UTF8Encoding(False) : FilePath = "A.txt" Try Using fs As IO.FileStream = New IO.FileStream(FilePath, FileMode.Append) Using sw As StreamWriter = New StreamWriter(fs, utf8) : Dim str As String = 翻譯 : sw.Write(str) : sw.Flush() : End Using End Using Catch ex As Exception End Try If 判斷 = True Then : FilePath = "C.txt" Try Using fs As IO.FileStream = New IO.FileStream(FilePath, FileMode.Append) Using sw As StreamWriter = New StreamWriter(fs, utf8) : Dim str As String = "中文" : sw.Write(str) : sw.Flush() : End Using End Using Catch ex As Exception End Try Else : FilePath = "C.txt" Try Using fs As IO.FileStream = New IO.FileStream(FilePath, FileMode.Append) Using sw As StreamWriter = New StreamWriter(fs, utf8) : Dim str As String = "非中文" : sw.Write(str) : sw.Flush() : End Using End Using Catch ex As Exception End Try End If Shell("Tran.exe", vbNormalFocus) End Sub End Class End Module