Results 1 to 6 of 6

Thread: Is it possible to insert variable names into similar textbox names?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    2

    Is it possible to insert variable names into similar textbox names?

    I understand the basics of programming from doing some programming in college years ago in a not so popular language (FORTRAN). Recently started toying with VB to make some excel files more useful but, I've only learned what I've needed to from the program's help so I barely know any of the fun stuff that can be done with VB.

    Enough of that, here is what I am trying to figure out:

    I am trying to fill a number of text boxes with data calculated elsewhere in the program. There are say three sets of text boxes and each set has similiar names to the others with one part different.
    For example:
    TextBoxVendor2ImpInst
    TextBoxVendor2ImpWir
    TextBoxVendor2IncWork

    Where "Vendor2" changes to "Vendor3" etc.

    Instead of setting the value for each textbox for each vendor separate times I was hoping to be able to have a procedure do it for me. My problem is I don't know how to insert a variable into a textbox name so that it can be changed from one vendor to the next.

    Sample of code I initially tried. But obviously VB looks for a text box name with Company in it and that doesn't exist. I tried a number of ways to have Company be a variable within the textbox name with zero success. Is it even possible or do I have to leave it the way I currently have it set up?

    Breakdownboxes ("Vendor1")

    Private Sub Breakdownboxes(Company)
    BreakdownForm.TextBoxCompanyImpInst.Text = 0
    BreakdownForm.TextBoxCompanyImpWir.Text = 0
    BreakdownForm.TextBoxCompanyIncWork.Text = 0
    BreakdownForm.TextBoxCompanyMFGDam.Text = 0
    BreakdownForm.TextBoxCompanyFailComp.Text = 0
    BreakdownForm.TextBoxCompanyDwgErr.Text = 0
    BreakdownForm.TextBoxCompanyDesChg.Text = 0
    BreakdownForm.TextBoxCompanyDesErr.Text = 0
    End Sub

    Thanks

  2. #2
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Is it possible to insert variable names into similar textbox names?

    Not quite clear on what you are trying to achieve, but if you are trying to change the actual text box's name then no it isn't possible. If you are just trying to populate the text box with a variable then yes it can be done.

  3. #3
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Is it possible to insert variable names into similar textbox names?

    VB Code:
    1. For i = 1 to 10
    2.      Me.Controls("Vendor" & i) = "testing"
    3. Next

    That will add "testing" into textboxes called "Vendor" & 1-10


    HTH

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    2

    Re: Is it possible to insert variable names into similar textbox names?

    I thought my question would come out confusing. Wasn't sure how to explain it. I'll try this.
    Instead of doing this to set initial values in the sets of text boxes:

    VB Code:
    1. ' Vendor1 Text Boxes
    2.   BreakdownForm.TextBoxVendor1ImpInst.Text = 0
    3.   BreakdownForm.TextBoxVendor1ImpWir.Text = 0
    4.   BreakdownForm.TextBoxVendor1IncWork.Text = 0
    5.   BreakdownForm.TextBoxVendor1MFGDam.Text = 0
    6.   BreakdownForm.TextBoxVendor1FailComp.Text = 0
    7.   BreakdownForm.TextBoxVendor1DwgErr.Text = 0
    8.   BreakdownForm.TextBoxVendor1DesChg.Text = 0
    9.   BreakdownForm.TextBoxVendor1DesErr.Text = 0
    10.    
    11.     ' Vendor2 Text Boxes
    12.     BreakdownForm.TextBoxVendor2ImpInst.Text = 0
    13.     BreakdownForm.TextBoxVendor2ImpWir.Text = 0
    14.     BreakdownForm.TextBoxVendor2IncWork.Text = 0
    15.     BreakdownForm.TextBoxVendor2MFGDam.Text = 0
    16.     BreakdownForm.TextBoxVendor2FailComp.Text = 0
    17.     BreakdownForm.TextBoxVendor2DwgErr.Text = 0
    18.     BreakdownForm.TextBoxVendor2DesChg.Text = 0
    19.     BreakdownForm.TextBoxVendor2DesErr.Text = 0
    20.  
    21.    ' Vendor3 Text Boxes etc.

    I was hoping to do something like this:
    VB Code:
    1. '  Call Breakdownboxes procedure to populate textboxes belonging to Vendor1,  '  Vendor2, etc.
    2. Breakdownboxes ("Vendor1")
    3. Breakdownboxes ("Vendor2")
    4. Breakdownboxes ("Vendor3")
    5.  
    6. Private Sub Breakdownboxes(Company)
    7.     BreakdownForm.TextBoxCompanyImpInst.Text = 0
    8.     BreakdownForm.TextBoxCompanyImpWir.Text = 0
    9.     BreakdownForm.TextBoxCompanyIncWork.Text = 0
    10.     BreakdownForm.TextBoxCompanyMFGDam.Text = 0
    11.     BreakdownForm.TextBoxCompanyFailComp.Text = 0
    12.     BreakdownForm.TextBoxCompanyDwgErr.Text = 0
    13.     BreakdownForm.TextBoxCompanyDesChg.Text = 0
    14.     BreakdownForm.TextBoxCompanyDesErr.Text = 0
    15. End Sub

    Where Vendor1 or Vendor2 etc. would replace Company in the text box name in order to represent the actual text box names I am using.

    Apologize for the confusion before.

    Hopefully this came across better.

    Thanks

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Is it possible to insert variable names into similar textbox names?

    As kfc posted...


    Code:
    public sub Breakdown(byref frmToDo as form, byval strControl as string)
    
    '---- requires 
    '----    the form to look at
    '----    the controls to update
    
    '---- Call like:
    '----    Breakdown me,"Vendor1"
    
        frm.controls("TextBox" & strControl & "ImpInst").text = 0
        frm.controls("TextBox" & strControl & "ImpWir").text = 0
    'etc.
    
    end sub

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Is it possible to insert variable names into similar textbox names?

    I'd add the third parameter (in red) below, then you can put in whatever value you want.

    Code:
    public sub Breakdown(byref frmToDo as form, byval strControl as string, byval strValue as string)
    
    '---- requires 
    '----    the form to look at
    '----    the controls to update
    
    '---- Call like:
    '----    Breakdown me,"Vendor1", "0"
    
        frm.controls("TextBox" & strControl & "ImpInst").text = strValue
        frm.controls("TextBox" & strControl & "ImpWir").text = strValue
    'etc.
    
    end sub
    Tengo mas preguntas que contestas

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