如何利用vb编程text1“输入do”text2“输入做” 按 command1“添加记录”
text1“输入do”text2“输入做”按command1“添加记录”text1“输入do”按command2“翻译”text2“显示做”text1“输入do”按com...
text1“输入do”text2“输入做” 按 command1“添加记录”
text1“输入do”按 command2“翻译”text2“显示做”
text1“输入do”按 command3“删除记录”text1和text2的记录删除。
能否有保存记录啊,要不能保存,则没有把添加记录的效果体现出来了 展开
text1“输入do”按 command2“翻译”text2“显示做”
text1“输入do”按 command3“删除记录”text1和text2的记录删除。
能否有保存记录啊,要不能保存,则没有把添加记录的效果体现出来了 展开
2011-02-03
展开全部
简单点的,退出程序后,记录会删除,直接拷贝到窗体代码即可:
Option Explicit
Dim Col1 As New Collection
Dim Col2 As New Collection
Private Sub Command1_Click() '添加
Col1.Add Text1.Text
Col2.Add Text2.Text
End Sub
Private Sub Command2_Click() '翻译
Dim i
Text2.Text = ""
For i = 1 To Col1.Count
If Col1.Item(i) = Text1.Text Then
Text2.Text = Col2.Item(i)
Exit Sub
End If
Next i
MsgBox Text1.Text & " 还未记录!"
End Sub
Private Sub Command3_Click() '删除
Dim i
Text2.Text = ""
For i = 1 To Col1.Count
If Col1.Item(i) = Text1.Text Then
Col1.Remove (i)
Col2.Remove (i)
Text1.Text = ""
Text2.Text = ""
Exit Sub
End If
Next i
MsgBox Text1.Text & " 还未记录!"
End Sub
'如果是百八十条的话,保存到txt就可以了,如果成千上万,就要存到数据库了(建议可以找vb+access的资料看看)补充------------------------------------------
Private Sub Form_Load()
Dim str1
Dim grp() As String
If Dir(App.Path & "\trans.txt") <> "" Then
Open App.Path & "\trans.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str1
If str1 <> "" Then
grp = Split(str1, "|")
Col1.Add grp(0)
Col2.Add grp(1)
End If
Loop
Close 1
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Col1.Count > 0 Then
Dim i
Open App.Path & "\trans.txt" For Output As #1
For i = 1 To Col1.Count
Print #1, Col1.Item(i) & "|" & Col2.Item(i)
Next i
Close 1
End If
End Sub
Option Explicit
Dim Col1 As New Collection
Dim Col2 As New Collection
Private Sub Command1_Click() '添加
Col1.Add Text1.Text
Col2.Add Text2.Text
End Sub
Private Sub Command2_Click() '翻译
Dim i
Text2.Text = ""
For i = 1 To Col1.Count
If Col1.Item(i) = Text1.Text Then
Text2.Text = Col2.Item(i)
Exit Sub
End If
Next i
MsgBox Text1.Text & " 还未记录!"
End Sub
Private Sub Command3_Click() '删除
Dim i
Text2.Text = ""
For i = 1 To Col1.Count
If Col1.Item(i) = Text1.Text Then
Col1.Remove (i)
Col2.Remove (i)
Text1.Text = ""
Text2.Text = ""
Exit Sub
End If
Next i
MsgBox Text1.Text & " 还未记录!"
End Sub
'如果是百八十条的话,保存到txt就可以了,如果成千上万,就要存到数据库了(建议可以找vb+access的资料看看)补充------------------------------------------
Private Sub Form_Load()
Dim str1
Dim grp() As String
If Dir(App.Path & "\trans.txt") <> "" Then
Open App.Path & "\trans.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, str1
If str1 <> "" Then
grp = Split(str1, "|")
Col1.Add grp(0)
Col2.Add grp(1)
End If
Loop
Close 1
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Col1.Count > 0 Then
Dim i
Open App.Path & "\trans.txt" For Output As #1
For i = 1 To Col1.Count
Print #1, Col1.Item(i) & "|" & Col2.Item(i)
Next i
Close 1
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询