Tuesday, June 24, 2014

Export Data in Excel with VBScript Classic ASP

As i found lot of articles on the Internet, how to export a page to Excel using VBScript Classic ASP. There are very simple way to Create excel page using vbscript with the help of given steps.

Step 1. 
<%
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=My_List.xls"
%>

Step 2. 
<html xmlns:x="urn:schemas-microsoft-com:office:excel">


Sunday, December 8, 2013

On Error Statement | Classic ASP | ASP | VB Script

On Error Statement in VB Script

Hello friends, let us start to learn about "On Error Resume Next", as we know run-time errors, stopped code and display error message. Some times we need to handle such type of Errors, in some cases.

"On Error Resume Next" Statement provides the execution to continue with the statement immediately following the statement that caused the run-time error. In other words we can say "On Error Resume Next" statement is error-handling routine inline within the procedure.

On Error Resume Next
Err.Raise 6 ' Raise an overflow error.
MsgBox "Error # " & CStr(Err.Number) & " " & Err.Description
Err.Clear ' Clear the error.

Tuesday, November 5, 2013

Dynamic Splash Page Using HTML CSS & Javascript with source Code

Dynamic Splash Page Using HTML CSS & Javascript with source Code

Hello Friends, lets us learn splash screen effects using Html, CSS & javascript. Now days we saw all major web sites like news sites, astrology sites, conference... etc uses of One time open pop-up (a small window) open. Now we are going to create so lets us start first Css page then Html page Then Javascript.

There are some segments of One time open pop-up page, collcet it in one page and run your browser.

Css Part:
#popup0 {
visibility: hidden;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
text-align: center;
z-index: 200;
}

#popup0 .box-area {
width: 700px;
margin: 100px auto;
background-color: #c04204;
background: -webkit-gradient(radial, center center, 0, center center, 460, from(#fd3803), to(#c04204));
background: -webkit-radial-gradient(circle, #fd3803, #c04204);
background: -moz-radial-gradient(circle, #fd3803, #c04204);
background: -ms-radial-gradient(circle, #fd3803, #c04204);
border: 5px solid #fff;
text-align: center;
-moz-box-shadow: inset 0 0 15px 10px #802c03;
-webkit-box-shadow: inset 0 0 15px 10px #802c03;
box-shadow: inset 0 0 15px 10px #802c03;
border-radius: 5px;
}

.close {
margin: -20px 0px 0 690px;
position: absolute;
display: block;
width: 30px;
height: 30px;
box-shadow: 0 0 0px #666;
border-radius: 100%;
background:url(close-button.png)no-repeat;
}

#popup0 h2 {
display: block;
padding-left: 15px;
margin: 0px auto 10px;
font-size: 36px;
color: #fff;
text-align:left;
}

#popup0 h3 {
display: block;
padding-left: 15px;
margin: 0px auto 10px;
font-size: 18px;
color: #fff;
text-align:left;
}

.header-area {
border-bottom: 0px solid #ddd;
padding: 10px 0 0;
}

.footer-area {
border-top: 0px solid #ddd;
padding: 10px 0;
}

.col2 {
float: right;
width: 100%;
height: 400px;
}

#overlay0 {
visibility: hidden;
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
background: #000;
filter: alpha(Opacity = 70);
opacity: 0.7;
-moz-opacity: 0.7;
-khtml-opacity: 0.7;
z-index: 1;
}

HTML Part:
< div id="overlay0">< /div>
< div id="popup0">
< div class="box-area">
Your All pop-up page informetion will be here.
< div style="clear: both">
< /div>
< /div>
< /div>


Javsscript Part:
var interval = 20 * 20;
function MyTimer() {
//alert("Deepak Madheshiya");
var timeOutValue = setTimeout(function () {
showPopup('');
}, interval);
return timeOutValue;
}

function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}

else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
return null;
}

function setUrlCookies() {
MyTimer();
}

var ADV_CODE = "01";
var advcode;
var cookiesname = ["ishowadv0"];
var cookiesvalues = new Array();
var overlayid = ["overlay0"];
var popupid = ["popup0"];
function showPopup() {
var datetime = new Date();
for (var i = 0; i < cookiesname.length; i++) {
cookiesvalues[i] = readCookie(cookiesname[i]);
if (cookiesvalues[i] == "" || cookiesvalues[i] == null) {
advcode = cookiesname[i];
ovr = document.getElementById(overlayid[i]);
pop = document.getElementById(popupid[i]);
ovr.style.visibility = (ovr.style.visibility == "visible") ? "hidden" : "visible";
pop.style.visibility = (pop.style.visibility == "visible") ? "hidden" : "visible";
createCookie("lastadvshowonday", datetime.getDate(), 1);
break;
}
}
}
function closePopup(tag, tagvalue, overlayidpass, popupidpass) {
document.getElementById(overlayidpass).style.visibility = 'hidden';
document.getElementById(popupidpass).style.visibility = 'hidden';
CreateClickSession(tag, tagvalue);
}
function CreateClickSession(tagname, tagvalue) {
createCookie(advcode, "false", 1);
}

Sending email using CDOSYS in Classi ASP | The transport failed to connect to the server."

CDO.Message - "The transport failed to connect to the server." | CDO.Message.1 error '80040213' | ASP Sending e-mail with CDOSYS

Hello friends, today we learn new thing which is related to mail sending object in Classic ASP. In Classic ASP there are a CDOSYS, built-in component in Classis ASP. This component is used to send e-mails with ASP.

How to create CDOSYS object?
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
myMail.TextBody="This is a message."
myMail.Send
set myMail=nothing
%>

How to Send a text e-mail with Bcc and CC fields:
Simply Add following code in Above code myMail.Bcc="someoneelse@somedomain.com" myMail.Cc="someoneelse2@somedomain.com"

Some misc code:
Sending an HTML e-mail that sends a webpage from a website:
myMail.CreateMHTMLBody "http://www.w3schools.com/asp/"
Sending an HTML e-mail that sends a webpage from a file on your computer:
myMail.CreateMHTMLBody "http://www.url.com/test.asp/"

Sending a text e-mail with an Attachment:
myMail.AddAttachment "c:\mydocuments\test.txt"

Sending a text e-mail using a remote server:
<% Set myMail=CreateObject("CDO.Message") myMail.Subject="Sending email with CDO" myMail.From="mymail@mydomain.com" myMail.To="someone@somedomain.com" myMail.TextBody="This is a message." myMail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2 'Name or IP of remote SMTP server myMail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com" 'Server port myMail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25 myMail.Configuration.Fields.Update myMail.Send set myMail=nothing %>

CDO.Message.1 The transport failed to connect to the server ?

If you got such type of error check out following points:
This is a network related error. Application cannot connect to the mail server (cdoSMTPServer)

  • Is a valid SMTP Server?
  • Be sure the server System.Web.Mail is executing on can connect to the mail server. May be firewalls or proxy servers can get in the way.
  • Specifying the value via IP address. Poor DNS resolution can sometimes hinder name lookups.
  • Make sure the that the mail server is running at port 25.
  • If you did not specify a SmtpMail.SmtpServer property, or if SmtpMail.SmtpServer points to "localhost" (or the equivalent), be sure the SMTP Service is running on port 25.
  • For testing purposes change the MailMessage.From and MailMessage.To properties to an address that exists on SmtpMail.SmtpServer. Some times this exception is thrown, when it really is a relay issue.

Thursday, October 24, 2013

Web Storage Demo With Example using HTML 5

Web Storage Demo With Example using HTML 5
Hello friends, Today we will start to learn new topic using Web Storage Using HTML 5 with Example. So that you can learn step by step. Now Let us start to play web Storage in Html 5.
We are assuming that you know HTTP session cookies. There are two mechanisms by HTML 5, similar to HTTP session cookies. But there are some Draw Backs.
First is that Cookies are include with HTTP request so there are problems to slow down your web sites by transmitting the same data.
Second is that sending data not encrypted over the internet and also Cookies are limited data transmission 4 kb. There are mot enough to store required data.
So, HTML 5 provides to handle Such type of situations using session storage and local storage.
What is Session Storage?
It is designed for scenarios where the user is carrying out a single transaction. but user can be carrying out multiple transactions in different windows at the same time.

For Example: Use Given Code in body section.
Hello friends, Today we will start to learn new topic using Web Storage Using HTML 5 with Example. So that you can learn step by step. Now Let us start to play web Storage in Html 5.
We are assuming that you know HTTP session cookies. There are two mechanisms by HTML 5, similar to HTTP session cookies. But there are some DrawBacks.
First is that Cookies are realated to HTTP request so there are problems to slow down your web sites by transmitting the same data.
Second is that sending data unencrypted over the internet and also Cookies are limited data transmission 4 kb. There are mot enough to store required data.
So, HTML 5 provides to handle Such type of situations using session storage and local storage.
What is Session Storage?
It is designed for scenarios where the user is carrying out a single transaction. but user can be carrying out multiple transactions in different windows at the same time.
For Example: Use Given Code in script section.

< script type="text/javascript"> if( sessionStorage.hits ){ sessionStorage.hits = Number(sessionStorage.hits) +1; }else{ sessionStorage.hits = 1; } document.write("Total Hits :" + sessionStorage.hits );


 
Refresh the page to increase number of hits. Close the window and open it again and check the result. Refresh the page to increase number of hits. Close the window and open it again and check the result. What is Local Storage? It is designed for storage that spans multiple windows, and lasts beyond the current session. For Example: < script type="text/javascript"> if( localStorage.hits ){ localStorage.hits = Number(localStorage.hits) +1; }else{ localStorage.hits = 1; } document.write("Total Hits :" + localStorage.hits ); < /script>

Refresh page to increase no of hits.

Close the window and open it again and check the result and see magic.

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