943,923 Members | Top Members by Rank

Ad:
Feb 2nd, 2004
0

passing arrays in visual basic

Expand Post »
I've written a lot of code in QuickBasic 4.5 and have finally decided to learn Visual Basic. I'm using VB 4.0 which I bought a long time ago, but for learning purposes I figure it's good enough for now. It all looks pretty straightforward, but my problem comes when passing arrays as arrguments between subprocedures. An array declared dynamically as, say, "Dim arrayName() As Single" and listed in the sub's parameter list as "arrayName()" seems perfectly acceptable to VB's grammar checker, but when I try to call the sub using "arrayName()" as an argument I get a "type mis-match: array or user-defined type expected" warning. In my experience, using the array's name followed by empty parentheses has always worked for passing arrays between subs. As VB seems to accept most of QBASIC's syntax, I'm puzzled by this problem, especially since passing arrays between subs seem so fundamental. Does anyone have an answer? Thanks very much in advance.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Chas Griff is offline Offline
1 posts
since Feb 2004
Feb 6th, 2004
0

Re: passing arrays in visual basic

OK, not quite sure what you are saying, so let me see if this helps.

Passing Arrays as Parameters

1. Reference the array by name in the CALL statement
2. The called SUB/FUNCTION MUST accept the data into a parameter declared with the SAME data type, but without an index.
3. Arrays must be passed using the ByRef Method.

Ex.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Sub ProcTest(By Ref lngNum() as Long)
  2. lngNum(1) = 2
  3. End Sub
  4.  
  5. Public Sub Something()
  6. Dim lngArray(1 To 5) as Long
  7. Call ProcTest(lngArray)
  8. MsgBox("Index 1 = " & lngArray(1))
  9. End Sub

Hope this helps?! :lol:
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Caesar cipher problem with CHR(32)
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: What do you do with your knowledge?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC