|
-
Dec 3rd, 2002, 12:22 AM
#1
Thread Starter
Member
Clearing a Collection
How do you clear a collection consisting of labels and text boxes?
me.collection1.clear
or
Clear(collection1)
do not work. Thanks.
-
Dec 3rd, 2002, 02:11 AM
#2
Member
It is kind of odd that Collections don't have the Clear() method. Oh well, just do..
collection1 = New Collection()
-
Dec 3rd, 2002, 11:18 AM
#3
Frenzied Member
Dont gain the world and lose your soul
-
Dec 4th, 2002, 11:49 PM
#4
Thread Starter
Member
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.
Last edited by andrew104; Dec 5th, 2002 at 12:25 AM.
-
Dec 5th, 2002, 12:25 AM
#5
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
-
Dec 5th, 2002, 12:34 AM
#6
Thread Starter
Member
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.
-
Dec 5th, 2002, 01:36 AM
#7
VB Code:
Dim re As New Regex("[a-zA-Z]")
Me.Text = re.Matches(TextBox1.Text).Count
-
Dec 5th, 2002, 01:45 AM
#8
Thread Starter
Member
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.
-
Dec 5th, 2002, 01:49 AM
#9
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
-
Dec 5th, 2002, 01:52 AM
#10
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.
-
Dec 5th, 2002, 02:19 AM
#11
Thread Starter
Member
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... ?
-
Dec 5th, 2002, 02:28 AM
#12
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
-
Dec 5th, 2002, 02:29 AM
#13
Thread Starter
Member
NEVERMIND - GOT IT!
ONE MORE QUESTION! I guess they never stop. How can I disable the backspace key?
-
Dec 5th, 2002, 02:30 AM
#14
Thread Starter
Member
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
-
Dec 5th, 2002, 02:44 AM
#15
Looks fine, but you don't need the {1} unless you don't want to count 'aa' otherwise nevermind.
-
Dec 5th, 2002, 04:22 AM
#16
Registered User
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....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|