Home > Software engineering >  Combox. List as an array in a Filter function, error "type mismatch"
Combox. List as an array in a Filter function, error "type mismatch"

Time:09-18

If Ubound (Filter (droplist. List, "renamed", True)))=1 then
Msgbox "rename option does not exist"
Droplist. Additem "renamed"

Is a combox droplist.

The purpose is to realize, when combox. When there is no "renamed" list, add a "renamed" option,

Run times "type mismatch".

CodePudding user response:

This problem can be converted to:
Array can be assigned to Combox list, in turn, Combox. Assigned to the array list?

CodePudding user response:

The error message is so clear
In the wrong place a breakpoint, the debug print see combox. The list is what data type, and then look at the three parameters of the Filter () were asked what type,
If yes, what was in the Filter () returns the data type, whether ubound () required input type,

CodePudding user response:

All commented On the Error Resume Next statement, running in the VBA IDE,
The error and then click the debugging, the cursor will stop error in the statement,
Or
In doubt may have a logical error statements in advance to set breakpoints, run through the breakpoint interrupt,

At this point can be used in the immediate window
? The variable name
Or
? The function name () function parameter
Or
Process (parameters)
Auxiliary debugging,

CodePudding user response:

For I=0 To droplist. ListCount - 1
If droplist. List (I)="renamed" Then Exit the For
Next I

If I=droplist. ListCount Then
Msgbox "rename option does not exist"
Droplist. AddItem "renamed"
End If

CodePudding user response:

The practice of using the API:
 Private Declare Function SendMessagebyString Lib _ 
"User32" Alias "SendMessageA" (ByVal hWND As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long As String)

Private Const CB_FINDSTRINGEXACT=& amp; H158

If SendMessagebyString (droplist. HWnd CB_FINDSTRINGEXACT, 1, "renamed")=1 Then
Msgbox "rename option does not exist"
Droplist. Additem "renamed"
End the If
  •  Tags:  
  • VBA
  • Related