hello guys , i got a problem with string let's say:

i got a string like this :
dim Amount As string
no error Amount = 0000780080
error Amount =000060005A

the problem now is the amount contain a value A at the end of the string.
how am I suppose to identify that the string got an alpha . without changing the
dim Amount As Integer.

I wanna take out the error onto the notepad ..
I hope that it;s clear and understandable ,
please if someone could help me...

regards
coco

Dani AI

Generated

— good description of the problem. 's IsNumeric suggestion is a quick, convenient filter, but it accepts a range of numeric formats (decimal points, signs, scientific notation and culture-specific symbols). If the requirement is "only ASCII digits" (no letters at all), use a stricter test and log failures to a text file.

' strict "digits only" check and append invalid entries to a log
Dim s As String = inputValue.Trim()

If System.Text.RegularExpressions.Regex.IsMatch(s, "^\d+$") Then
    ' valid: digits only
Else
    System.IO.File.AppendAllText(logPath, s & Environment.NewLine)
End If

If the string should be converted to a numeric type after validation, use TryParse to avoid exceptions and handle range safely. Choose Int64/Decimal depending on expected magnitude/precision.

Dim parsed As Long
If Long.TryParse(s, parsed) Then
    ' parsed now contains the numeric value
Else
    System.IO.File.AppendAllText(logPath, s & Environment.NewLine)
End If

If the trailing letter might indicate hexadecimal data rather than an error, test with a hex pattern (^[0-9A-Fa-f]+$) and parse with the appropriate NumberStyles. Trim input first, log with timestamps if helpful, and pick the numeric type that covers your maximum value. See the .NET regex guide for pattern details (regular expressions), the TryParse docs for numeric conversion (Int64.TryParse), and file append behavior (File.AppendAllText).

Recommended Answers

All 2 Replies

you can use the isnumeric function like this

if IsNumeric(Amount)=True Then
error="false"
else
error="true"
end if

thank you!! i'll have a try..

coco

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.