|
-
Jul 13th, 2003, 04:37 PM
#1
Thread Starter
New Member
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?)
-
Jul 13th, 2003, 05:58 PM
#2
-
Jul 13th, 2003, 06:18 PM
#3
Fanatic Member
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:
Dim i As Integer
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.
Load txtTextBox(i) 'This creates a new element in the array.
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.
txtTextBox(i).Visible = True
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.
-
Jul 13th, 2003, 08:38 PM
#4
Thread Starter
New Member
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?
-
Jul 13th, 2003, 08:49 PM
#5
Fanatic Member
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:
For i = 0 To txtTextBox.Count
If txtTextBox(i).Visible = False Then
MsgBox "This textbox doesn't exist."
Else
MsgBox "This textbox exists."
End If
Next i
And it will achieve the effect you're looking for.
-
Jul 13th, 2003, 08:50 PM
#6
Fanatic Member
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 . . .
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:
Private Function IsLoaded(tBox As TextBox) As Boolean
Dim strTemp As String
IsLoaded = True
On Error GoTo ErrHandler
strTemp = tBox.Text
Exit Function
ErrHandler:
'referencing the object failed
'so it isn't loaded
IsLoaded = False
End Function
'Usage . . .
Private Sub Command2_Click()
MsgBox IsLoaded(Text1(6))
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!
-
Jul 13th, 2003, 08:54 PM
#7
-
Jul 13th, 2003, 08:56 PM
#8
Fanatic Member
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!
-
Jul 13th, 2003, 08:59 PM
#9
Fanatic Member
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.
-
Jul 13th, 2003, 09:08 PM
#10
Fanatic Member
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!
-
Jul 13th, 2003, 09:16 PM
#11
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|