The purpose of writing this article is to share my knowledge with others. In this article, I have written the code for checking the alphabets.
Though this is very basic level code but sometimes we need to include this type of code, in our applications. We can use this code where the entries should be in alphabets like ‘First Name’, ‘Last Name’, etc.
The variable is passed as “C_S” as a parameter to the function named “Check_Alphabets”. There are two variables in the function:
Var_Loop is for the looping purpose whereas Var_Len contains the length of “C_S”. Next, the contents in the C_S are being converted to small case by using the LCase function. Next each character in the C_S is being checked in the “For Next” loop. If any character in C_S is not in the range of 97 – 122 ASCII characters then the function returns false. 97 is the ASCII of ‘a’ whereas 122 is the ASCII of ‘z’. If all the characters are in the range of 97 – 122 ASCII characters then the function returns true.
Note: Please download source file for proper functioning of the code.
Sub Btn_Submit_OnClick(Sender As Object, E As EventArgs)
Dim Var_Txt_Text As String
Var_Txt_Text = Trim(Txt_Text.Text)
If Var_Txt_Text = "" Then
Lbl_Message.Text = "Please enter something in the text box."
ElseIf Check_Alphabets(Var_Txt_Text) = True Then
Lbl_Message.Text = "Congratulations! Input is in alphabets."
Lbl_Message.Text = "Sorry! Input is not in alphabets."
Dim Var_Loop, Var_Len
Var_Len = Len(C_S)
C_S = LCase(C_S)
For Var_Loop = 1 To Var_Len
If Mid(C_S, Var_Loop, 1) < Chr(97) Or Mid(C_S, Var_Loop, 1) > Chr(122) Then