vb 如何做翻译器?

2024-12-01 00:29:16
推荐回答(1个)
回答1:

以下均为本人亲自做的:
1.首先新建一个模块(内容如下)
Public cidian(50000, 2) As String '一个可以存放5万的单词的词库数组
Public nowwei As Long '表示当前词库数目
Public Sub ctoe(view1 As Object)
For i = 1 To nowwei Step 1 '查找(中文转英文)
If view1.Text = cidian(i, 1) Then
MsgBox (cidian(i, 2)) '显示结果
Exit Sub
End If
Next
MsgBox ("无结果")
End Sub
Public Sub etoc(view1 As Object)
For i = 1 To nowwei Step 1 '查找(英文转中文)
If view1.Text = cidian(i, 2) Then
MsgBox (cidian(i, 1)) '显示结果
Exit Sub
End If
Next
MsgBox ("无结果")
End Sub
Public Sub addcidian(chinese As String, english As String) '增加词典
nowwei = nowwei + 1
cidian(nowwei, 1) = chinese
cidian(nowwei, 2) = english
End Sub
2.使用函数
你可以在指定的地方使用以下函数:
(1)etoc(view1 as object) '查找(英文转中文)
view1是用户输入框
(2)ctoe(view1 as object) '查找(中文转英'查找(英文转中文)
view1是用户输入框
(3)addcidian(chinese As String, english As String)'增加词典
chinese 是中文
english 是英文
3.例子:
Private Sub Command1_Click()
Call ctoe(Text1)
End Sub

Private Sub Command2_Click()
Call etoc(Text1)
End Sub

Private Sub Form_Load()
Call addcidian("测试", "test") '增加3条词典
Call addcidian("你", "you")
Call addcidian("你好吗", "How Are You")
End Sub
希望能够对你有帮助