By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,058 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,058 IT Pros & Developers. It's quick & easy.

Receiving "Type Mismatch Error"

P: 2
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:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdclear_Click(Index As Integer)
  2.     Dim warning As String
  3.     warning = InputBox("Caution! This will DELETE your ENTIRE list. Do you Still wish to Continue", "Be Careful")
  4.     If warning Is "Yes" Or "Y" Then
  5.         lstStuff.Clear
  6.     ElseIf warning Is "No" Or "N" Then
  7.         warning = MsgBox("Your list was not cleared", , "List not Cleared")
  8.     Else
  9.         warning = MsgBox("Response not recognized. Please Type 'Yes' Or 'No'", , "Input Error")
  10.     End If
  11. End Sub 
Dec 28 '07 #1
Share this Question
Share on Google+
3 Replies


100+
P: 274
Try this

If warning = "Yes" Or warning ="Y" Then
Dec 29 '07 #2

VijaySofist
100+
P: 107
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:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub cmdclear_Click(Index As Integer)
  2.     Dim warning As String
  3.     warning = InputBox("Caution! This will DELETE your ENTIRE list. Do you Still wish to Continue", "Be Careful")
  4.         If warning Is "Yes" Or "Y" Then
  5.             lstStuff.Clear
  6.         ElseIf warning Is "No" Or "N" Then
  7.             warning = MsgBox("Your list was not cleared", , "List not Cleared")
  8.         Else
  9.             warning = MsgBox("Response not recognized. Please Type 'Yes' Or 'No'", , "Input Error")
  10.         End If
  11. End Sub 
Hi!

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

Try the foolowing code in your program
Expand|Select|Wrap|Line Numbers
  1.  Private Sub cmdclear_Click(Index As Integer)
  2.     Dim warning As String
  3.     warning = MsgBox("Caution! This will DELETE your ENTIRE list. Do you Still wish to Continue", vbInformation+vbYesNo,"Be Careful")
  4.         If warning =vbYes Then
  5.             lstStuff.Clear
  6.         Else
  7.             warning = MsgBox("Your list was not cleared", , "List not Cleared")
  8.         End If
  9. End Sub
All The Best

With Regards
Vijay. R
Dec 29 '07 #3

Expert 5K+
P: 8,434
bxscikid, in case you missed it the point creative1 was making is that Is is not the correct comparison operator. You should use =.
Dec 29 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.