Go to GoReading for breaking news, videos, and the latest top stories in world news, business, politics, health and pop culture.

How to Check a String for Alphabet Only in VB

104 2
    • 1). Open Visual Basic 6 from the "Start" icon, located on the Windows task bar.

    • 2). Select "Standard.exe" and click "Open" to start a new Visual Basic 6 application.

    • 3). Drag the "Textbox" icon to the window labeled "Form1," creating a text box labeled "Text1."

    • 4). Drag the "CommandButton" icon to the window labeled "Form1," creating a button labeled "Command1."

    • 5). Double click on the button labeled "Command1" to open the code window. Below the line labeled "Private Sub Command1_Click()" paste the code:

      dim scompare As String

      dim icount As Integer

      For icount = 1 To Len(Text1.Text)

      scompare = Mid$(Text1.Text, icount, 1)

      Text1.Text = Mid$(Text1.Text, icount + 1, Len _ (Text1.Textt))

      If scompare Like ("[A-Z]") Or _

      scompare Like ("[a-z]") Or _

      scompare Like ("#") Then

      msgbox("Alpa characters only")

      Else

      msgbox(Non-Alphabetic characters found")

      Exit Function

      End If

      Next icount

    • 6). Press the "F5" key to execute the Visual Basic application. Type the text you wish to check in the text box. Click on the button labeled "Command1," and a message will be display verifying if the text is alphabetic or not.

Source...

Leave A Reply

Your email address will not be published.