See Also Syntax 1 Example Syntax 2 Example
Clears the contents of a list box or combo box. Alternatively, clears the contents of the operating environment Clipboard.
Syntax 1
control.Clear
Syntax 2
Clipboard.Clear
Remarks
In Syntax 1, control may either be a list box or a combo box. In Syntax 2, only the special Clipboard object is allowed.
AddItem Method
Clipboard Object
RemoveItem Method
Clear Method - Syntax 1 Example
The example uses the Clear method to clear all items from a list box. To try this example, paste the code into the Declarations section of a form with a list box control named List1. Then press F5 and click the form.
Sub Form_Click ()
Dim Entry, I, Msg ' Declare variables
Msg = "Choose OK to add 100 items to your list box."
MsgBox Msg ' Display message.
For I = 1 To 100 ' Count from 1 to 100.
Entry = "Entry " & I ' Create entry.
List1.AddItem Entry ' Add the entry.
Next I
Msg = "Choose OK to remove every other entry."
MsgBox Msg ' Display message.
For I = 1 To 50 ' Determine how to
List1.RemoveItem I ' remove every other
Next I ' item.
Msg = "Choose OK to remove all items from the list box."
MsgBox Msg ' Display message.
List1.Clear ' Clear list box.
End Sub
Clear Method - Syntax 2 Example
The example uses the Clear method to clear the Clipboard. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Const CF_BITMAP = 2 ' Define bitmap format.
Dim Msg ' Declare variable.
On Error Resume Next ' Set up error handling.
Msg = "Choose OK to load a bitmap onto the Clipboard."
MsgBox Msg ' Display message.
Clipboard.Clear ' Clear Clipboard.
Clipboard.SetData LoadPicture("PAPER.BMP") ' Get bitmap.
If Err Then
Msg = "Could not find the .BMP file."
MsgBox Msg ' Display error message.
Exit Sub
End If
Msg = "A bitmap is now on the Clipboard. Choose OK to copy "
Msg = Msg & "the bitmap from the Clipboard to the form."
MsgBox Msg ' Display message.
Picture = Clipboard.GetData() ' Copy from Clipboard.
Msg = "Choose OK to clear the picture box."
MsgBox Msg ' Display message.
Picture = LoadPicture() ' Clear picture box.
End Sub