Adarsh Sojitra
Adarsh Sojitra

Reputation: 2199

How to solve "Compile Error : type mismatch" error in VB6?

It seems that there are already some answers available but I can't find proper answer for my question.

Here is the code:

Private Sub Combo2_click()
Dim item_id, price As Integer
Dim item_name As String
If Combo2.Index Is 0 Then
    price = 30
ElseIf Combo2.Index Is 1 Then
    price = 40
ElseIf Combo2.Index Is 2 Then
    price = 50
ElseIf Combo2.Index Is 3 Then
    price = 60
Else
    price = 55
End If
End Sub

I am getting error as "Compile Error : Type MisMatch" ... I don't know why! It is showing error on the like Private Sub COmbo2_click() ...

Upvotes: 0

Views: 2127

Answers (1)

41686d6564
41686d6564

Reputation: 19641

There are two mistakes in your code:

1- You should use Combo2.ListIndex instead of .Index. (because index is used for something else and that's when your control is an element in an array)

2- You should replace Is with = (and that's what throws the exception of Type mismatch).

Hope that helps :)

Upvotes: 5

Related Questions