Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,324 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,800 people online right now. Registration is fast and FREE... Join Now!




Passing two multi-dimensional arrays via paramater passing

 
Reply to this topicStart new topic

Passing two multi-dimensional arrays via paramater passing

-fedexer-
27 Aug, 2008 - 12:14 PM
Post #1

New D.I.C Head
*

Joined: 3 Jun, 2008
Posts: 41



Thanked: 2 times
My Contributions
CODE

-- in general declarations
Dim userID(5, 1) as String
Dim seat(5, 0) as Integer
dim loggedInID as Integer
----

sub routine here()
Bookseat  loggedInID, userID(5, 1) seat(5,0)

end sub

Private Sub Bookseat(ByVal loggedInID As Integer, ByRef userID() As String, seat() As Integer)
//code
End sub


Now the problem is , when Bookseat is called, VB throws this error:

QUOTE
Compile error:

Type mismatch: array or user-defined type expected


I can't seem to work out how to pass those two multi-dimensional arrays into the Bookseat ...

All help is greatly appreciated.

Thanks
-fedexer-

This post has been edited by -fedexer-: 27 Aug, 2008 - 12:15 PM
User is offlineProfile CardPM
+Quote Post

thava
RE: Passing Two Multi-dimensional Arrays Via Paramater Passing
27 Aug, 2008 - 05:17 PM
Post #2

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 442



Thanked: 18 times
Dream Kudos: 50
My Contributions
try this one
CODE

Bookseat loggedInID, userID, seat

it will solve your problem

and also any changes on array done inside the sub procedure may take take effects on out side the sub icon_up.gif


This post has been edited by thava: 27 Aug, 2008 - 05:22 PM
User is offlineProfile CardPM
+Quote Post

-fedexer-
RE: Passing Two Multi-dimensional Arrays Via Paramater Passing
27 Aug, 2008 - 09:58 PM
Post #3

New D.I.C Head
*

Joined: 3 Jun, 2008
Posts: 41



Thanked: 2 times
My Contributions
Having done that i still get the same error thrown, i am starting to think it is due to me requesting them as string an integers (which one array is an integer, and the other a string) change it to as variant, and hey presto it works.. but completely changes everything as default initialize value does not seem to be 0 or "".

Thanks for the help though thava.

This post has been edited by -fedexer-: 27 Aug, 2008 - 09:59 PM
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: Passing Two Multi-dimensional Arrays Via Paramater Passing
28 Aug, 2008 - 03:33 AM
Post #4

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 799



Thanked: 51 times
Dream Kudos: 2175
My Contributions
vb

sub routine here()
Bookseat loggedInID, userID(5, 1) ,seat(5,0)

end sub

What this is saying is
Call BookSeat
With loggedInID
And userID at row 5 column 1
And seatID at row 5 column 0

so the routine need the parameter set to
vb

Private Sub Bookseat(ByVal loggedInID As Integer, ByRef userID As String,Byref seat As Integer)
'example
userID="Hello"
seat=123
End sub


By using ByRef it is passed back into the array, at position specifed.

This post has been edited by AdamSpeight2008: 28 Aug, 2008 - 03:33 AM
User is offlineProfile CardPM
+Quote Post

-fedexer-
RE: Passing Two Multi-dimensional Arrays Via Paramater Passing
28 Aug, 2008 - 09:05 AM
Post #5

New D.I.C Head
*

Joined: 3 Jun, 2008
Posts: 41



Thanked: 2 times
My Contributions
Ok.. well that is news to me, and definetly not what i was intending to be doing, what i am trying to do is pass the whole array into the function, so it can be edited inside the function.

Would that be possible? and if so , how?

Thanks so far lads.


User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: Passing Two Multi-dimensional Arrays Via Paramater Passing
28 Aug, 2008 - 01:19 PM
Post #6

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 799



Thanked: 51 times
Dream Kudos: 2175
My Contributions
QUOTE(-fedexer- @ 28 Aug, 2008 - 06:05 PM) *

Ok.. well that is news to me, and definetly not what i was intending to be doing, what i am trying to do is pass the whole array into the function, so it can be edited inside the function.

Would that be possible? and if so , how?

Thanks so far lads.


Since the arrays have been defined outside of a routine the can be accessed inside of one.
It is possible to pass the memory address into the array, but it get complicated and messy.
User is offlineProfile CardPM
+Quote Post

thava
RE: Passing Two Multi-dimensional Arrays Via Paramater Passing
28 Aug, 2008 - 03:53 PM
Post #7

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 442



Thanked: 18 times
Dream Kudos: 50
My Contributions
i think the problem is in your coding
i have a piece of code try this
CODE


Private Sub Bookseat(ByVal loggedInID As Integer, ByRef userID() As String, seat() As Integer)
'
For i = 0 To UBound(seat) - 1
    userID(i, 0) = i + 3
    seat(i, 0) = i + 3
Next

End Sub
Private Sub Form_Load()
    For i = 0 To UBound(seat) - 1
        userID(i, 0) = i
        seat(i, 0) = i
    Next
    Debug.Print "before passing"
    For i = 0 To UBound(seat) - 1
        Debug.Print userID(i, 0)
        Debug.Print seat(i, 0)
    Next
    Bookseat loggedInID, userID, seat
    Debug.Print "affter passing"
    For i = 0 To UBound(seat) - 1
        Debug.Print userID(i, 0)
        Debug.Print seat(i, 0)
    Next
End Sub

i think you miss the "," in your method passing
if you have the error stilll post your coding briefly
hope you solved it icon_up.gif

if this post helpfull just click the this post was helpful

This post has been edited by thava: 28 Aug, 2008 - 04:01 PM
User is offlineProfile CardPM
+Quote Post

-fedexer-
RE: Passing Two Multi-dimensional Arrays Via Paramater Passing
29 Aug, 2008 - 07:12 AM
Post #8

New D.I.C Head
*

Joined: 3 Jun, 2008
Posts: 41



Thanked: 2 times
My Contributions
Yeah after talking with my computing studies teacher about array passing he informed me that it should not be done, i actually overlooked the fact that i could call the array inside the procedure anyway.

Thanks for all the help though guys

-fedexer-
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:38AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month