+ Reply to Thread
Results 1 to 5 of 5

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

  1. #1
    Amzee
    Guest

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

    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!

  2. #2
    Tom Ogilvy
    Guest

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

    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

    --
    Regards,
    Tom Ogilvy


    "Amzee" <Amzee@discussions.microsoft.com> wrote in message
    news:FAE35677-7C3F-4B75-B9FB-E2B05FC1B61C@microsoft.com...
    > 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!




  3. #3
    Amzee
    Guest

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

    Hi Tom,

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

    Regards.

    "Amzee" wrote:

    > 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!


  4. #4
    Tom Ogilvy
    Guest

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

    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

    --
    Regards,
    Tom Ogilvy

    "Amzee" <Amzee@discussions.microsoft.com> wrote in message
    news:80E7F3AD-A2C6-4F01-B542-B85B5A87D0C4@microsoft.com...
    > Hi Tom,
    >
    > It worked fine when I used Public Sub setSelections(arrayName() as String)
    >
    > Regards.
    >
    > "Amzee" wrote:
    >
    > > 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!




  5. #5
    Amzee
    Guest

    Re: How to reference a public array (declared in module) from a pr

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


    "Tom Ogilvy" wrote:

    > 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
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "Amzee" <Amzee@discussions.microsoft.com> wrote in message
    > news:80E7F3AD-A2C6-4F01-B542-B85B5A87D0C4@microsoft.com...
    > > Hi Tom,
    > >
    > > It worked fine when I used Public Sub setSelections(arrayName() as String)
    > >
    > > Regards.
    > >
    > > "Amzee" wrote:
    > >
    > > > 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!

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1