How to reference a public array (declared in module) from a proced

A

Amzee

I can reference a listbox in a Worksheet using the following

Public Sub Procedure1(worksheetName As String, listBoxName As String)
Dim listSize As Integer
listSize = Worksheets(worksheetName).OLEObjects(listBoxName).Object.ListCount
......
end sub

How do I do the same for a public array (declared in a module) with the
following procedure??

Public Sub setSelections(arrayName as String)
????.....
end sub

Thanks!
 
T

Tom Ogilvy

Assuming arrayname is a single dimension array of type string.

Public Sub setSelections(arrayName as String)
for i = lbound(arrayname) to ubound(arrayname)
sStr = msg & arrayname(i) & ", "
if i mod 5 = 0 then
msgbox msg
sStr = ""
end if
Next
end sub
 
A

Amzee

Hi Tom,

It worked fine when I used Public Sub setSelections(arrayName() as String)

Regards.
 
T

Tom Ogilvy

There were a couple of typos/mistakes. For completeness here is a cleaned
up version (although it sounds like you got what you needed).

Sub Main()
Dim myArr(1 To 10) As String
For i = 1 To 10
myArr(i) = Chr(i + 64) & Chr(i + 65) & Chr(i + 66)
Next
setSelections myArr


End Sub

Public Sub setSelections(ArrayName() As String)
For i = LBound(ArrayName) To UBound(ArrayName)
sStr = sStr & ArrayName(i) & ", "
If i Mod 5 = 0 Then
MsgBox sStr
sStr = ""
End If
Next
End Sub
 
A

Amzee

Thanks Tom. It's working fine for me now.


Tom Ogilvy said:
There were a couple of typos/mistakes. For completeness here is a cleaned
up version (although it sounds like you got what you needed).

Sub Main()
Dim myArr(1 To 10) As String
For i = 1 To 10
myArr(i) = Chr(i + 64) & Chr(i + 65) & Chr(i + 66)
Next
setSelections myArr


End Sub

Public Sub setSelections(ArrayName() As String)
For i = LBound(ArrayName) To UBound(ArrayName)
sStr = sStr & ArrayName(i) & ", "
If i Mod 5 = 0 Then
MsgBox sStr
sStr = ""
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top