ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Collection as parameter (https://www.excelbanter.com/excel-programming/350324-collection-parameter.html)

stefantem[_15_]

Collection as parameter
 

Problem:
In UserForm1 I have TextBox1, TextBox2, CommandButton1 and
CommandButton2.

Private Sub CommandButton1_Click()
Call test(1)
End Sub

Private Sub CommandButton2_Click()
Call test(2)
End Sub

In Module1 I declare two collections:

dim group1, group2 as New Collection

Public Sub test (a As Integer)
group1.Add UserForm1.TextBox1, "g1"
group2.Add UserForm1.TextBox2, "g2"

''I want to put in TextBox1 or TextBox2 value 1
''and I want to use collection of controls

group & i (1).Value="1" "is not correct but I need a solution for that

End Sub


--
stefantem
------------------------------------------------------------------------
stefantem's Profile: http://www.excelforum.com/member.php...o&userid=13594
View this thread: http://www.excelforum.com/showthread...hreadid=501008


JE McGimpsey

Collection as parameter
 
First, you should never Dim something as a New object. See:

http://cpearson.com/excel/variables.htm

Second, your statement "I declare two collections" is wrong. Your Dim
statement only declares group2 as a collection, group1 is a Variant (see
the same reference).

One way to accomplish your desired method would be to make a collection
of your collections:

Dim group1 As Collection
Dim group2 As Collection

Public Sub test(a As Integer)
Dim groups As Collection
Dim i As Long
Set group1 = New Collection
Set group2 = New Collection
Set groups = New Collection
groups.Add group1
groups.Add group2
group1.Add UserForm1.TextBox1, "g1"
group2.Add UserForm1.TextBox2, "g2"
For i = 1 To groups.count
groups(i)(1).Text = i
Next i
End Sub

Note: I'm not sure what you're trying to do with your argument (a) for
test().


In article ,
stefantem
wrote:

Problem:
In UserForm1 I have TextBox1, TextBox2, CommandButton1 and
CommandButton2.

Private Sub CommandButton1_Click()
Call test(1)
End Sub

Private Sub CommandButton2_Click()
Call test(2)
End Sub

In Module1 I declare two collections:

dim group1, group2 as New Collection

Public Sub test (a As Integer)
group1.Add UserForm1.TextBox1, "g1"
group2.Add UserForm1.TextBox2, "g2"

''I want to put in TextBox1 or TextBox2 value 1
''and I want to use collection of controls

group & i (1).Value="1" "is not correct but I need a solution for that

End Sub


Tom Ogilvy

Collection as parameter
 
What is the point of having a collection with one member?

Seems like you need a better explantion of what you want to do. Right now
it appears you only need one collection and I previously gave you an example
for that.

--
Regards,
Tom Ogilvy


"stefantem" wrote
in message ...

Problem:
In UserForm1 I have TextBox1, TextBox2, CommandButton1 and
CommandButton2.

Private Sub CommandButton1_Click()
Call test(1)
End Sub

Private Sub CommandButton2_Click()
Call test(2)
End Sub

In Module1 I declare two collections:

dim group1, group2 as New Collection

Public Sub test (a As Integer)
group1.Add UserForm1.TextBox1, "g1"
group2.Add UserForm1.TextBox2, "g2"

''I want to put in TextBox1 or TextBox2 value 1
''and I want to use collection of controls

group & i (1).Value="1" "is not correct but I need a solution for that

End Sub


--
stefantem
------------------------------------------------------------------------
stefantem's Profile:

http://www.excelforum.com/member.php...o&userid=13594
View this thread: http://www.excelforum.com/showthread...hreadid=501008





All times are GMT +1. The time now is 07:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com