Results 1 to 3 of 3

Thread: Creating / naming variables on the fly

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Location
    Sydney, Australia
    Posts
    1

    Creating / naming variables on the fly

    Hi there wonderful people....
    I have designed a form which contains 57 textboxs. As this form is in Access and not VB, I cannot do control arrays.. So I need to declare them individual as shown below:

    <Visual Basic>

    textbox1 = myArray(1)
    textbox2 = myArray(2)
    textbox3 = myArray(3)
    textbox4 = myArray(4)
    ...
    ...
    ...
    </Visual Basic>
    I would like to be able to this on the fly in a loop as shown below:

    </Visual Basic>
    while index < 4

    textbox<index> = myArray(index)

    Wend

    </Visual Basic>

    In php it is done by naming one variable from two or more other variables on the fly such as below:

    <PHP>

    myVariable = textbox;
    $index = 0;

    while($index < 4)
    {

    $$myVariable$index = myArray($index)
    }

    </PHP>

    I don't know if there is a way of pointing to locations, etc

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    If you set your TextBoxes up as a control array, ie txtBox(0) - txtBox(3), you can easily accomplish it like so:

    VB Code:
    1. For i = 0 to 3
    2.     txtBox(i).Text = myArray(i)
    3. Next

    To set the TextBoxes as a control array, you must specify an index in the properties window and name all the boxes with the same name (ex txtBox).
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Nevermind. I somehow missed the part where you said "I can't use a control array."

    I do not believe there is anyway to name variables on the fly, unless the scripting library works that way.

    Give me a minute to find some code...
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width