Solved

How do I pass an array from a function?

Posted on 2008-10-01
4
391 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 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

21 Experts available now in Live!

Get 1:1 Help Now