Solved

How do I pass an array from a function?

Posted on 2008-10-01
4
390 Views
Last Modified: 2012-05-05
I wrote a function that breaks some data into an array.  Now I need to use that array in another procedure.  How do I pass the array out of the function, and how do I call it into my other procedure?  

My function code is:

   Public Function Array_lstCells()
        Dim a As Integer = lstCells.SelectedItems.Count
        Dim arr_lstCells(a, 3)
        Dim i As Integer = 0
        Dim sb As String = ""

        For Each sel As Object In lstCells.SelectedItems
            arr_lstCells(i, 0) = lstCells.SelectedItems.Item(i)
            'Assign project # based on txtProject
            arr_lstCells(i, 1) = txtProject.Text
            'Split out the path and project# from the data file
            Dim strSplitListItem As String() = lstCells.SelectedItems.Item(i).split("-")
            'Split out the cell and file type from the first split
            Dim strSplitListItem2 As String() = strSplitListItem(1).Split(".")
            'Assign the cell
            arr_lstCells(i, 2) = strSplitListItem2(0)
            'Assign the file type
            arr_lstCells(i, 3) = strSplitListItem2(1)

            i = i + 1
            sb = sb & sel.ToString() & vbCrLf
        Next
    End Function

I want to pass arr_lstCells out of the function.
0
Comment
Question by:stewdaddy
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:philipjonathan
ID: 22620851
Try changing the function declaration to:
Public Function Array_lstCells() As Object(,)

And add a return statement before End Function:

  Return arr_lstCells
End Function
0
 

Author Comment

by:stewdaddy
ID: 22620957
And then how do I call it into the procedure?  I keep getting a "variable not declared" error for aar_lstCells.  My Procedure looks like this:

    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
        Array_lstCells()
        MessageBox.Show(arr_lstCells(0, 0) & vbCrLf & arr_lstCells(0, 1) & vbCrLf & arr_lstCells(0, 2) & vbCrLf & arr_lstCells(0, 3))
    End Sub
0
 
LVL 18

Accepted Solution

by:
philipjonathan earned 125 total points
ID: 22621063
Chang the calling to:
Dim arr_lstCells As Object(,) = Array_lstCells()
0
 

Author Closing Comment

by:stewdaddy
ID: 31502244
Ok that now works.  Thank you for your help.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now