?
Solved

Passing array between subs

Posted on 2011-09-12
3
Medium Priority
?
263 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 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

718 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