我是新手,我在VB.Net的实践考试中忙于我的Pre Prac示例
我们必须创建一个Windows窗体应用程序,其中有2个TextBoxes,2个Comboboxes和2个按钮,用于将文本框中键入的单词添加到所需的组合框中。现在当你按下按钮添加一个单词并且文本框为空时,会显示一条消息,表示它是空的,这很好,因为这很容易,当单词被添加到组合框时,单词被添加到一个arraylist,但当我输入相同的单词时,必须显示一条消息,该单词已经存在于arraylist中,但它会再次将同一个单词添加到组合框中
附件是我的代码到目前为止,我缺少什么
Public Class Form1
Dim arAnim As ArrayList = New ArrayList
Dim arVerb As ArrayList = New ArrayList
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub btnAddVerb_Click(sender As Object, e As EventArgs) Handles btnAddVerb.Click
Dim result1 As DialogResult
If txtBoxVerb.Text Is "" Then
result1 = MessageBox.Show("Please type a word", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Else
If arVerb.Contains(cmbBoxVerb) Then
result1 = MessageBox.Show("Word Exists", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Else
cmbBoxVerb.Items.Add(txtBoxVerb.Text)
arVerb.Add(cmbBoxVerb)
End If
txtBoxVerb.Clear()
End If
End Sub
End Class
答案 0 :(得分:1)
你需要这样做:
If arVerb.Contains(cmbBoxVerb) Then
而不是
{{1}}
答案 1 :(得分:0)
好的我知道了吗
这是代码,它按照我想要的方式工作
Public Class Form1
Dim arAnim As ArrayList = New ArrayList
Dim arVerb As ArrayList = New ArrayList
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub btnAddVerb_Click(sender As Object, e As EventArgs) Handles btnAddVerb.Click
Dim result1 As DialogResult
If txtBoxVerb.Text Is "" Then
result1 = MessageBox.Show("Please type a word", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Else
If arVerb.Contains(txtBoxVerb.Text) Then
result1 = MessageBox.Show("Word Exists", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Else
cmbBoxVerb.Items.Add(txtBoxVerb.Text)
arVerb.Add(txtBoxVerb.Text)
End If
txtBoxVerb.Clear()
End If
End Sub
End Class