IBM Support

Converting a numeric string causes type mismatch error

Troubleshooting


Problem

A type mismatch error occurs when converting a numeric string with a comma (for example, 1,234.32) to a number: Runtime error '13' - Module ScriptName, Line LineNumber Type mismatch error

Cause

The CDbl, CInt, CLng & CSng commands cannot convert a string that uses a
comma as the thousand separator character.

Resolving The Problem

Strip the commas from the numeric string and convert the comma-free numeric string.

Here is a sample script:

Sub Main

Dim Result As Integer

Dim StringNumber As String
Dim SecondStringNumber As String
Dim TempString As String
Dim LengthStringNumber As Integer
Dim x As Integer
Dim Number As Double

StringNumber = "2,141,500.32"

LengthStringNumber = Len(StringNumber)

x = 1

'Creates a new numeric string without commas
Do While x <= LengthStringNumber
TempString = Mid(StringNumber, x, 1)
If TempString <> "," Then
SecondStringNumber = SecondStringNumber & TempString
End If
x = x + 1
Loop

'Converts the new string to a number
Number = CDbl(SecondStringNumber)

End Sub





[{"Product":{"code":"SSSHDX","label":"Rational Robot"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"--","Platform":[{"code":"PF033","label":"Windows"}],"Version":"2002;2002.05.00;2002 Release 2;2002.05.20;2003;2003.06.00;2003.06.12;2003.06.13","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Historical Number

121890263

Document Information

More support for:
Rational Robot

Software version:
2002, 2002.05.00, 2002 Release 2, 2002.05.20, 2003, 2003.06.00, 2003.06.12, 2003.06.13

Operating system(s):
Windows

Document number:
74109

Modified date:
16 June 2018

UID

swg21120992