Your cell already contains a string: "6+6+2", so calling ToString on it doesn't do anything useful.
And strings that contain equations can't be "converted" to numbers by calling CDbl - all that will do is throw an exception - which you catch - because the whole string is not a number:
Dim s As String = "6+6+2"
Dim DocNo As String
DocNo = Math.Abs(CDbl(s))
Console.WriteLine(DocNo)
Will throw an exception:
System.InvalidCastException: Conversion from string "6+6+2" to type 'Double' is not valid. ---> System.FormatException: Input string was not in a correct format.
What you need to do is evaluate the string expression as a number - this may help:
An expression evaluator written in VB.NET[
^]
Or you could use the
DataTable.Compute[
^] method:
Dim result = New DataTable().Compute("6+6+2", Nothing)
But that's not particularly efficient as you have to create a whole DataTable object to do it ...