dcsimg
Results 1 to 7 of 7

Thread: [RESOLVED] How do I allow the user to enter a desired number of variables?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2008
    Location
    Guildford, UK
    Posts
    160

    Resolved [RESOLVED] How do I allow the user to enter a desired number of variables?

    My program analyzes a tunnel and I need the user to be able to first of all tell me how many "sections" the tunnel has, the length of each section and the height of each section. So if the user says there are 3 sections I want three boxes to appear to enter their legnth and three more for their height. How do I do this?

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,303

    Re: How do I allow the user to enter a desired number of variables?

    use a control array of textboxes, you can then create the correct number of textboxes for the number of sections
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2008
    Location
    Guildford, UK
    Posts
    160

    Re: How do I allow the user to enter a desired number of variables?

    Thanks for the quick reply, but how do I make a control array of text boxes?


  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,939

    Re: How do I allow the user to enter a desired number of variables?

    See the "Controls" section of our Classic VB FAQs (in the FAQ forum, which is shown near the top of our home page)

  5. #5
    Junior Member kasmot's Avatar
    Join Date
    Sep 2006
    Posts
    23

    Re: How do I allow the user to enter a desired number of variables?

    place a textbox on your form and copy it
    then paste it to the form...
    a message box will appear, just click "YES"
    you have a control array textbox's
    http://worldinsights.blogspot.com/

    if your problem is resolved then mark it as resolved
    then rate the member that help you...

  6. #6
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: How do I allow the user to enter a desired number of variables?

    yes, by copying you can create an array of controls as mentioned in the previous post, else try the below
    1. Set the index of the first text box to 0 (for ex. set txt1.Index = 0 'at design time)
    2. Set the second text box's name as the previous one (txt1) and set its Index to 1
    3. Continue the same for all the text boxes for which you want to be in the array (set the name as txt1 increment the index values only)
    Last edited by ganeshmoorthy; Jul 31st, 2008 at 09:33 AM.
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  7. #7
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,527

    Re: How do I allow the user to enter a desired number of variables?

    Yeah, I wouldn't use numbers in the textbox names at all.

    txtLength(3)
    txtHeight(3)

    This approach can quickly get unwieldy if you end up with a tunnel that has many sections, or you end up adding more section variables. Or both.

    You might consider treating this as a one->many table relationship with tunnels and sections, setting up the user interface accordingly. If there are very few section variables, a simple grid on the tunnel form would suffice for the section detail. If there are several variables, list the sections in some way and have each open up to its own detail form.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width