Solved

create multiple Textbox control .....

Posted on 2003-11-18
9
414 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

820 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