| | |
passing arrays in visual basic
![]() |
•
•
Join Date: Feb 2004
Posts: 1
Reputation:
Solved Threads: 0
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.
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.
Hope this helps?! :lol:
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)
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:
![]() |
Similar Threads
- how can i Initialise 2 dimentional integer array in visual basic 6 (Visual Basic 4 / 5 / 6)
- Combo lookup arrays in Visual basic.net 2005 (VB.NET)
- Is it possible to display report in Visual Basic which is created in Microsoft Access (Visual Basic 4 / 5 / 6)
- Passing arrays between subs (VB.NET)
- Palindromes on visual basic 5.0 (Visual Basic 4 / 5 / 6)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Caesar cipher problem with CHR(32)
- Next Thread: What do you do with your knowledge?
| Thread Tools | Search this Thread |
* 6 2007 access activex add age basic beginner birth bmp calculator cd cells.find click client code college connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web windows





