ByRef Parameters

Results 1 to 2 of 2

Thread: ByRef Parameters

  1. #1
    Join Date
    Dec 1969

    Default ByRef Parameters

    Anyone know how to pass function parameters byRef using JScript server side scripts? it&#039;s that I want to pass a rs to a function which will prepare my paging. I can&#039;t send it back by return sinc I use it for another varaible...<BR><BR>Thanks a lot!

  2. #2
    Join Date
    Dec 1969

    Default You can't...period...

    Long been a problem with Java *and* JavaScript.<BR><BR>The traditional way of "fixing" it is to use a one element array as the argument and change the array element. That has the effect of passing the value back to the caller.<BR><BR>*********<BR><BR>function getRsAndErrorCode( holder )<BR> var rs = Server.CreateObject("ADODB.Recordset")<BR> try {<BR> ... );<BR> } catch {<BR> return -17;<BR> }<BR> holder[0] = rs;<BR> return 0;<BR>}<BR><BR>var junk = new Array(1);<BR>if getRsAndErrorCode( junk ) == 0<BR>{<BR> theRS = junk[0];<BR> ....<BR>}<BR><BR>Note that you *CAN* create the recordset *before* the call, pass that as the argument, and do the opening inside the call.<BR><BR>In that case you are only changing the contents (value of) the argument and don&#039;t need "by ref" semantics.<BR><BR>**************<BR><BR>The other possibility is to of course pass in an instance of some object, instead of just the array. The array is fine if you only have one "by ref" to be returned, but if you get more complex than that...<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts