Results 1 to 11 of 11

Thread: [RESOLVED] textbox array counting

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    Resolved [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:
    1. Dim I As Integer
    2. Dim F As Boolean
    3.  
    4. Do Until F = True
    5. I = I + 1
    6. If I > 5 Then MsgBox ("No more boxs available")
    7. If Text6(I) = "" Then F = True
    8.  
    9. 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

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: textbox array counting

    VB Code:
    1. Private Sub Form_Load()
    2.     Dim intLoop As Integer
    3.    
    4.     For intLoop = 0 To Text1.UBound
    5.    
    6.         If Len(Text1(intLoop).Text) = 0 Then 'No text in TextBox...
    7.             'Your code here.
    8.             'Exit For '- Uncomment this to exit the loop if you want to.
    9.         End If
    10.        
    11.     Next intLoop
    12.    
    13. End Sub

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    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:
    1. Dim I As Integer
    2. Dim F As Boolean
    3. Dim intLoop As Integer
    4.    
    5.     For intLoop = 0 To Text6.UBound
    6.    
    7.         If Len(Text6(intLoop).Text) = 0 Then 'No text in TextBox...
    8.             Do Until F = True
    9.             I = I + 1
    10.            
    11.             If Text6(I) = "" Then F = True
    12.  
    13.             Loop 'Your code here.
    14.             Exit For  'Uncomment this to exit the loop if you want to.
    15.         End If
    16.        
    17.     Next intLoop

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    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:
    1. Dim intLoop As Integer
    2.    
    3.     For intLoop = 0 To Text1.UBound
    4.    
    5.         If Len(Text1(intLoop).Text) = 0 Then 'No text in TextBox...
    6.             'Go to the next TextBox (if there are any).
    7.             If intLoop < Text1.UBound Then
    8.                 Text1(intLoop + 1).SetFocus 'Set focus to the next TextBox.
    9.                 Exit For 'Exit the loop.
    10.             End If
    11.            
    12.         End If
    13.        
    14.     Next intLoop

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    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:
    1. For intLoop = 0 To Text6.UBound
    2.    
    3.         If Len(Text6(intLoop).Text) = 0 Then 'No text in TextBox...
    4.             'Go to the next TextBox (if there are any).
    5.             If intLoop < Text6.UBound Then
    6.             Exit For
    7.                 Text6(intLoop + 1).SetFocus 'Set focus to the next TextBox.
    8.             If intLoop > Text6.UBound Then MsgBox ("your stupid")
    9.            
    10.                 Exit For 'Exit the loop.
    11.             End If
    12.            
    13.         End If
    14.        
    15.     Next intLoop
    16.    
    17.  
    18.  
    19.  
    20.  
    21.  
    22. Label6(1).Caption = Text2.Text
    23. Label9(1).Caption = ctrlModel.Text
    24. Label8(1).Caption = Combo3.Text
    25. Text6(intLoop).Text = Text1.Text * Text2
    26.  
    27. Discount = Combo4.ListIndex
    28.  
    29. Select Case Discount
    30.  
    31. Case Is = 1: strDiscount = Text1 * Text2 * 0.05
    32. Case Is = 2: strDiscount = Text1 * Text2 * 0.1
    33. Case Is = 3: strDiscount = Text1 * Text2 * 0.2
    34.  
    35.     End Select
    36.     Text5(0).Text = strDiscount
    37. Label12(1).Caption = Text1 * Text2 - Text5(0).Text
    38.  
    39.  
    40.  
    41. End Sub
    Last edited by crater; Nov 23rd, 2006 at 11:18 PM. Reason: code

  6. #6
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: textbox array counting

    VB Code:
    1. 'change this
    2. For intLoop = 0 To Text1.UBound
    3. 'to
    4. 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.


  7. #7
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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.

  8. #8
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: textbox array counting

    If intLoop < Text6.UBound Then Text6(intLoop + 1).SetFocus 'Set focus to the next TextBox.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    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)

  10. #10
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: textbox array counting

    For x = 0 To Text6.Ubound - 1

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Posts
    606

    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
  •  



Click Here to Expand Forum to Full Width