Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

Type Mismatch error

Hello, I create a class but when I try to dyplay the MsgBox I get an Error " Type Mismatch"

it is my code
Declaration:
Class Nombre
    Public Name As String
    Public Pago As Currency
     
    Public Sub calc(x As Integer)
        Me.Pago = 9 * x
    End Sub
     
End Class ' end of the Class Nombre

on the Click event:
Sub Click(Source As Button)
   On Error Goto lblErrs
     
   Dim myNombre As New Nombre
     
   With myNombre
      myNombre.Name =  "Tarzan"
      myNombre.calc(40)                    
   End With
     Msgbox "Name: " +myNombre.Name + "Pago: "+ myNombre.Pago >>>> Here got Type Mismatch Error
     
lblErrs:
     Messagebox "An error has occurred. The error was '" & Error$ &"' code number, " & Err & ".", 0, "Error!"
     Exit Sub    
End Sub

Thank you.

Carlos



0
calucho
Asked:
calucho
  • 3
1 Solution
 
ZvonkoSystems architectCommented:
Hello Carlos,

try this:

Sub Click(Source As Button)
     On Error Goto lblErrs
     
     Dim myNombre As New Nombre
     
     With myNombre
          myNombre.Name =  "Tarzan"
          myNombre.calc(40)                    
     End With
     Msgbox "Name: " & myNombre.Name & "Pago: " & myNombre.Pago '>>>> Here got Type Mismatch Error
     Exit Sub
     
lblErrs:
     Messagebox "An error has occurred. The error was '" & Error$ &"' code number, " & Err & ".", 0, "Error!"
     Exit Sub    
End Sub

Good luck,
Zvonko

0
 
scottrmaCommented:
You have defined Pago as Currency. You need to convert it to String before it can be printed in a Messagebox:

Msgbox "Name: " + myNombre.Name + "Pago: "+ Cstr(myNombre.Pago)

Regards,

Scott
0
 
ZvonkoSystems architectCommented:
Only for reduction:

Sub Click(Source As Button)
     On Error Goto lblErrs
     
     Dim myNombre As New Nombre
     
     With myNombre
          .Name =  "Tarzan"
          .calc(40)                    
          Msgbox "Name: " & .Name & "Pago: " & .Pago
     End With
     Dim i As Integer
     Exit Sub
     
lblErrs:
     Messagebox "Line#" & Erl & ", ErrorCode:" & Err & "; Error: " & Error, 0, "Error!"
     Exit Sub    
End Sub






0
 
caluchoAuthor Commented:
Thank you amigo Zvonko.
0
 
ZvonkoSystems architectCommented:
Thank you too.

But next time please remember that regular grading is an A.
Give B only if you are dispointed.

See you,
Zvonko

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now