?
Solved

How do I pass an array from a function?

Posted on 2008-10-01
4
Medium Priority
?
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 375 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

719 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