Passing By Reference

Hi everyone,
Please check the following code:

Sub Click(Source As Navigator)

          Dim cMIPScale( 1 to 7, 1 to 2 )  As String
          Dim vMIPScale                         As Variant

          cMIPScale( 1, 1 ) = "Location"
          cMIPScale( 2, 1 ) = "Grade"
          vMIPScale = CheckMIPScale( cMIPScale )
End Sub

Function CheckMIPScale( tMIPScale )

          CheckMIPScale = ""
          '== Statements to check the view
          '== and start filling the rest of the
          '== array from (3 to 7, 1 to 2 )
          CheckMIPScale = tMIPScale
End Function

What I'm trying to do here is, when user press the button UPDATE, the button will declare an array and initiate 1st and 2nd elements then pass the array to the function. Now the function based on the 2 elements will search a view and fill the rest of array elements ( from 3 to 7, 1 to 2 ) and return array to the SUB who called the function. I used the Debugger and it stopped at the statement "vMIPScale = CheckMIPScale( cMIPScale )" saying Type Mismatch. Seriously I've read the Notes help before posting here but couldn't solve it. Any help would be appreciated. and if there's a better way to do it, I don't mind at all.

Many thanks in advance.
Faraj1969System AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sjef BosmanGroupware ConsultantCommented:
Probably it's about the parameter definition in the function. Try

    Function CheckMIPScale( tMIPScale( 1 to 7, 1 to 2 )  As String )

But why don't you have your function defined differently? Like this:

    Sub Click(Source As Navigator)

          Dim vMIPScale As Variant

          vMIPScale = CheckMIPScale("Location", "Grade")
    End Sub

    Function CheckMIPScale(s1 As String, s2 As String)

          CheckMIPScale = ""
          '== Statements to check the view
          '== and start filling the rest of the
          '== array from (3 to 7, 1 to 2 )
          Dim tMIPScale(1 to 7, 1 to 2) As String
          CheckMIPScale = tMIPScale
    End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Faraj1969System AdministratorAuthor Commented:
Umm, ok sjef, I'll try that and let you know. One more thing, after the function finish, the array will be assigned to the variant variable. shall i treat the variant same as treating array ? ( sorry i'm not very familier with variant variables yet )

Cheers
0
qwaleteeCommented:
When you don't give a type to a variable, it gets a type of variant.  In your Function declaration, tMIPScale is untyped, so by definition, it is type Variant.

Variants are essentially "hold anything" variables.  They can hold any type of scalar or array or Notes object or OLE object or other object.  

That said, I do recall Notes being a little fussy about passed arrays.  Variants are supposed to be able to hold anything, but that doesn't mean you can pass anything to a variant.   There have been some oddball cases where I had to use an intermediate variant to hold something that could otherwise not be passed, e.g.,

Dim temp as variant, myRealVariable as somethingWeird
code to set up myRealVariable here
temp = myRealVariable
Call someFunction( temp )
myRealVariable = temp


But you may not need to go that far.  Declare the parameter as a variant array or string array, and see if it works:

Function CheckMIPScale( tMIPScale() )
Function CheckMIPScale( tMIPScale() As Variant ) 'identical to previous line, but being explicit about it
Function CheckMIPScale( tMIPScale() As String)

Sorry, that's an off the cuff answer, so it might not be it.  But it is an easy change to try!
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Sjef BosmanGroupware ConsultantCommented:
A Variant contains both data and a definition of the type of the variable. This makes the Variant an easy-to-use type, but the flexibility requires considerable overhead. Use Variants only when your function needs to return more than one type. Indeed, treat your Variant as if it were the array as you defined it. There are some caveats, you'll encounter them on the way (as I usually do).
0
Faraj1969System AdministratorAuthor Commented:
Many thanks sjef and qwaletee, I appreciate it. I'll work on it tonight, and let you know the result tomorrow.

Have a nice day.   Cheers.
0
Faraj1969System AdministratorAuthor Commented:
Ok, I said I'm going home but, I also knew if I didn't fix it, I'll keep thinkin of it all night long, so I made a giant cup of tea and stayed behind.. lol !!!  Anyway, here how I did it, and it worked like a charm.

Sub Click(Source As Navigator)
          Dim cMIPScale( 1 to 5, 1 to 2 )  As String
          Call CheckMIPScale( cMIPScale, "Location", "Grade" )
End Sub

Function CheckMIPScale( tMIPScale, tLocation As String, tGrade As String )
          '== Statements to check the view
          '== and start filling the array
          '== from ( 1 to 5, 1 to 2 )
End Function

This way, I decreased the size of the array from 7 to 5, omitted the use of the variant, and I didn't use the statement "CheckMIPScale = tMIPScale" inside the function. When I checked the array cMIPScale inside SUB through Debugger, it had all the values I need. To be honest, now sure how the function returned the array filled with values, I just hope DEBUG doesn't lie..... Very grateful guys. Cheers.
0
Sjef BosmanGroupware ConsultantCommented:
That's the spirit! And how very recognizable: tea's my kind of inspirational addiction as well. One more jar to go...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.