Passing arrays between subs

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2005
Posts: 1
Reputation: Pieter is an unknown quantity at this point 
Solved Threads: 0
Pieter Pieter is offline Offline
Newbie Poster

Passing arrays between subs

 
0
  #1
Oct 7th, 2005
I'm new to visual basic, and after writing my first few programs I decided it's a nice language for database front ends :-) just like VBA.

Everhing is working out fine, but there's one thing I can't figure out, how do I pass arrays between private subs without declaring them in a module?
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 2
Reputation: molti is an unknown quantity at this point 
Solved Threads: 0
molti molti is offline Offline
Newbie Poster

Re: Passing arrays between subs

 
0
  #2
Oct 19th, 2005
just like any other variable.
declare them in the first sub or global, on reference to the second sub put them between brackets, like this:

'Global declaration, variables can be used in entire script.
Dim strArray(1, 10) as String

Private Sub First()
'Local declaration, used in only this sub or referred to when calling subs.
Dim intArray(1, 10) as Integer
Second(intArray)
'or
Second()
End Sub

Private Sub Second(intArray)
strArray(1) = "A"
intArray(1) = 2
End Sub
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Passing arrays between subs

 
0
  #3
Nov 1st, 2007
Try something like this:
  1. Dim myArray(10) As Integer
  2.  
  3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4. AddArray(myArray, Integer.Parse(TextBox2.Text))
  5. TextBox1.Text = myArray(Integer.Parse(TextBox2.Text)).ToString
  6. End Sub
  7.  
  8. Private Sub AddArray(ByVal thisArray As Array, ByVal Index As Integer)
  9. thisArray(Index) = Index + 3
  10. End Sub
I didn't do it but check when passing arrays that your index is not outside the bounds of the array.
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC