Receiving "Type Mismatch Error"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bxscikid
    New Member
    • Dec 2007
    • 2

    Receiving "Type Mismatch Error"

    I am using VB 6 in order to clear a listbox (lststuff) containing material entered by the user via input boxes. I am trying to utilize a command button which will clear the list for the user. When testing the program, as soon as i click on the command button I receive a "Type mismatch" error. How can I solve this?

    This is the code I am using:
    [CODE=vb]Private Sub cmdclear_Click( Index As Integer)
    Dim warning As String
    warning = InputBox("Cauti on! This will DELETE your ENTIRE list. Do you Still wish to Continue", "Be Careful")
    If warning Is "Yes" Or "Y" Then
    lstStuff.Clear
    ElseIf warning Is "No" Or "N" Then
    warning = MsgBox("Your list was not cleared", , "List not Cleared")
    Else
    warning = MsgBox("Respons e not recognized. Please Type 'Yes' Or 'No'", , "Input Error")
    End If
    End Sub [/CODE]
    Last edited by Killer42; Dec 29 '07, 12:46 PM.
  • creative1
    Contributor
    • Sep 2007
    • 274

    #2
    Try this

    If warning = "Yes" Or warning ="Y" Then

    Comment

    • VijaySofist
      New Member
      • Jun 2007
      • 107

      #3
      Originally posted by bxscikid
      I am using VB 6 in order to clear a listbox (lststuff) containing material entered by the user via input boxes. I am trying to utilize a command button which will clear the list for the user. When testing the program, as soon as i click on the command button i receive a "Type mismatch" error. How can I solve this?

      this is the code i am using:
      Code:
       Private Sub cmdclear_Click(Index As Integer)
          Dim warning As String
          warning = InputBox("Caution! This will DELETE your ENTIRE list. Do you Still wish to Continue", "Be Careful")
              If warning Is "Yes" Or "Y" Then
                  lstStuff.Clear
              ElseIf warning Is "No" Or "N" Then
                  warning = MsgBox("Your list was not cleared", , "List not Cleared")
              Else
                  warning = MsgBox("Response not recognized. Please Type 'Yes' Or 'No'", , "Input Error")
              End If
      End Sub
      Hi!

      In your coding, Why can't you use a MsgBox instead of InputBox

      Try the foolowing code in your program
      Code:
       Private Sub cmdclear_Click(Index As Integer)
          Dim warning As String
          warning = MsgBox("Caution! This will DELETE your ENTIRE list. Do you Still wish to Continue", vbInformation+vbYesNo,"Be Careful")
              If warning =vbYes Then
                  lstStuff.Clear
              Else
                  warning = MsgBox("Your list was not cleared", , "List not Cleared")
              End If
      End Sub
      All The Best

      With Regards
      Vijay. R

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        bxscikid, in case you missed it the point creative1 was making is that Is is not the correct comparison operator. You should use =.

        Comment

        Working...