Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Indexing TB Problem


Reply
 
Thread Tools Display Modes
  #1  
Old 09-20-2005, 12:48 PM
Mystery Mystery is offline
Junior Contributor
 
Join Date: Sep 2005
Posts: 228
Default Indexing TB Problem


So i have 50 textboxes in an array... Im trying to make a textbox hidden if it has text in it, then show the next box. This is the code i have, but its not working properly.

Code:
Private Sub Command1_Click()
Dim x As Integer
If Text1(x) = "" Then
lblblah = "k"
Else
Text1(x).Visible = False
Text1(x).Text = Text1(x) + 1
Text1(x).Visible = True
End If
End Sub

Any help would be phenomenal! Thanks
Reply With Quote
  #2  
Old 09-20-2005, 12:58 PM
BobThePenguin's Avatar
BobThePenguin BobThePenguin is offline
Junior Contributor
 
Join Date: Apr 2005
Posts: 397
Default

here's an example that finds the first empty textbox and sets the focus to it and makes all the other textboxes invisible. Hopefully you can extrapolate from here what you need:

Code:
Dim I as integer dim firstEmptyBox as integer firstEmptyBox = -1 'say the array is of textboxes called text1 and the index ranges 'from 0 to 10 for i = 0 to 10 if text1(i).text = "" and firstEmptyBox = -1 then firstEmptyBox = i else text1(i).visible = false endif next i if firstEmptyBox <> -1 then text1(firstEmptyBox).setfocus else 'All boxes have text endif

Last edited by BobThePenguin; 09-20-2005 at 01:04 PM.
Reply With Quote
  #3  
Old 09-20-2005, 01:29 PM
Mystery Mystery is offline
Junior Contributor
 
Join Date: Sep 2005
Posts: 228
Default

Ok bro i got that to work, and i didnt want to ask you unless i couldnt figure it out, but i cant haha... how would i make label1 display whats in each text box starting with 0, and if a textbox is empty, go back to start point 0.

Code:
Private Sub Command2_Click()
Dim x As Integer
For x = 0 To 49
Label1 = Text1(x).Text
Next x
End Sub
i tried that looking at your first code, and couldnt get it to work. tried a few variations. thank you.
Reply With Quote
  #4  
Old 09-20-2005, 01:45 PM
BobThePenguin's Avatar
BobThePenguin BobThePenguin is offline
Junior Contributor
 
Join Date: Apr 2005
Posts: 397
Default

So you want a label to display the text in each box as you cycle through them (better put a timer in to slow it down so you can read the text in the label) and, when it gets to an empty textbox then just stop and display the text of text(0)?

Code:
Dim I as integer dim TheTextBoxIWant as integer TheTextBoxIWant = -1 for i = 0 to 49 label.caption = text(i).text 'put in a timer or something to make things readable if that is your intent if text(i).text = "" then 'or whatever stoping conditions you want TheTextBoxIWant = i label.caption = text(0).text exit for endif next i 'Now TheTextBoxIWant has the first empty textbox and label has the caption of text(0).text



Is that what you want?? I kinda doubt it is and think this may be closer:

Code:
Dim I as integer dim flag as boolean do while flag = false for i = 0 to 49 if text(i).text = "" then exit for endif label.caption = text(i).text if i = 49 then flag = true next i loop

But since that will loop endlessly if there is an empty textbox you'll need to modify it somehow.

I'm not really sure exactly what you were asking so if neither of these examples help re-phrase your question or provide more details.
Reply With Quote
  #5  
Old 09-20-2005, 01:50 PM
Mystery Mystery is offline
Junior Contributor
 
Join Date: Sep 2005
Posts: 228
Default

those look right, i havent checked them yet.. what i want is this:

The first code you gave me, is basically saving all the info in each text box, then displaying a blank textbox correct?

So now i have a command2, i want to start with the first textbox with info in it, and display that into label 1. Then once thats displayed, they click the command button again, and the second text box with info in it will be displayed in label1.. so on..
Reply With Quote
  #6  
Old 09-20-2005, 01:53 PM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Can you post some of the code you've tried? As much as we like to help here, we're not a group that just does custom code for you. We're here to help you learn.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #7  
Old 09-20-2005, 02:02 PM
BobThePenguin's Avatar
BobThePenguin BobThePenguin is offline
Junior Contributor
 
Join Date: Apr 2005
Posts: 397
Default

Quote:
Originally Posted by Mystery
The first code you gave me, is basically saving all the info in each text box
No, its not saving anything. Its just turing everything that isnt the first textbox with no text invisible. (wow, thats a lot of negatives especially if you replace invisible with not visible)


Ah, ok.

Code:
Private Sub Command2_Click() Static FirstEmptyTextBox as Integer 'static means the variable sticks around after the sub is done 'FirstEmptyBox1 = 0 Dont need this, numeric values default to 0 ' and we want to keep a running count of where we are if text1(firstEmptyTextBox).text <> "" and FirstEmptyTextBox <> 50 then 'make sure we aren't going to go off the bounds of the array '' Label1.caption = Text1(FirstEmptyBox).Text 'So far I have specified what I am doing with every object and you havent specified with any. 'Not that it matters here but it is good practice not to rely on default values 'edit: whoops, see that you did with the textboxes which is good FirstEmptyTextBox = FirstEmptyTextBox + 1 else firstEmptyTextBox = 0 'start over if this is a blank textbox endif End Sub
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->