Clear Method Example

This 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 ListBox control named List1, and then press F5 and click the form.

Private 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

This example uses the Clear method to clear the Clipboard object. To try this example, paste the code into the Declarations section of a form, and then press F5 and click the form.

Private 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 = "Can't 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."
   MsgBox Msg   ' Display message.
   Picture = LoadPicture()   ' Clear picture.
End Sub