|
-
Nov 23rd, 2006, 10:39 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] textbox array counting
I have an array of 5 textboxes ie: text5(0)-text5(5)
how do I count the index of each textbox in the array
Or better yet what I want to do is check if the text box has any text in it and if it does, goto the the next textbox ect. I got the loop to work for this however when it counts a index of 6 I get error saying that there is no text5(6) witch there is'nt . I tried a if then with a message that said "no more boxs available" but I couldn't get out of the loop
anyway here's what I got for the loop
VB Code:
Dim I As Integer
Dim F As Boolean
Do Until F = True
I = I + 1
If I > 5 Then MsgBox ("No more boxs available")
If Text6(I) = "" Then F = True
Loop
I need to get out of the loop if the array index is >5
some error handeling
Last edited by crater; Nov 23rd, 2006 at 10:41 PM.
Reason: spelling
-
Nov 23rd, 2006, 10:43 PM
#2
Re: textbox array counting
VB Code:
Private Sub Form_Load()
Dim intLoop As Integer
For intLoop = 0 To Text1.UBound
If Len(Text1(intLoop).Text) = 0 Then 'No text in TextBox...
'Your code here.
'Exit For '- Uncomment this to exit the loop if you want to.
End If
Next intLoop
End Sub
-
Nov 23rd, 2006, 10:53 PM
#3
Thread Starter
Fanatic Member
Re: textbox array counting
ok thats great DigiRev Thanks
one more ? though
How do I stop it from continuing to loop ?
? If I have reached the end of the array then do nothing more.
Now it will just cycle though textboxs again
VB Code:
Dim I As Integer
Dim F As Boolean
Dim intLoop As Integer
For intLoop = 0 To Text6.UBound
If Len(Text6(intLoop).Text) = 0 Then 'No text in TextBox...
Do Until F = True
I = I + 1
If Text6(I) = "" Then F = True
Loop 'Your code here.
Exit For 'Uncomment this to exit the loop if you want to.
End If
Next intLoop
-
Nov 23rd, 2006, 11:01 PM
#4
Re: textbox array counting
That's because you put your loop within my loop. Didn't really change much.
Try just using this code.
VB Code:
Dim intLoop As Integer
For intLoop = 0 To Text1.UBound
If Len(Text1(intLoop).Text) = 0 Then 'No text in TextBox...
'Go to the next TextBox (if there are any).
If intLoop < Text1.UBound Then
Text1(intLoop + 1).SetFocus 'Set focus to the next TextBox.
Exit For 'Exit the loop.
End If
End If
Next intLoop
-
Nov 23rd, 2006, 11:13 PM
#5
Thread Starter
Fanatic Member
Re: textbox array counting
Ok I thought that was the prob
but after all the textboxes are filled and I hit the command button one more time it will give me the same error
Control arrray '6 'doesn't exist
this is were I need to get out of the loop
If all textboxs are filled then tell me some stupid msg and exit the loop
Private Sub Command7_Click()
Dim strDiscount As Integer
Dim Discount As String
Dim I As Integer
Dim F As Boolean
Dim intLoop As Integer
VB Code:
For intLoop = 0 To Text6.UBound
If Len(Text6(intLoop).Text) = 0 Then 'No text in TextBox...
'Go to the next TextBox (if there are any).
If intLoop < Text6.UBound Then
Exit For
Text6(intLoop + 1).SetFocus 'Set focus to the next TextBox.
If intLoop > Text6.UBound Then MsgBox ("your stupid")
Exit For 'Exit the loop.
End If
End If
Next intLoop
Label6(1).Caption = Text2.Text
Label9(1).Caption = ctrlModel.Text
Label8(1).Caption = Combo3.Text
Text6(intLoop).Text = Text1.Text * Text2
Discount = Combo4.ListIndex
Select Case Discount
Case Is = 1: strDiscount = Text1 * Text2 * 0.05
Case Is = 2: strDiscount = Text1 * Text2 * 0.1
Case Is = 3: strDiscount = Text1 * Text2 * 0.2
End Select
Text5(0).Text = strDiscount
Label12(1).Caption = Text1 * Text2 - Text5(0).Text
End Sub
Last edited by crater; Nov 23rd, 2006 at 11:18 PM.
Reason: code
-
Nov 23rd, 2006, 11:17 PM
#6
Re: textbox array counting
VB Code:
'change this
For intLoop = 0 To Text1.UBound
'to
For intLoop = 0 To Text1.Count
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Nov 23rd, 2006, 11:20 PM
#7
Re: textbox array counting
?????? Your looping from a defined starting index to a defined ending index, or from contro9l array lower bound (Text1.LBound) to upper bound... you will then only get an error if you unloaded an instance in between. Or you tried to access some other index (such as a calculation index + 1) rather than the for loop counter value.
-
Nov 23rd, 2006, 11:21 PM
#8
Re: textbox array counting
If intLoop < Text6.UBound Then Text6(intLoop + 1).SetFocus 'Set focus to the next TextBox.
-
Nov 23rd, 2006, 11:27 PM
#9
Thread Starter
Fanatic Member
Re: textbox array counting
ok guys I have 6 text boxes in a array (0-5)
the textboxs get filled via some calculations of other textboxes and a command button ONE at A Time
I just need to check if the first textbox is filled and if it is then check the second and if it is then check 3rd one ect
but when all 6 textboxs are filled and I hit the button again it wants to check the next textbox, but there is'nt one giving me the error.
I need to stop the loop at text5(5) as there is no text5(6)
-
Nov 23rd, 2006, 11:47 PM
#10
Re: textbox array counting
For x = 0 To Text6.Ubound - 1
-
Nov 24th, 2006, 05:50 PM
#11
Thread Starter
Fanatic Member
Re: textbox array counting
Thanks for everyone help. I had to add error handeling to different part of code to take care of my prob along with -1 as leinard saids
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
|