RSS Forums RSS
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 38167 | Replies: 1
Reply
Join Date: Feb 2004
Location: Pound Ridge, NY
Posts: 1
Reputation: Chas Griff is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Chas Griff Chas Griff is offline Offline
Newbie Poster

Help passing arrays in visual basic

  #1  
Feb 2nd, 2004
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2003
Location: Canada
Posts: 786
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Rep Power: 9
Solved Threads: 25
Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Help Re: passing arrays in visual basic

  #2  
Feb 6th, 2004
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.
Public Sub ProcTest(By Ref lngNum() as Long)
   lngNum(1) = 2
End Sub

Public Sub Something()
  Dim lngArray(1 To 5) as Long
  Call ProcTest(lngArray)
  MsgBox("Index 1 = " & lngArray(1))
End Sub

Hope this helps?! :lol:
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:03 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC