Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Passing array between subs

Posted on 2011-09-12
3
Medium Priority
?
266 Views
Last Modified: 2012-06-27
I feel like a total noob for having to ask this question, but, I'm having trouble passing an array between subroutines. What am I missing?

here is a sample of my code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim soup(3, 3) As String
        soup(0, 0) = "nacho"
        soup(0, 1) = "cheese"
        mySub(soup(3, 3))
    End Sub

    Protected Sub mySub(ByRef soup As String)
        soup(0, 0) = "Eggs"
        soup(0, 1) = "Bacon"
    End Sub

Open in new window

0
Comment
Question by:David11011
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 2000 total points
ID: 36523709
Please try the following:

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Dim soup(3, 3) As String
		soup(0, 0) = "nacho"
		soup(0, 1) = "cheese"
		mySub(soup)
	End Sub

	Protected Sub mySub(ByRef soup(,) As String)
		soup(0, 0) = "Eggs"
		soup(0, 1) = "Bacon"
	End Sub

Open in new window

0
 
LVL 2

Author Comment

by:David11011
ID: 36523746
That worked. thanks. One more question for you.
Originally I tried
	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		Dim soup(3, 3) As String
		soup(0, 0) = "nacho"
		soup(0, 1) = "cheese"
		mySub(soup)
	End Sub

	Protected Sub mySub(ByRef soup(3, 3) As String)
		soup(0, 0) = "Eggs"
		soup(0, 1) = "Bacon"
	End Sub

Open in new window

but that throws an error. Why would  soup(,) not throw an error and soup(3, 3) throw an error when  (3,3) is within the array bounds?
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 36523798
The only time you specify the array size is on the variable declaration.  On the function declaration you just indicate that it's a two-dimension array (soup(,) in this case).

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

886 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