gpt4 book ai didi

vba - 如何检查组合框列表中是否已存在数据?

转载 作者:行者123 更新时间:2023-12-04 13:51:02 28 4
gpt4 key购买 nike

如何检查cmbTypeYacht.text中是否已经存在cmbTypeYacht.list中的数据?

这是我得到的:

Dim TypeYacht As String 'Type of yacht input

TypeYacht = cmbTypeYacht.Text

If TypeYacht = ("cmbTypeYacht list") Then
MsgBox "Type of Yacht is already on the list", vbExclamation, "Yacht Chantering"
Else
cmbTypeYacht.AddItem cmbTypeYacht.Text

With cmbTypeYacht
.Text = ""
.SetFocus
End With
End If

对标签感到抱歉,我不太确定是哪个标签,而是使用Microsoft Visual Basic应用程序。

最佳答案

ComboBox类有一个FindStringExact()方法,它将为您解决问题,如下所示:

Dim resultIndex As Integer = -1

resultIndex = cmbTypeYacht.FindStringExact(cmbTypeYacht.Text)

If resultIndex > -1 Then
' Found text, do something here
MessageBox.Show("Found It")
Else
' Did not find text, do something here
MessageBox.Show("Did Not Find It")
End If

您也可以像这样循环遍历列表:
Dim i As Integer = 0
For i = 0 To cmbTypeYacht.Items.Count - 1
If cmbTypeYacht.Items.Contains(cmbTypeYacht.Text) Then
MessageBox.Show("Found It")
Exit For
End If
Next

关于vba - 如何检查组合框列表中是否已存在数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19308611/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com