|
-
Dec 3rd, 2002, 01:43 AM
#1
Thread Starter
Member
Increasing Text Number
Hi,
I have 45 text boxes on my form, I want to check each text box for all the alphabets. So I decided to make a loop in this way
n=1
do until n=45
If textn.text = "A" then
condition
end if
n=n+1
loop
but the problem is how the n of textn.text should b assigned value of n.
plz help
Thanking you,
arv1980
-
Dec 3rd, 2002, 01:55 AM
#2
Hyperactive Member
hi,.
first take array of text boxes and use this loop
n=1
do until n=45
If text(n).text = "A" then
condition
end if
n=n+1
loop
-
Dec 3rd, 2002, 02:53 AM
#3
This may help if you want to add more TextBoxes (no need to change the code):
VB Code:
Option Explicit
Private Sub Form_Load()
Dim n As Integer
For n = 1 To Text1.Count
If Text1(n).Text = "A" Then
' Your condition code here
End If
Next
End Sub
Generaly tho, Control Arrays start at 0(index). If so use:
VB Code:
Option Explicit
Private Sub Form_Load()
Dim n As Integer
For n = [b]0 To Text1.Count - 1[/b]
If Text1(n).Text = "A" Then
' Your condition code here
End If
Next
End Sub
And...... To speed things up slightly, evaluate the TextBox count once, like:
VB Code:
Option Explicit
Private Sub Form_Load()
Dim n As Integer, tcnt As Integer
[b]tcnt = Text1.Count - 1[/b]
For n = 0 To tcnt
If Text1(n).Text = "A" Then
' Your condition code here
End If
Next
End Sub
Last edited by Bruce Fox; Dec 3rd, 2002 at 02:58 AM.
-
Dec 3rd, 2002, 10:20 AM
#4
Thread Starter
Member
hi
count doesn't works. it just gives error "count" property not defined.
thanks
-
Dec 3rd, 2002, 10:27 AM
#5
Addicted Member
Are you using a load of text boxed named (eg) TextBox1, TextBox2, TextBox3, etc... or a Control array where all the textboxes have the same name (eg TextBox) but all have a unique index which diferetiates betwee them all?
The latter is the better method
If you can dream it, you can do it - Moo Power!
-
Dec 3rd, 2002, 10:28 AM
#6
Originally posted by arv1980
hi
count doesn't works. it just gives error "count" property not defined.
thanks
It works for me..... do all of your text boxes have the same name? (IE, is the control array set up correctly?)
-
Dec 3rd, 2002, 11:48 PM
#7
Thread Starter
Member
I m using different text boxes. like text1, text2...... But how about if i use one text box & then compare each character of the text.
-
Dec 3rd, 2002, 11:57 PM
#8
VB Code:
Dim ctl As Control
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
If ctl.Text = "A" Then
' condition
End If
End If
Next
-
Dec 4th, 2002, 08:09 PM
#9
Thread Starter
Member
hi,
Thanks everyone, but Martin even that doesn't works. It shows ctl as "".
-
Dec 4th, 2002, 08:21 PM
#10
Yes. If you just look at ctl it will be "", but put a breakpoint on the If ctl.Text = "A" Then line you will see that ctl.Text has a value equal to whatever is in the textbox. You can also go to the Immediate screen and type ?ctl.Name and it will display the name of the textbox.
-
Dec 4th, 2002, 08:53 PM
#11
Hyperactive Member
Originally posted by MartinLiss
VB Code:
Dim ctl As Control
For Each ctl In Controls
If TypeOf ctl Is TextBox Then
If ctl.Text = "A" Then
' condition
End If
End If
Next
This should work for you make sure you are using the right way.
Get some more info about it on Google.com or search the MSDN Website for more info on For Each Control
-
Dec 4th, 2002, 11:57 PM
#12
Conquistador
I want to check each text box for all the alphabets.
It seems as though you're only checking for "A"?
-
Dec 7th, 2002, 01:50 AM
#13
Thread Starter
Member
no it doesn't works. any other option.
-
Dec 7th, 2002, 10:47 AM
#14
Please post your code that you say doesn't work, because it will if it's done correctly.
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
|