qfren
asked on
create multiple Textbox control .....
hi:
1)
Let say in a form, i get 2 input value from user ..i and J...
So, with both value, i need to create the text box control in a form
If the user key in i=3 and j=4, after i click "OK"
here is the layout of the text box i want..
TEXTBOX TEXTBOX "empty"
TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX
*empty means no text box at that place
if the user key in i=5, j=8 then click OK,
TEXTBOX TEXTBOX TEXTBOX TEXTBOX "empty"
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
*empty means no text box at that place
How to do this with array?or any others way?
q
1)
Let say in a form, i get 2 input value from user ..i and J...
So, with both value, i need to create the text box control in a form
If the user key in i=3 and j=4, after i click "OK"
here is the layout of the text box i want..
TEXTBOX TEXTBOX "empty"
TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX
*empty means no text box at that place
if the user key in i=5, j=8 then click OK,
TEXTBOX TEXTBOX TEXTBOX TEXTBOX "empty"
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
TEXTBOX TEXTBOX TEXTBOX TEXTBOX TEXTBOX
*empty means no text box at that place
How to do this with array?or any others way?
q
On an empty form create 3 textboxes.
To text1, change index property to 0.
Rename text2, and text3 to i and j. (They will be used for user input)
Create command button and paste this code into it.
-------------------------- ---------- ---------- ---------- -------
Private Sub Command1_Click()
cols = Val(i.text)
rows = Val(j.text)
a = 0
For x = 1 To rows
For y = 1 To cols
a = a + 1
Load text1(a)
text1(a).Left = y * text1(a).Width + 50
text1(a).Top = x * text1(a).Height + 50
If x = 1 And y = cols Then
Else
text1(a).Visible = True
End If
Next y
Next x
End Sub
-------------------------- ---------- ---------- -----
To text1, change index property to 0.
Rename text2, and text3 to i and j. (They will be used for user input)
Create command button and paste this code into it.
--------------------------
Private Sub Command1_Click()
cols = Val(i.text)
rows = Val(j.text)
a = 0
For x = 1 To rows
For y = 1 To cols
a = a + 1
Load text1(a)
text1(a).Left = y * text1(a).Width + 50
text1(a).Top = x * text1(a).Height + 50
If x = 1 And y = cols Then
Else
text1(a).Visible = True
End If
Next y
Next x
End Sub
--------------------------
If you have noticed every textbox as one array dimension, and if you wish to retrieve a text which is in the particular coordinate, then use this sub:
Example: >> call gettext(2,3) << will display the text at 2nd column and 3rd row
-------------------------- ---------- ---------- ---------- ------- To Declarations section of a form1 (That way cols and rows variables will be visible to gettext Sub)
Dim cols As Integer
Dim rows As Integer
-------------------------- ---------- ---------- ---------- -------
Sub gettext(col As Integer, row As Integer)
If row = 1 And col = cols Then
MsgBox "That textbox is not availabe"
Else
Index = row * cols - (cols - col)
MsgBox Text1(Index)
End If
End Sub
-------------------------- ---------- ---------- ---------- -------
Or you can design it as function like this:
-------------------------- ---------- ---------- ---------- -------
Function gettext(col As Integer, row As Integer) As String
If row = 1 And col = cols Then
MsgBox "That textbox is not availabe"
gettext = "-1"
Else
Index = row * cols - (cols - col)
gettext = Text1(Index)
End If
End Function
-------------------------- ---------- ---------- ---------- --------
Example: >> print gettext (3,2) <<
Example: >> call gettext(2,3) << will display the text at 2nd column and 3rd row
--------------------------
Dim cols As Integer
Dim rows As Integer
--------------------------
Sub gettext(col As Integer, row As Integer)
If row = 1 And col = cols Then
MsgBox "That textbox is not availabe"
Else
Index = row * cols - (cols - col)
MsgBox Text1(Index)
End If
End Sub
--------------------------
Or you can design it as function like this:
--------------------------
Function gettext(col As Integer, row As Integer) As String
If row = 1 And col = cols Then
MsgBox "That textbox is not availabe"
gettext = "-1"
Else
Index = row * cols - (cols - col)
gettext = Text1(Index)
End If
End Function
--------------------------
Example: >> print gettext (3,2) <<
Another thing:
If you have to create this 'Table' of textboxes several more than once then change Command1_Click to this:
-------------------------- ---------- ---------- ----------
Private Sub Command1_Click()
If cols > 0 Or rows > 0 Then
a = rows * cols
For x = 1 To a
Unload Text1(x)
Next x
End If
cols = Val(i.text)
rows = Val(j.text)
a = 0
For x = 1 To rows
For y = 1 To cols
a = a + 1
Load Text1(a)
Text1(a).Left = y * Text1(a).Width + 50
Text1(a).Top = x * Text1(a).Height + 50
Text1(a).text = a
If x = 1 And y = cols Then
Else
Text1(a).Visible = True
End If
Next y
Next x
End Sub
-------------------------- ---------- ---------- -------
Now it will unload previously created textboxes, before attempting to create new ones.
If you need more help, just ask!
If you have to create this 'Table' of textboxes several more than once then change Command1_Click to this:
--------------------------
Private Sub Command1_Click()
If cols > 0 Or rows > 0 Then
a = rows * cols
For x = 1 To a
Unload Text1(x)
Next x
End If
cols = Val(i.text)
rows = Val(j.text)
a = 0
For x = 1 To rows
For y = 1 To cols
a = a + 1
Load Text1(a)
Text1(a).Left = y * Text1(a).Width + 50
Text1(a).Top = x * Text1(a).Height + 50
Text1(a).text = a
If x = 1 And y = cols Then
Else
Text1(a).Visible = True
End If
Next y
Next x
End Sub
--------------------------
Now it will unload previously created textboxes, before attempting to create new ones.
If you need more help, just ask!
P.S. Sorry about spelling and grammar mistakes; I was in hurry when writing comments.
ASKER
hi:
Thanks for quick reply, i will go through that see if it helps in my situation and let u all know..
q
Thanks for quick reply, i will go through that see if it helps in my situation and let u all know..
q
ASKER
hi dbrckovi :
i can create the control as ur coding above...its works..
BUT...i cant get the correct value of the text box...
Now,
TEXTBOX1 TEXTBOX2 TEXTBOX3 TEXTBOX4 TEXTBOX5
So,after user create the textbox and key in a value of each of the text box and click "Compute".......i wanna the value of TEXTBOX5 get from the fomula below...
Let say,
TEXTBOX5 = TEXTBOX1 + TEXTBOX2 +TEXTBOX3+TEXTBOX4
How?
q
i can create the control as ur coding above...its works..
BUT...i cant get the correct value of the text box...
Now,
TEXTBOX1 TEXTBOX2 TEXTBOX3 TEXTBOX4 TEXTBOX5
So,after user create the textbox and key in a value of each of the text box and click "Compute".......i wanna the value of TEXTBOX5 get from the fomula below...
Let say,
TEXTBOX5 = TEXTBOX1 + TEXTBOX2 +TEXTBOX3+TEXTBOX4
How?
q
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Create one textbox on the form and name it txt and set its index property to 0, this way you created an array of the textboxes with only one
member.
now use
Load txt(newIndex)
Where you have to icrement the newindex starting from number 1, because 0 already exists.
Now position the textbox, using txt(newindex).left and .top
the rest is easy....