Results 1 to 11 of 11

Thread: Creating a text box array on the fly

  1. #1

    Thread Starter
    New Member RickoniX's Avatar
    Join Date
    Mar 2002
    Posts
    15

    Question Creating a text box array on the fly

    I am trying to make something that needs to add and delete text boxes, rectangles, and lines on the fly with buttons, is there a way to create, delete, and check if any are missing on the fly?

    (Also, is there a way to send to back/bring to front through code?)

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Creating a text box array on the fly

    Originally posted by RickoniX
    (Also, is there a way to send to back/bring to front through code?)
    Search for ZOrder


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    To add textboxes on the fly, you first need to know how many text boxes you need. For this example, we'll use 9 of them. I am assuming you want them to be arranged in two different columns.

    First, you draw your first textbox and make it whatever size you want. We'll use that as the basis for the size and position of the others. You then use a loop to create the array. In this example, we'll call the array txtTextBox, and draw each textbox 25 twips down from the one before it.

    Next, put in the following code:

    VB Code:
    1. Dim i As Integer
    2. For i = 1 To 8 'We already made the first one, so we only need to make 8 more.  Also, the first one has already been given an Index of 0, so theres no need to start at 0.
    3.     Load txtTextBox(i) 'This creates a new element in the array.
    4.     txtTextBox(i).Top = txtTextBox(i - 1).Top + txtTextBox(0).Height + 25 'This sets the position of each textbox.  You can experiment with this setting and see what works best for you.
    5.     txtTextBox(i).Visible = True
    6. Next i

    For the second column, we create a textbox with a different name (txtTextBox1 in this example) and do the same thing with each element of txtTextBox1. To remove them, all we have to do is find the Index of the textbox we want to delete, and set its visible property to False.

    If you have any further questions, don't hesitate to ask me.

  4. #4

    Thread Starter
    New Member RickoniX's Avatar
    Join Date
    Mar 2002
    Posts
    15
    Can that be used multiple times on one box? Like with a button that adds one each time?

    And also, could you remove them/tell which ones have still been removed?

  5. #5
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    Can that be used multiple times on one box? Like with a button that adds one each time?
    Of course it can. Just change the loop accordingly.

    And also, could you remove them/tell which ones have still been removed?
    You cannot completely remove any elements, but you can change their Visible properties to False, and it will have the same effect. Completely removing elements of a control array will cause an 'Element not found' error when you try to loop through it. As for determining which ones have been removed you could go like this:

    VB Code:
    1. For i = 0 To txtTextBox.Count
    2.     If txtTextBox(i).Visible = False Then
    3.         MsgBox "This textbox doesn't exist."
    4.     Else
    5.         MsgBox "This textbox exists."
    6.     End If
    7. Next i

    And it will achieve the effect you're looking for.

  6. #6
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    Originally posted by RickoniX
    Can that be used multiple times on one box? Like with a button that adds one each time?

    And also, could you remove them/tell which ones have still been removed?
    Removing them is easy . . .

    VB Code:
    1. 'example
    2. Unload Text1(5)

    There is no way to tell if a member of an array of controls is loaded, except to reference the control. If you reference the control, and it isn't loaded, it will generate an error. You can use this to test if the object is loaded . . .

    VB Code:
    1. Private Function IsLoaded(tBox As TextBox) As Boolean
    2.     Dim strTemp As String
    3.    
    4.     IsLoaded = True
    5.     On Error GoTo ErrHandler
    6.     strTemp = tBox.Text
    7.    
    8. Exit Function
    9. ErrHandler:
    10.     'referencing the object failed
    11.     'so it isn't loaded
    12.     IsLoaded = False
    13. End Function
    14.  
    15. 'Usage . . .
    16. Private Sub Command2_Click()
    17.     MsgBox IsLoaded(Text1(6))
    18. End Sub
    "Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!

    Resistance is futile, you will be compiled . . . Please!

  7. #7
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    Cute kid.

  8. #8
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    Originally posted by hothead
    Cute kid.
    Thanks HotHead!

    He just came in to my room and yelled at me and grabbed his talking SpongeBob that was laying next to me. Apparently he thought I took it, and that could have meant my demise!!
    "Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!

    Resistance is futile, you will be compiled . . . Please!

  9. #9
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    LOL! My cousin's kid is the same way. He's 2 years old and kinda looks like BamBam from the Flintstones movie. I just met him last week at my grandma's burial service. She wanted to be cremated and buried up north.

  10. #10
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    Were you up in my neck of the woods?

    Where are you from in Missouri? I grew up in St. Louis, went to school in Rolla, partied in Springfield (who didn't!) . . .
    "Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!

    Resistance is futile, you will be compiled . . . Please!

  11. #11
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    No, my family lives in Carleton Michigan. I'm in Buckhorn Missouri right now, but I'm planning to go to UMR soon. I do most of my partying at a bar in St. Robert, and sometimes at home.

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