In: Computer Science
Visual Basic program in visual studio please
Write a function that checks whether a string has a number based. Use what we learned about Asc to complete the following:
Function CheckLength (S As String) As Boolean
‘add a do loop to start at first character
‘if Ascii current character is between Asc (“0”) and Asc (“9”)
‘then we have a hit Return True
‘else check the next character
‘if loop is over, that means no hit was found Return False
End Function
Use this function in an application that allows the user to enter the string/text that should be tested by your CheckLength function.
Please submit your completed application.
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new Windows Forms Application in VB is created using Visual Studio 2017 with name "StringCheckApp".This application contains a form with name "Form1.vb".Below are the files associated with form1.
1.Form1.vb[Design]

2.Form1.cs
Public Class Form1 'VB class
'Button click
Private Sub btnCheckString_Click(sender As Object, e As EventArgs)
Handles btnCheckString.Click
'taking string entered by user
Dim s As String = txtString.Text
'call function
If (CheckLength(s)) Then
'when function return true , means string contains number
lblMessage.Text = s & " contains number"
Else
'when function return false
lblMessage.Text = s & " does not contains number"
End If
End Sub
'Function to check length
Function CheckLength(S As String) As Boolean
Dim i As Integer 'declaring variable
Dim ascii As Integer 'variable to store ascii value
Dim flag As Boolean 'variable used for flag
'using do While loop
Do While i < S.Length
'checking acii for fist character
ascii = Asc(S(i))
'checking value of ascii
If ascii >= Asc("0") And ascii <= Asc("9") Then
'if number found then
flag = True
Else
flag = False
End If
i = i + 1 'increment value of i
Loop
Return flag 'return flag
End Function
End Class
======================================================
Output : Run application using F5 and will get the screen as shown below
Screen 1 :

Screen 2:Screen when string contains number

Screen 3:When string does not contains number

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.