Runtime error '13': Incompatible types

Asked

Viewed 613 times

0

I use a spreadsheet system in the service that we created at the time we used Windows 7. Then computers were upgraded to windows 10, due to the discontinuation of 7. It was created from excel from office 2000. After the last update of windows 10, every time I tell them to update themselves in the matrix, they present the title message. Even before that, there was never any trouble with them.

The subroutine that Microsoft Visual Basic is now displaying "defect" is this:

Function FormataProcesso(NI)

Dim novoNi As String

    **novoNi = CStr(CDec(NI))**    <====

'------- primeiro completa com zeros para formatar como CNPJ ----

    novoNi = MaskOut(novoNi)

    If Len(novoNi) <= 15 Then Tamanho = 15 Else Tamanho = 17

    While (Len(novoNi) < Tamanho)

        novoNi = "0" & novoNi

    Wend

NI is the number of CNPJ, which appears pure in the spreadsheet, without . or - When debugging, the module highlights the line with the arrow as "defective".

Has anyone ever solved this kind of defect?

1 answer

0

Everything indicates that the problem is not in the migration of the operating system, but in the origin of the data that the macro is performing the reading.

If the Cdec function is provided with a text string that cannot be converted to a numerical value, it returns the error.

See these two examples, with the first normal wheel and the second error '13':

1st Example

Sub exemplo1()

Dim dec1 As Variant
dec1 = CDec("1,001.000001")
MsgBox (dec1)

End Sub

2nd Example

Sub exemplo2()

Dim dec1 As Variant
dec1 = CDec("1,001.0000/1")
MsgBox (dec1)

End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.