Results 1 to 5 of 5

Thread: Areguments to ASP

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Hi,
    is it possible to send a parameter to a sub / function byref, i.e. so we can change the value stored at the address where the variable is passed from.

    I was under the impression this wasn't the case, but have seen an example where the parameter is passed as a variant.

    e.g.
    VB:

    Public Function Get_Age(ByRef age As Variant) As Boolean

    age = 5
    Get_Age = True


    End Function


    ASP:
    <%
    dim lo_age
    dim li_age
    dim lb_age
    set lo_age = Server.CreateObject("Test.Age")

    li_age = 3

    lb_age = lo_age.Get_Age(li_age)

    Response.Write "Anything" & li_age
    %>

    Should I expect this to write 5 or 3 or nothing.?

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    You would get 5 after calling your function, since the default is ByRef. So, that means you have a reference to your original variable li_age.

    Regards,

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Does the parameter have to be variant?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 1999
    Location
    Belfast
    Posts
    254
    Thanks got answer:

    "A common scenario is to call a method on a server-side object that returns an array of strings, or some other type, to ASP. Depending on how the server-side object is coded, this may cause a "Type Mismatch" error in the script. The key to making this work, is declaring the object method to return a VARIANT. Inside the method, store the array of data in a VARIANT and return this variable to the server-side script."

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    In Scripting, every variable you declare is a variant.
    So, when you're a passing the string to the DLL, then make sure you have converted the string (even if your variable has something like this MyVar = "abc"), you have to convert the value to string. Here is a little example:

    In VB's DLL
    Code:
    Public Function SetNewValue(p_strString As String)
        SetNewValue = "This is a new value"
    End Function
    In ASP
    Code:
    Dim objMyDLL
    Dim strMyVar
    
    Set objMyDLL = Server.CreateObject("MyDLL.MyClass")
    
    strMyVar = "abc"
    strMyVar = objMyDLL.SetNewValue(CStr(strMyVar))
    
    Response.Write "New value is " & strMyVar

    If you don't convert to string, then you would get Type mismatch from your DLL.

    Regards,

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