Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
help with data collection! | New Users to Excel | |||
How to choose if I use a parameter or not in a parameter query | Excel Discussion (Misc queries) | |||
Error with passing collection as parameter | Excel Programming | |||
Collection | Excel Programming | |||
2 Collection questions | Excel Programming |