Finding out what a textbox contains

Hi there. I am currently developing a small application to tell users what grade of security their password has. Now, to do this, i need to check what the textbox contains, like signs, numbers, how many lines they are and so on. I can understand the basic syntax for it:

If Textbox1 = contains !"# %&/()= then metervalue = metervalue + 5

Well, that is what i have figured out, but i don't know the proper command to see if a textbox contains something. I know how to check if the content matches a word or a number, but i don't know how to check if the textbox contains letters, how many they are and so on. If anyone can help me on this, would it be extremely appreciated.




Answer this question

Finding out what a textbox contains

  • TheFoZ

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    If Strings.InStr(TextBox1.Text, "dog").CompareTo(0) Then MessageBox.Show("dog") Else MessageBox.Show("no dog")

    If Strings.InStr(TextBox1.Text, "cat").CompareTo(0) Then MessageBox.Show("cat") Else MessageBox.Show("no cat")

    If Strings.InStr(TextBox1.Text, "fish").CompareTo(0) Then MessageBox.Show("fish") Else MessageBox.Show("no fish")

    End Sub

    End Class

    A Hell of a lot Less Pasta (spaghetti) way More Sauce (OPP),,,, The Atkin's Way(OPP Way).... I'm starting to Get It..........


  • Ishaq

    There's another way to do it.....

    Private Sub Textbox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

    Dim ForbiddenChars As String = "!@#$%^&*()_+"

    If ForbiddenChars.Contains(e.KeyChar) Then

    'do stuff

    Else

    'do other stuff

    e.Handled = True

    End If

    End Sub



  • Curtis_more

    If you are really bored, you could possibly do it like this:
    '-------------------------------------------------------------------------------------
    Dim charArray(3), character As Char

    charArray(0) = "!"
    charArray(1) = "#"
    charArray(2) = "$"

    For Each character In charArray
    If InStr(TextBox1.Text, character) > 0 Then
    MessageBox.Show("There is a special character in the password")
    End If
    Next
    '-------------------------------------------------------------------------------------
    I'm positive that this is not the best way, but it works.

    I would say there's probably some way you could figure out a range of ASCII values for special characters and then loop through the string.tochararray array, but you would have to look into that.

  • Moishe

    Public Class Form1

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    MsgBox(TextBox1.Text)

    End Sub

    End Class


  • Mohamed B.

    you are welcome

  • cprcrack

    Hey shakalama, thanks, that helped me through it. Just need to modify some studd and fix it with the letters and stuff left (all of the boring stuff). Thanks a lot!

  • Battula

    hi,

    you can get every letter in the textbox and put it in array and loop through it and to know if its letter or number, i hope if you give a concrete example

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    MessageBox.Show("how many letters in the textbox = " + TextBox1.Text.Length.ToString())

    Dim textboxletters() As Char

    Dim singleletter As Char

    textboxletters = TextBox1.Text.ToCharArray()

    For Each singleletter In textboxletters

    If IsNumeric(singleletter) Then

    MessageBox.Show("I found a number = " + singleletter)

    Else

    MessageBox.Show("I found a letter (" + singleletter + ")")

    End If

     

    Next

    End Sub

    hope that helps



  • LesSmith

    Hmmm... all that it does now seems to be that it types the letters in the textarea onto a messagebox. Not to sound ungrateful, but what i meant was, that when a textbox contained something, like when it contains one of the letters from the alphabet, something would happen. Like, the value of a progressbar would change.


  • Finding out what a textbox contains