How do you clear a collection consisting of labels and text boxes?
me.collection1.clear
or
Clear(collection1)
do not work. Thanks.
Printable View
How do you clear a collection consisting of labels and text boxes?
me.collection1.clear
or
Clear(collection1)
do not work. Thanks.
It is kind of odd that Collections don't have the Clear() method. Oh well, just do..
collection1 = New Collection()
:)
Maybe this will work
Code:Collection = null;
Ok, I STILL cannot get the stupid clear collection thing. Here is exactly what I need to do.
When the user clicks the ClearButton,
The InputTextBox should clear along with all of the display labels
The focus should return to the InputTextBox and
The ClearLabel should be disabled.
The Clear Routine must be written using collections and a For/Each loop.
To do this, create a collection of all display labels and use the loop to clear them.
You can always just loop through:
VB Code:
'_Col is the collection Public Sub Clear() Dim cnt As Integer Dim cntMax As Integer cntMax = _Col.Count For cnt = cntMax To 1 Step -1 _Col.Remove(cnt) Next End Sub
YES! that worked wonderfully. Thank you very much. I have a question for you then.... I've finally got the program complete except for probably the easiest part - count the total number of characters (alpha, A-Z) entered in the text box. I've had a lot of suggestions, but they either don't work, or I don' t understand them. Thanks for the help.
VB Code:
Dim re As New Regex("[a-zA-Z]") Me.Text = re.Matches(TextBox1.Text).Count
I don't understand your code at all Edneeis. It doesn't work either. It says "regex", whatever that is is not a defined type. And "Me.type" is invalid as well.
Sorry I forgot the imports:
Imports System.Text.RegularExpressions
Or use this code instead:
Dim re As New System.Text.RegularExpressions.Regex("[a-zA-Z]")
Me.Text = re.Matches(TextBox1.Text).Count
Where is Me.Type?
Its Me.TEXT
Regex is a class that does all sorts of string functions and matching. There I am having it search for all characters A-Z both lower and upper case. The Me.Text bit just puts the character count in the form caption. You'll need to do whatever you want with it, but re.Matches(TextBox1.Text).Count will return the count and of course instead of textbox1 you'll have to put the string you want to count the characters from.
The Regex class is kind of a strange one but its very powerful.
Aha! I finally understand it. Sorry for being so stupid. One more question though... how can I make it detect both cases? I see you have done it for all characters (A-Z), but how do I do that for just "a" and "st", etc... ?
You aren't stupid just learning something new. To find other characters or set of characters just declare a new regex and pass in the characters you want to find. If it is a list of characters then put it in [] otherwise don't.
So Regex("[st]") will find any s in the source and any t as individual charactes.
Or Regex("st") will find any 'st' in the source as a set of characters together. It uses the literal.
VB Code:
Dim re As New Regex("a") Me.Text = re.Matches(TextBox1.Text).Count re = New Regex("st") Me.Text &= " " & re.Matches(TextBox1.Text).Count
NEVERMIND - GOT IT!
ONE MORE QUESTION! I guess they never stop. How can I disable the backspace key?
Here's what I've done for it to count upper and lower. I hope this is correct? It seems to work ok...
VB Code:
'count the number of times a is typed Dim acount As New System.Text.RegularExpressions.Regex("[aA]{1}") ACountLabel.Text = acount.Matches(InputTextBox.Text).Count
Looks fine, but you don't need the {1} unless you don't want to count 'aa' otherwise nevermind.
The only way I can see to "disable" the backspace key is to set KeyPreview of the form to true and then catch the KeyPress event of the control and each time check if it is the backspace key that is pressed. If it is you set the e.Handled to true and the control will not recieve the backspace.
I think the keycode for backspace is 8....