|
-
Nov 6th, 2000, 09:22 AM
#1
Thread Starter
Addicted Member
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.?
-
Nov 6th, 2000, 09:57 AM
#2
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,
-
Nov 6th, 2000, 09:59 AM
#3
Thread Starter
Addicted Member
Does the parameter have to be variant?
-
Nov 6th, 2000, 10:25 AM
#4
Thread Starter
Addicted Member
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."
-
Nov 6th, 2000, 10:30 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|