Solved

Passing array between subs

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

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…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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