Solved

create multiple Textbox control .....

Posted on 2003-11-18
9
412 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add text to end of existing text in file 16 69
Saving history changes to sub form 4 36
Best way to parse out a json string in VB6? 10 109
Protecting vb6 & .Net code Obfuscation 18 94
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

914 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now