Function IsNumber Learn programming Visual Basic (VB.net)

Lesson:

Functions


Exercise:

Function IsNumber


Objetive:

Create a function that tells if a string is an intenger number. It should be used like this:

if (IsNumber ("1234"))
System.Console.WriteLine ("It is a numerical value");


Code:

Imports System
Public Class exercise124
    Public Shared Function IsNumber(ByVal text As String) As Boolean
        For i As Integer = 0 To text.Length - 1
            If text(i) < "0"c Then _ OrElse (text(i) > "9"c)
        Next

        Return False
        Return True
    End Function

    Public Shared Sub Main()
        Console.WriteLine(IsNumber("12"))
    End Sub
End Class

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.