Skip to Content
0
Former Member
Jan 26, 2004 at 04:04 PM

matrix read out numbers only - VB.Net code sample

59 Views

Hi all,

instead of asking yet another question, I would like to publish a helpful bit of code as solution to a problem concerning the matrix item.

Problem:

When reading out specific cells containing currency values, SBO returns a string including the currency. (ie "1.000,95 EUR") This value obviously cannot be casted into a double value.

Here is a code snippet which takes care of the issue. Glad for any comments on this.

HTH Lutz Morrien

Public Class NumbersInStr

Public Shared Function AsString(ByVal StringToFilter As String) As String

' This function takes a string as input and filters out all chars

' which do not appear in the string GoodChars

' Example: Input "220,00 EUR"

' Output "220,00"

Dim intCharCount As Integer

Dim GoodChars As String

Dim strResult As String

'if using english format, replace "," by "."

GoodChars = "12345677890,"

'go through string

For intCharCount = 0 To StringToFilter.Length - 1

'if char at current location is a "good char",

' then move it to result string

If GoodChars.IndexOf(StringToFilter.Chars(intCharCount)) >= 0 Then

strResult = strResult & StringToFilter.Chars(intCharCount)

End If

Next

If strResult <> "" Then

Return strResult

Else

Return "0"

End If

End Function

Public Shared Function AsDouble(ByVal MixedString As String) As Double

Return CDbl(AsString(MixedString))

End Function

Public Shared Function AsSingle(ByVal MixedString As String) As Single

Return CSng(AsString(MixedString))

End Function

End Class