It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Text box loop until string entered

Moderator: dafunkymunky

Text box loop until string entered

Postby smuj56 on Wed May 11, 2011 8:40 pm

Hey folks

iv been given a task to play about with and learn how to use visual basic express.

im currently at the start and need to code a form that a user enters there name.
i need it so that if they input numbers or nothing at all it loops until some string has been put in, but i cant figure it out. iv been reading through my book and looking on the net. this name also needs the 1st letter of each name to be a capitol letter even if its entered all in lower case. can someone help me. this is my code so far for this bit.

Where i have "String" is where i want the string command, so that if user enters 2+ String then open form 2

username = txtname.Text

Do Until txtname.Text = "String"
If txtname.Text = "" Then MsgBox(" you must enter your name")
If IsNumeric(txtname.Text) Then MsgBox(" please enter letters")

Exit Do
Loop


Me.Hide()
Form2.Show()

Thanks for your help

Adam
smuj56
 
Posts: 1
Joined: Wed May 11, 2011 8:34 pm

Re: Text box loop until string entered

Postby avenger19 on Mon May 16, 2011 12:33 pm

hey man
i played around with some code and got some of your problem to work ...

Code: Select all
        Dim bool As Boolean = False
        If TextBox1.Text = "" Then
            MsgBox("no string")
        Else
            Dim oneChar As Char
            Dim firstName As String
            firstName = Trim(TextBox1.Text)
            oneChar = firstName.Chars(0)
            If Asc(oneChar) >= 48 And Asc(oneChar) <= 57 Then
                MsgBox("number begins string")
            ElseIf Asc(oneChar) >= 65 And Asc(oneChar) <= 90 Then
                bool = True
            Else
                MsgBox("first letter is not capital")
            End If
        End If
        If bool = True Then
            MsgBox("good string!")
        End If


this code first sees if there is any text ... if there isnt then it doesnt execute any of the code. then it converts the first char (or letter) of the string to ASCII code and sees if it is a number between 0 and 9 ... if it is then it tells you ... if its not then it continues on. next it converts it again and sees if it is a capital letter ... if it is then it changes the value of the boolean to true so that the next block will execute ... if its not then it will tell you. finally if the boolean equals true it will say "good string!".
you are more than welcome to use this code ... please edit it to however you need ... please let me know if it helped / worked for you. (:
--
AVenger19
Check out my youtube channel: http://www.youtube.com/user/19avenger19
avenger19
 
Posts: 3
Joined: Mon May 16, 2011 11:42 am
Location: Seoul, South Korea


Who is online

Users browsing this forum: No registered users and 1 guest