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







LVL 8
qfrenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

p_sieCommented:
You have to dynamically add the textboxes to the form.

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....
0
dbrckoviCommented:
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
---------------------------------------------------
0
dbrckoviCommented:
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)  <<
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

dbrckoviCommented:
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!
0
dbrckoviCommented:
P.S. Sorry about spelling and grammar mistakes;  I was in hurry when writing comments.
0
qfrenAuthor Commented:
hi:

Thanks for quick reply, i will go through that see if it helps in my situation and let u all know..


q
0
qfrenAuthor Commented:
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


0
dbrckoviCommented:
Just use regular indexes instead of gettext function.

-----------------------------
    Text1(5) = ""
    For x = 1 To 4
        Text1(5).Text = Format(Val(Text1(5).Text) + Val(Text1(x).Text))
    Next x
-----------------------------

Note that textboxes store strings, and not numbers, so you have to convert every string to a number before you can use it as number     >>     number = val(string)
To convert a number back to string use >>    string = Format (number)

Here is differently written example from above. It's more readable.

-------------------------------------------
    Dim Result As Integer
    Dim Value As Integer
   
    Result = 0
   
    For x = 1 To 4
        Value = Val(Text1(x).Text)
        Result = Result + Value
    Next x

    Text1(5).Text = Format(Result)
--------------------------------------------
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.