Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

create multiple Textbox control .....

Posted on 2003-11-18
9
Medium Priority
?
420 Views
Last Modified: 2010-05-01
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







0
Comment
Question by:qfren
9 Comments
 
LVL 9

Expert Comment

by:p_sie
ID: 9776936
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
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9776995
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
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9777080
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Expert Comment

by:dbrckovi
ID: 9777114
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
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9777139
P.S. Sorry about spelling and grammar mistakes;  I was in hurry when writing comments.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9779013
0
 
LVL 8

Author Comment

by:qfren
ID: 9784799
hi:

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


q
0
 
LVL 8

Author Comment

by:qfren
ID: 9797004
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
 
LVL 11

Accepted Solution

by:
dbrckovi earned 2000 total points
ID: 9797481
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question