Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with data collection! brandon roland[_2_] New Users to Excel 1 August 8th 07 10:09 PM
How to choose if I use a parameter or not in a parameter query Arnaud Excel Discussion (Misc queries) 0 March 8th 07 01:19 PM
Error with passing collection as parameter McManCSU[_17_] Excel Programming 3 August 1st 05 06:19 PM
Collection Todd Huttenstine Excel Programming 4 December 17th 04 09:41 PM
2 Collection questions Stuart[_5_] Excel Programming 5 January 30th 04 04:50 PM


All times are GMT +1. The time now is 04:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"