Solved

Passing array between subs

Posted on 2011-09-12
3
255 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 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now