[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Passing By Reference

Posted on 2004-11-30
7
Medium Priority
?
202 Views
Last Modified: 2013-12-18
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.
0
Comment
Question by:Faraj1969
  • 3
  • 3
7 Comments
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 300 total points
ID: 12707083
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
 

Author Comment

by:Faraj1969
ID: 12707186
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
 
LVL 31

Expert Comment

by:qwaletee
ID: 12707328
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 12707374
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
 

Author Comment

by:Faraj1969
ID: 12707548
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
 

Author Comment

by:Faraj1969
ID: 12708220
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 12708345
That's the spirit! And how very recognizable: tea's my kind of inspirational addiction as well. One more jar to go...
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question