Results 1 to 4 of 4

Thread: Need to know how to external functions byRef

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    2

    Question

    Friends
    I need to know in a VBScript how to do I call a method with 2 parameters by reference.
    I tried call

    Object = CreateObject(ActiveX.function)
    and then
    Object.method (ByRef array1, ByRef array2) and it did not work.

    I need to pass this by reference only because the method will update the array information based on some validation.

    Would appreciate any help

    Thanks

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    In your ActiveX object, make sure your parameters are defined as byref myArray as variant

    Example:

    Public Function DoIt(ByRef MyArray1 as Variant, ByRef MyArray2 as Variant) as Boolean




    Tom

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    2

    Post Already have it ByRef in the method

    In my called methood, I already have it as
    methodA (ByRef arr1 As Variant, ByRef arr2 As Variant)
    but still whatever I pass is still taking by value.
    In fact, I wrote a small VB stub which calls this method and I am noticing that the array is called by Reference. It is only when I am calling in VBscript that it is calling the method by Value, on default.
    Thanks
    Kondal

  4. #4
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    Hey Kondal

    I just sent this to you in an Email, but if you don't get it, here it is

    This works fine for me: my VB function is able to modify the contents of the array and ASP is then able to read the changes

    ASP code
    Code:
    <%@Language=VBScript EnableSessionState=False%>
    <% option explicit
    
    dim myArray1(0)
    dim myArray2(0)
    
    dim objObject
    
    set objObject = server.CreateObject("prjTest.Class1")
    
    call objObject.doit(myArray1, myArray2)
    
    set objObject = nothing
    
    Response.Write myArray1(0)
    Response.Write myArray2(0)
    
    %>
    VB Code -- call your project "prjTest" and leave the default class name as "Class1"
    Code:
    Public Sub DoIt(ByRef myArray1 As Variant, ByRef myArray2 As Variant)
    
        myArray1(0) = "HelloWorld!"
        myArray2(0) = "Hi!"
        
    End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width