Solved

Passing array between subs

Posted on 2011-09-12
3
261 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
[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
3 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

710 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