Showing posts with label Classic ASP. Show all posts
Showing posts with label Classic ASP. Show all posts

Saturday, July 13, 2013

VBScript - ByVal Vs ByRef / VBScript Passing Values ByRef or ByVal

Let Us See how we can get values by Reference and by Values :

In VBScript ByRef and ByVal:

<%
Function MyFunctionByRef(ByRef Myvalue)
      Myvalue = Myvalue + 1
End Function

Dim sendvalues : sendvalues = 3
Dim MyOutput: MyOutput = MyFunctionByRef(sendvalues)
Response.write "MyOutput: " & MyOutput  '4
%>

<%
Function MyFunctionByVal(ByVal Myvalue)
     Myvalue = Myvalue + 1
End Function

Dim sendvalues : sendvalues = 3
Dim MyOutput: MyOutput = MyFunctionByVal(sendvalues)
Response.write "MyOutput: " & MyOutput '4
%>



VBScript - ByVal Vs ByRef




Passing Parameters ByRef and ByVal

In VBScript, there are two ways values can be passed:
1) ByVal

2) ByRef

Using ByVal, we can pass arguments as values whereas with the use of ByRef, we can pass arguments are references.
ByVal:

the parameter is passed by value, thus the subroutine works with a copy of the original.
ByRef:

the parameter is passed by reference, thus the subroutine works directly with the original.


Example: Parameters By Value


Function GetValue( ByVal var )
var = var + 1
End Function

Dim x: x = 5

'Pass variable x to GetValue function ByVal
GetValue x

Response.write "x = " & x

Output: x = 5

Example: Parameters By Reference:


Function GetReference( ByRef var )
var = var + 1
End Function

Dim x: x = 5

'Pass the variable x to the GetReference function ByRef
GetReference x

Response.write x

Output: 6

Tuesday, November 29, 2011

Squishing onto a line: the colon :

Sometimes we need to reduce the human readability of our code. The colon will provides help to do this by letting we put multiple lines of ASP code onto a single line. Below is an example …..!! 



<%
Dim a
Dim b
Dim c
a=3 : b=25 : c=a-b : b=a*c : c=a*a-c+b : b=5*3*c*2/a
%>