|
-
Jul 28th, 2005, 12:19 PM
#1
Thread Starter
New Member
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
-
Jul 28th, 2005, 02:34 PM
#2
Frenzied Member
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.
-
Jul 28th, 2005, 02:50 PM
#3
Re: Is it possible to insert variable names into similar textbox names?
VB Code:
For i = 1 to 10
Me.Controls("Vendor" & i) = "testing"
Next
That will add "testing" into textboxes called "Vendor" & 1-10
HTH
-
Jul 28th, 2005, 03:46 PM
#4
Thread Starter
New Member
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:
' Vendor1 Text Boxes
BreakdownForm.TextBoxVendor1ImpInst.Text = 0
BreakdownForm.TextBoxVendor1ImpWir.Text = 0
BreakdownForm.TextBoxVendor1IncWork.Text = 0
BreakdownForm.TextBoxVendor1MFGDam.Text = 0
BreakdownForm.TextBoxVendor1FailComp.Text = 0
BreakdownForm.TextBoxVendor1DwgErr.Text = 0
BreakdownForm.TextBoxVendor1DesChg.Text = 0
BreakdownForm.TextBoxVendor1DesErr.Text = 0
' Vendor2 Text Boxes
BreakdownForm.TextBoxVendor2ImpInst.Text = 0
BreakdownForm.TextBoxVendor2ImpWir.Text = 0
BreakdownForm.TextBoxVendor2IncWork.Text = 0
BreakdownForm.TextBoxVendor2MFGDam.Text = 0
BreakdownForm.TextBoxVendor2FailComp.Text = 0
BreakdownForm.TextBoxVendor2DwgErr.Text = 0
BreakdownForm.TextBoxVendor2DesChg.Text = 0
BreakdownForm.TextBoxVendor2DesErr.Text = 0
' Vendor3 Text Boxes etc.
I was hoping to do something like this:
VB Code:
' Call Breakdownboxes procedure to populate textboxes belonging to Vendor1, ' Vendor2, etc.
Breakdownboxes ("Vendor1")
Breakdownboxes ("Vendor2")
Breakdownboxes ("Vendor3")
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
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
-
Jul 29th, 2005, 02:39 AM
#5
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
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...
-
Jul 29th, 2005, 06:47 AM
#6
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|