Solved

How do I pass an array from a function?

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

785 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