Passing many controls parameter to procedure
Hi
I Would like to pass one or more controls to a procedure , How can I Do, I tried to use ParamArray , but no work
I would like something as:
Code:
My_procedure (myWhere As String, myBindVals As String, txttetbox1 as textbox, txttexbox2 as textbox....)
'or only textbox (or combobox....etc)
My_procedure (myWhere As String, myBindVals As String, txttetbox1 as textbox)
Re: Passing many controls parameter to procedure
And what's the problem?
The code that you wrote should work...
Re: Passing many controls parameter to procedure
How did a ParamArray not work? Other options can be to add the controls to a collection, then pass the collection. In either case, you would iterate through the passed parameter (whether a pararmarray or collection), i.e.,
Code:
For x = 1 To passedCollection.Count
or
For x = 0 To Ubound(paramArrayVariable)
Re: Passing many controls parameter to procedure
Quote:
Originally Posted by
Eduardo-
And what's the problem?
The code that you wrote should work...
my problem is populate control, but when return to form the control is empty
Code:
' Populate the control with the obtained value.
For i = 0 To UBound(parametervalues)
parametervalues(i) = ldLOVRetVal(intLOVId, i + 1)
' txtCfop_code = ldLOVRetVal(intLOVId, 1)
' txtCfopdescri = ldLOVRetVal(intLOVId, 2)
Next
'------------------
' How can I put setfocus in firstcontrol
' txtCfop_code.SetFocus
Re: Passing many controls parameter to procedure
I don't know. If you can post a sample project to see the problem that could help.
1 Attachment(s)
Re: Passing many controls parameter to procedure
Quote:
Originally Posted by
Eduardo-
I don't know. If you can post a sample project to see the problem that could help.
Example
Re: Passing many controls parameter to procedure
You don't return a control. You pass a control, the routine does whatever it needs to with the control. Simple example
Code:
Private Sub Command1_Click()
PopulateControls txtCfop_code, Command1
End Sub
Public Sub PopulateControls(ParamArray Ctrls())
Dim c As Long
For c = 0 To UBound(Ctrls)
If TypeName(Ctrls(c)) = "TextBox" Then
Select Case Ctrls(c).Name
Case "txtCfop_code"
' do whatever is needed
Ctrls(c).Text = "Hello World"
' other Cases for other textbox controls
End Select
ElseIf TypeName(Ctrls(c)) = "CommandButton" Then
' setup your case statements
Else
' other ElseIf statements as needed
End If
If c = 0 Then
Ctrls(c).SetFocus ' set focus to 1st control passed in paramarray?
End If
Next
End Sub
Re: Passing many controls parameter to procedure
Hmmm, yeah, I looked at it too.
I'm pretty sure you can't actually return the values passed in a ParamArray. It'd be very tricky and very non-standard to do that.
However, you can certainly return some set of controls in an Object array, or a Collection, or even a Variant array. And you could pass in this array (or Collection), fill it, and then it'd be passed back filled.
But it also seems that we're confusing actual controls with the properties of those controls. We can certainly pass in a reference to some control (or even set of controls, possibly with ParamArray), and then change whatever properties we like ... and they'd still be changed when we returned.
Mutley, if you could outline a bit more about what you're trying to do, I think we could probably come up with better solutions.
Take Care,
Elroy
Re: Passing many controls parameter to procedure
Quote:
Originally Posted by
mutley
Example
Code:
Private Sub CMDFILL_Click()
example_fill TXTCODE, TXTDECRI
End Sub
Private Sub example_fill(ParamArray parametervalues() As Variant)
Dim txt_examples(4) As String
txt_examples(0) = "MYCODE"
txt_examples(1) = "MYDESSCRIPTION"
txt_examples(2) = "LONDON"
txt_examples(3) = "PARIS"
txt_examples(4) = "NEW YORK"
For I = 0 To UBound(parametervalues)
parametervalues(I).Text = txt_examples(I)
Next
'I would like the controls with MYCODE and MYDESSCRIPTION
End Sub
Or:
Code:
Private Sub CMDFILL_Click()
example_fill TXTCODE, TXTDECRI
End Sub
Private Sub example_fill(ParamArray parametervalues() As Variant)
Dim txt_examples(4) As String
Dim iCtl As Control
txt_examples(0) = "MYCODE"
txt_examples(1) = "MYDESSCRIPTION"
txt_examples(2) = "LONDON"
txt_examples(3) = "PARIS"
txt_examples(4) = "NEW YORK"
For I = 0 To UBound(parametervalues)
Set iCtl = parametervalues(I)
iCtl = txt_examples(I)
Next
'I would like the controls with MYCODE and MYDESSCRIPTION
End Sub
Re: Passing many controls parameter to procedure
Quote:
Originally Posted by
Eduardo-
Code:
Private Sub CMDFILL_Click()
example_fill TXTCODE, TXTDECRI
End Sub
Private Sub example_fill(ParamArray parametervalues() As Variant)
Dim txt_examples(4) As String
txt_examples(0) = "MYCODE"
txt_examples(1) = "MYDESSCRIPTION"
txt_examples(2) = "LONDON"
txt_examples(3) = "PARIS"
txt_examples(4) = "NEW YORK"
For I = 0 To UBound(parametervalues)
parametervalues(I).Text = txt_examples(I)
Next
'I would like the controls with MYCODE and MYDESSCRIPTION
End Sub
Or:
Code:
Private Sub CMDFILL_Click()
example_fill TXTCODE, TXTDECRI
End Sub
Private Sub example_fill(ParamArray parametervalues() As Variant)
Dim txt_examples(4) As String
Dim iCtl As Control
txt_examples(0) = "MYCODE"
txt_examples(1) = "MYDESSCRIPTION"
txt_examples(2) = "LONDON"
txt_examples(3) = "PARIS"
txt_examples(4) = "NEW YORK"
For I = 0 To UBound(parametervalues)
Set iCtl = parametervalues(I)
iCtl = txt_examples(I)
Next
'I would like the controls with MYCODE and MYDESSCRIPTION
End Sub
Very very good
Is possible call an event ?
Re: Passing many controls parameter to procedure
Quote:
Originally Posted by
mutley
Very very good
Is possible call an event ?
iCtl.SetFocus
Re: Passing many controls parameter to procedure
What do you mean to call an event?
What would you like to do, specifically?