Saturday, July 20, 2013

How to get detailed info about all online visitors that are currently browsing Using Classic ASP

Count the number of current users / sessions using Classic asp VB script

Count the number of current users / sessions:

<%
 sub session_onStart()  
    application.lock() 
    application("SessionCount") = application("SessionCount") + 1 
    application.unlock() 
 end sub 
sub session_onEnd()  
    application.lock() 
    application("SessionCount") = application("SessionCount") - 1 
    application.unlock()  
end sub 
sub application_onStart()  
    ' No need to lock in onStart() 
     application("SessionCount") = 0  
end sub 
%>

Note: to know number of current users / session Print    application("SessionCount") variables

<%= application("SessionCount") %> 

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

What is eval() method in Classi ASP VB Script / How to Evaluate a String Dynamically - Change String at Run Time

Often we need to  Evaluate a String Dynamically , here Classic ASP  /  VB Script provides a power fool method named EVAL(), Let us see how to use Eval() method in Classic ASP / VB Script.


Const MYNAME = "Deepak Kumar Madheshiya"
Const MYNAME_HI = "दीपक कुमार मद्देशिया"

Dim LanguageCode: LanguageCode = 1
<%=GetString(MYNAME, LanguageCode))

OutPut: Deepak Kumar Madheshiya

LanguageCode = 0
<%=GetString(MYNAME, LanguageCode))

OutPut: दीपक कुमार मद्देशिया

Function GetString (MyValues, LanguageCode)

    If LanguageCode = "1" Then
        GetString = eval(MyValues & "_HI")
    Else
        GetString =eval(MyValues)
    End If    
End Function

Tuesday, July 9, 2013

Dynamically create input fields - jQuery

JQuery Provides,  to add or remove a textbox dynamically. The idea is very simple,  jQuery createElement(), html() and remove() method. See below given example : 


<html>


<head>
    <title>Dynamically create input fields - jQuery</title>
    <script src="/js/jquery-1.4.js"></script>
    <link rel='stylesheet' type='text/css' href='/styles.css'>
    <script type="text/javascript">
        var i;
        $(function() {
            var addDiv = $('#addinput');
            i = $('#addinput p').size() + 1;
            $('#addNew').live('click', function() {
            $('<p><input type="text" id="p_new" size="40" name="p_new_' + i + '" value="" placeholder="I am New" /><a href="#" class="mybutton" id="remNew">Remove</a> </p>').appendTo(addDiv);
                i++;
                return false;
            });

            $('#remNew').live('click', function() {
                if (i > 2) {
                    $(this).parents('p').remove();
                    i--;
                }
                return false;
            });
        });
        function fillHiddenField() {
            $('#MyTextBoxLength').val(i);
            return true;
        }
    </script>

</head>
<body>
<%
If request("Submit") <> "" Then

    dim iCount : iCount = Request("MyTextBoxLength")
    For i = 0 to (iCount-1)
      Response.Write  Request("p_new_"&i) &"<br/>"
    Next
    
End If
 %>
    <h2>
        Dynammically Add Another Input Box</h2>
<form id="two" name="two" class="asholder" action="test1.asp" method="post">
    <div id="addinput" class="ui-button-global">
        <p>
            <!--<input type="text" id="p_new" size="20" name="p_new" value="" placeholder="Input Value" /><a
                href="#" id="addNew">Add</a>-->
            <a href="2013-rashiphal-in-hindi.asp" id="addNew" class="ui-button icon arrowright">
            Add</a>
        </p>
        <input type="hidden" name="MyTextBoxLength" id="MyTextBoxLength" value="" />
    </div>
    <input type="submit" class="mybutton" name="Submit" value="Get Result" onclick="return fillHiddenField();" />
</form>    
</body>
</html>


How to Read RSS feed Using Classic ASP


Function BinaryToString(byVal Binary)
'--- Converts binary to text
'--- Set the return value in case of error
BinaryToString = ""
'--- Creates ADODB Stream data
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'--- Specify stream type data.
BinaryStream.Type = 1 '--- adTypeBinary
'--- Open the stream And write text/string data To the object
BinaryStream.Open
BinaryStream.Write Binary
'--- Change stream type to text
BinaryStream.Position = 0
BinaryStream.Type = 2 '--- adTypeText
'--- Specify  unicode data.
BinaryStream.CharSet = "UTF-8"
'--- Return converted text
BinaryToString = BinaryStream.ReadText
End Function



Sub GetMyData
Dim MyhorosignArray : MyhorosignArray = Array ("A","B","C","D","E","F","G","H","I","J","K","L")
Dim objHTTP, strBuff, objXML, objLst, intNoOfHeadlines, objHdl
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.Open "GET", "RSS-FEED-URL", False
objHTTP.Send
If objHTTP.Status = 200 Then strBuff = BinaryToString(objHTTP.ResponseBody)
Set objHTTP = Nothing
If Len(strBuff) > 0 Then
Set objXML = CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.LoadXML(strBuff)
If objXML.parseError.errorCode <> 0 Then
Response.Write objXML.parseError.errorCode & " (" & objXML.parseError.reason & ")"
Else
Set objLst = objXML.getElementsByTagName("item")
intNoOfHeadlines = objLst.length -1
For i = 0 To 11 'intNoOfHeadlines
Set objHdl = objLst.item(i)
Ref = objHdl.childNodes(0).text
Link = objHdl.childNodes(1).text
Text =  objHdl.childNodes(2).text
        Response.Write Text
Set objHdl = Nothing
Next
Set objLst = Nothing
End If
Set objXML = Nothing
End If
End Sub

Thursday, March 22, 2012

Response.Redirect Vs Server.Transfer



Response.Redirect Vs Server.Transfer




Server.Transfer: Transferring to another page using Server.Transfer conserves server resources. The transfer takes place on the server instead of forcing the browser to redirect to a new page. This means fewer HTTP requests coming through and can make your applications run more efficiently. Server.Transfer maintains to original URL in the browser.

Note:Only data transferred to a second ASP page are the ASP built-in objects and the ASP Error object values from the first request. Any variables declared by the first ASP page are not available in the second ASP page.

Server.Transfer has several advantages over Response.Redirect:
1) Because it saves a round trip between the server and the browser it's faster and reduces the load on the Web server.
2) The Response querystring and form collections are preserved during the transfer. As a result, you don't need to worry about reposting form and querystring data to the new page.

However, Server.Transfer does have a few disadvantages:

1) You can only use Server.Transfer to redirect to a page on the same Web server.
2) You can't pass a querystring to the new page. (However, remember that the querystring passed to the page executing the transfer will automatically be passed along to the new page.) If you try to pass a querystring to the new page, you will trigger an ASP error.
3) The browser is never notified of the new page, which can cause problems with relative links in some cases.
Note: Please 3rd point to noted very carefully



Wednesday, March 21, 2012

VBScript - ByVal Vs ByRef



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