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
Historical Number
121890263
Was this topic helpful?
Document Information
Modified date:
16 June 2018
UID
swg21120992