mainit123
Technical User
- Jan 24, 2005
- 25
I am trying to use the built-in VB tools rather than manually code my task of trying to tell if a string character I have trapped is or is not a member of an array.
This would seem to be a classic use of ArrayList.contains but the documentation is sparse on examples that I can go forward with. I feel I am close to a solution but need that final push.
Here is my code:
Dim badArray As Array = Array.CreateInstance(GetType(String), 4)
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Load the Bad char array,
badArray.SetValue(";", 1)
badArray.SetValue("+", 2)
badArray.SetValue("?", 3)
'Now validate
txtbx1 = TextBox1.Text
txt1cnt = Len(txtbx1)
txt1cntm1 = txt1cnt - 1
For i = 0 To txt1cntm1
For j = 1 To 3
mysub = TextBox1.Text.Substring(i, 1)
If mysub = badArray.GetValue(j) Then
Badchar = "Yes"
End If
Next j
Next i
As you can see, I am creating an array of "special" characters, like ";" , "+", and "?" so that I can alert the user when they have inadvertently typed those characters into the TextBox1. I am simply looping through each character of the captured TextBox string and comparing them against each item in my badArray.
So, I would love to see how ArrayList.Contains could automate this or not make it so manual.
Thanks in advance.
This would seem to be a classic use of ArrayList.contains but the documentation is sparse on examples that I can go forward with. I feel I am close to a solution but need that final push.
Here is my code:
Dim badArray As Array = Array.CreateInstance(GetType(String), 4)
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Load the Bad char array,
badArray.SetValue(";", 1)
badArray.SetValue("+", 2)
badArray.SetValue("?", 3)
'Now validate
txtbx1 = TextBox1.Text
txt1cnt = Len(txtbx1)
txt1cntm1 = txt1cnt - 1
For i = 0 To txt1cntm1
For j = 1 To 3
mysub = TextBox1.Text.Substring(i, 1)
If mysub = badArray.GetValue(j) Then
Badchar = "Yes"
End If
Next j
Next i
As you can see, I am creating an array of "special" characters, like ";" , "+", and "?" so that I can alert the user when they have inadvertently typed those characters into the TextBox1. I am simply looping through each character of the captured TextBox string and comparing them against each item in my badArray.
So, I would love to see how ArrayList.Contains could automate this or not make it so manual.
Thanks in advance.