|
 |
asp_web_howto thread: ByRef Arguments
Message #1 by jstmehr4u3@a... on Tue, 11 Feb 2003 04:59:44 +0000
|
|
I have built a class module in Visual basic. One function takes in a variable
ByRef as a String datatype (strReturn).
The function tests to make sure all other data is properly defined if not, the
function passes the error back to the client through the strReturn variable.
I made a vb project, set my reference, and tested the class module.(or at this
point it was a dll) Everything worked. the String variable sent to the class
module was returning with correct messages.
When I use an asp page, I try to reference the same dll and I get multiple
errors. I will show you the code, and the error message that was given to me. I
will start with the class module code.
Here is the Class Code (l_ variables are local, prv are private properties):
Public Function InsertNewStatus(ByRef ReturnString As String, _
Optional ByVal l_Description As String, _
Optional ByVal l_StatusType As String, _
Optional ByVal l_ISActive As Boolean) As Boolean
On Error Resume Next
If prvDescription = "" And l_Description = "" Then
ReturnString = "InsertNewStatus.Description is improperly defined."
InsertNewStatus = False
Exit Function
End If
If prvStatusType = "" And l_StatusType = "" Then
ReturnString = "InsertNewStatus.StatusType is improperly defined."
InsertNewStatus = False
Exit Function
End If
End Function
Here is the VB code that works:
Dim nStatus As OEMaintenance.Status
Set nStatus = New OEMaintenance.Status
nStatus.InsertNewStatus strReturn, "PAID", "PAYMENT", True
MsgBox strReturn
Set nStatus = Nothing
Here is the ASP (VBScript) code that doesn't work:
Dim nStatus, ret, strReturn
Set nStatus = server.CreateObject("OEMaintenance.Status")
strReturn = "Not working"
nStatus.IsActive = true
nStatus.StatusType = "PAYMENT"
if nStatus.InsertNewStatus(strReturn) then
Response.Write strReturn
else
Response.Write strReturn
end if
Set nStatus = Nothing
Here is the error message
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'InsertNewStatus'
/Maintain/Statuses.asp, line 13
I can do this: strReturn = CSTR(strReturn) to make sure the variable is a
String, instead of variant, and still get the same number. the ByRef String
variable (strReturn) is required, and is the only one required. Currently I am
not setting the Description, so I should be getting a message back saying
Description is not currently defined.
If I do:
If nStatus.InsertNewStatus("hi") it works, but obviously won't send me a
message.
Is there any reason why I can't send a variable into a dll ByRef using ASP?
TIA-
Mike S.
Message #2 by "Ken Schaefer" <ken@a...> on Tue, 11 Feb 2003 16:33:48 +1100
|
|
What if you change the method signature in your function so that it accepts
a variant strReturn, not a string.
There are no strings in ASP. Even if you do CStr() you still have a variant
(of subtype String)
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <jstmehr4u3@a...>
Subject: [asp_web_howto] ByRef Arguments
: I have built a class module in Visual basic. One function takes in a
variable
: ByRef as a String datatype (strReturn).
:
: The function tests to make sure all other data is properly defined if not,
the
: function passes the error back to the client through the strReturn
variable.
:
: I made a vb project, set my reference, and tested the class module.(or at
this
: point it was a dll) Everything worked. the String variable sent to the
class
: module was returning with correct messages.
:
: When I use an asp page, I try to reference the same dll and I get multiple
: errors. I will show you the code, and the error message that was given to
me. I
: will start with the class module code.
:
: Here is the Class Code (l_ variables are local, prv are private
properties):
: Public Function InsertNewStatus(ByRef ReturnString As String, _
: Optional ByVal l_Description As String, _
: Optional ByVal l_StatusType As String, _
: Optional ByVal l_ISActive As Boolean) As
Boolean
: On Error Resume Next
: If prvDescription = "" And l_Description = "" Then
: ReturnString = "InsertNewStatus.Description is improperly
defined."
: InsertNewStatus = False
: Exit Function
: End If
: If prvStatusType = "" And l_StatusType = "" Then
: ReturnString = "InsertNewStatus.StatusType is improperly defined."
: InsertNewStatus = False
: Exit Function
: End If
: End Function
:
: Here is the VB code that works:
: Dim nStatus As OEMaintenance.Status
: Set nStatus = New OEMaintenance.Status
: nStatus.InsertNewStatus strReturn, "PAID", "PAYMENT", True
: MsgBox strReturn
: Set nStatus = Nothing
:
: Here is the ASP (VBScript) code that doesn't work:
: Dim nStatus, ret, strReturn
: Set nStatus = server.CreateObject("OEMaintenance.Status")
: strReturn = "Not working"
: nStatus.IsActive = true
: nStatus.StatusType = "PAYMENT"
: if nStatus.InsertNewStatus(strReturn) then
: Response.Write strReturn
: else
: Response.Write strReturn
: end if
: Set nStatus = Nothing
: Here is the error message
: Microsoft VBScript runtime error '800a000d'
:
: Type mismatch: 'InsertNewStatus'
:
: /Maintain/Statuses.asp, line 13
:
: I can do this: strReturn = CSTR(strReturn) to make sure the variable is a
: String, instead of variant, and still get the same number. the ByRef
String
: variable (strReturn) is required, and is the only one required. Currently
I am
: not setting the Description, so I should be getting a message back saying
: Description is not currently defined.
:
: If I do:
: If nStatus.InsertNewStatus("hi") it works, but obviously won't send me a
: message.
:
: Is there any reason why I can't send a variable into a dll ByRef using
ASP?
:
: TIA-
: Mike S.
Message #3 by jstmehr4u3@a... on Sat, 22 Feb 2003 06:28:22 +0000
|
|
Ok, after much thought / research / coding and recoding I have found that
solution.
In the DLL change the BYREF argument to accept the datatype VARIANT. (Or by not
explicitly stating a datatype.) But, the key is that you can't act on that
variable sent BYREF. (I have www.15seconds.com to thank)
You have to declare a local variable to act on in the DLL, then reassign the
value to the variable sent BYREF. For instance:
Public function InsertText(byref ReturnMessage, byval Message)
dim TempString as string
TempString = ReturnMessage
if Message = "" then
TempString = "InsertText.Message is improperly Defined."
else
TempString = "InsertText Passed."
end if
ReturnMessage = TempString
end function
That works.
Mike - ENJOY!
> What if you change the method signature in your function so that it accepts
> a variant strReturn, not a string.
>
> There are no strings in ASP. Even if you do CStr() you still have a variant
> (of subtype String)
>
> Cheers
> Ken
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> From: <jstmehr4u3@a...>
> Subject: [asp_web_howto] ByRef Arguments
>
>
> : I have built a class module in Visual basic. One function takes in a
> variable
> : ByRef as a String datatype (strReturn).
> :
> : The function tests to make sure all other data is properly defined if not,
> the
> : function passes the error back to the client through the strReturn
> variable.
> :
> : I made a vb project, set my reference, and tested the class module.(or at
> this
> : point it was a dll) Everything worked. the String variable sent to the
> class
> : module was returning with correct messages.
> :
> : When I use an asp page, I try to reference the same dll and I get multiple
> : errors. I will show you the code, and the error message that was given to
> me. I
> : will start with the class module code.
> :
> : Here is the Class Code (l_ variables are local, prv are private
> properties):
> : Public Function InsertNewStatus(ByRef ReturnString As String, _
> : Optional ByVal l_Description As String, _
> : Optional ByVal l_StatusType As String, _
> : Optional ByVal l_ISActive As Boolean) As
> Boolean
> : On Error Resume Next
> : If prvDescription = "" And l_Description = "" Then
> : ReturnString = "InsertNewStatus.Description is improperly
> defined."
> : InsertNewStatus = False
> : Exit Function
> : End If
> : If prvStatusType = "" And l_StatusType = "" Then
> : ReturnString = "InsertNewStatus.StatusType is improperly defined."
> : InsertNewStatus = False
> : Exit Function
> : End If
> : End Function
> :
> : Here is the VB code that works:
> : Dim nStatus As OEMaintenance.Status
> : Set nStatus = New OEMaintenance.Status
> : nStatus.InsertNewStatus strReturn, "PAID", "PAYMENT", True
> : MsgBox strReturn
> : Set nStatus = Nothing
> :
> : Here is the ASP (VBScript) code that doesn't work:
> : Dim nStatus, ret, strReturn
> : Set nStatus = server.CreateObject("OEMaintenance.Status")
> : strReturn = "Not working"
> : nStatus.IsActive = true
> : nStatus.StatusType = "PAYMENT"
> : if nStatus.InsertNewStatus(strReturn) then
> : Response.Write strReturn
> : else
> : Response.Write strReturn
> : end if
> : Set nStatus = Nothing
> : Here is the error message
> : Microsoft VBScript runtime error '800a000d'
> :
> : Type mismatch: 'InsertNewStatus'
> :
> : /Maintain/Statuses.asp, line 13
> :
> : I can do this: strReturn = CSTR(strReturn) to make sure the variable is a
> : String, instead of variant, and still get the same number. the ByRef
> String
> : variable (strReturn) is required, and is the only one required. Currently
> I am
> : not setting the Description, so I should be getting a message back saying
> : Description is not currently defined.
> :
> : If I do:
> : If nStatus.InsertNewStatus("hi") it works, but obviously won't send me a
> : message.
> :
> : Is there any reason why I can't send a variable into a dll ByRef using
> ASP?
> :
> : TIA-
> : Mike S.
>
>
Message #4 by Imar Spaanjaars <Imar@S...> on Sat, 22 Feb 2003 14:23:11 +0100
|
|
Hi there,
Variables passed by reference should indeed be pass ByRef. However, you can
treat the passed reference as a local variable, so there is no need to
create a local copy of it.
If you look at your own sample, you could see that. In the end, you assign
ReturnMessage the value of TempString, so you _are_ acting on it.
Check out
http://support.microsoft.com/default.aspx?scid=KB;en-us;q197956
for a simple example of this.
Cheers,
Imar
At 06:28 AM 2/22/2003 +0000, you wrote:
>Ok, after much thought / research / coding and recoding I have found that
>solution.
>
>In the DLL change the BYREF argument to accept the datatype VARIANT. (Or
>by not
>explicitly stating a datatype.) But, the key is that you can't act on that
>variable sent BYREF. (I have www.15seconds.com to thank)
>
>You have to declare a local variable to act on in the DLL, then reassign the
>value to the variable sent BYREF. For instance:
>
>Public function InsertText(byref ReturnMessage, byval Message)
>dim TempString as string
>TempString = ReturnMessage
>if Message = "" then
> TempString = "InsertText.Message is improperly Defined."
>else
> TempString = "InsertText Passed."
>end if
>ReturnMessage = TempString
>end function
|
|
 |