Archive for 'Tutorial'

Classic ASP to Excel

Have you ever wondered how to go from a Classic ASP page to Excel? I have done this a lot usually someone in the office will ask, “Can I have the total profit of the month in a spreadsheet?” now you can handle this one of two ways go and copy all the data from the database one by one or you can extract the data and spit it out using ASP to Excel.

<%
‘The line below lets the browser know this is an Excel File
Response.ContentType = “application/vnd.ms-excel”
%>
<table>
<thead>
<tr>
<th style=”background-color:#CCCCCC;color:#FFFFFF;”>First Name</font></th>
<th style=”background-color:#CCCCCC;color:#FFFFFF;”>Last Name</font></th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
<tr>
<td>Steve</td>
<td>Smith</td>
</tr>
<tr>
<td>Frank</td>
<td>McCoy</td>
</tr>
</tbody>
</table>

Basically take the code above and paste it into your editor and save it as an ASP file run it and see the results.

Email Via Classic ASP

I know it has been a while since I sat down and wrote a decent post so tonight I figured let me discuss sending emails Classic ASP style. View the code below which will be explained in further detail:

<%
Dim strMailTo
Dim strMailSubject
Dim strMailBody
Dim objCDOMail ‘The CDO object

strMailSubject = “Test Via ASP”

strMailTo = Request.Form(”sendemail”)

strMailBody = “Hello World,”
strMailBody = strMailBody & “This is my first email.”
strMailBody = strMailBody & “Sent via ASP!!!”

Set objCDOMail = Server.CreateObject(”CDO.Message”)

objCDOMail.From = “mail@yourdomain.com”
objCDOMail.To = strMailTo
‘objCDOMail.Cc = “user@domain.com”
‘objCDOMail.Bcc = “user@domain.com”
objCDOMail.Subject = strMailSubject
objCDOMail.TextBody = strMailBody
objCDOMail.Send()
Set objCDOMail = Nothing
%>

Alright so the code above may looked complicated but it really isn’t. Basically the main part of this is the objCDOMail this is telling the server that you want to send a message via email. The variables dimed are just place holders for the objCDOMail parameters for example: strMailSubject is used to hold a string message for the subject line, objCDOMail.Subject.

First Letter Upper Case in Classic ASP

Today I want to illustrate a quick and easy way to change all first letters of words in a string to upper case using classic ASP.

<%
Function ChagetoUpperCase(X)
Dim lcstring
Dim oldcase
Dim NewArray
Dim newString
Dim IntegerI
Dim I

lcstring = CStr(LCase(X))
oldcase = ” ”
NewArray = Split(lcstring,” “)
For IntegerI = LBound(NewArray) To UBound(NewArray)
For I = 1 To Len(NewArray(IntegerI))

If Len(NewArray(IntegerI)) = 1 Then

newString = newString & UCase(NewArray(IntegerI)) & ” ”

ElseIf I=1 Then

newString = newString & UCase(Mid(NewArray(IntegerI), I, 1))

ElseIf I = Len(NewArray(IntegerI)) Then

newString = newString & Mid(NewArray(IntegerI), I, 1) & ” ”

Else

newString = newString & Mid(NewArray(IntegerI), I, 1)

End If

Next
Next
ChagetoUpperCase = Trim(newString)
End Function
%>

Then just call the function like this:

<%
Dim MyNewText
MyNewText = “hello everyone”

Dim NewOutPut
NewOutPut = ChagetoUpperCase(MyNewText)

Response.Write NewOutPut
%>

It should output this Hello Everyone. And that’s all there is to it.

Image Size from JavaScript to Classic ASP

I have spent the past day or so looking, thinking, and writing the perfect code that will return the dimensions of an image using JavaScript and place them in a cookie so that I may use it on an ASP page. Well after some research and thinking I came up with the following code.

<script type=”text/javascript”>
//Reference http://www.sovalid.com/blog
//Get and Assign Image
function GetImageSize(){
var img = new Image();
img.src = “http://www.google.com/intl/en_ALL/images/logo.gif”;
//Get Width and Height
wth = img.width;
hgt = img.height;

//Create the Two Cookies
document.cookie = “ImageWidth” + “=” +escape(wth)
document.cookie = “ImageHeight” + “=” +escape(hgt)

//Alert Width and Height as Test
wh=wth+” “+hgt;
alert(wh)
}

//Call Function
GetImageSize();
</script>

Reference my last post to see how to call the JavaScript cookie in Classic ASP. You can make the code as complex as you want this is just the basics, you can for example get the image from an ASP function instead of hard coding the image. You could also get the image from the page it self using document get element by id. Happy Coding.

Pass JavaScript Cookie to Classic ASP

Keeping up with yesterdays post I figured I would illustrate how to create a JavaScript cookie and pass it to Classic ASP.

This part was taken from http://www.w3schools.com for those of you that need a course on JavaScript Cookies:

<script type=”text/javascript”>
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + “=”);
if (c_start!=-1)
{
c_start=c_start + c_name.length+1 ;
c_end=document.cookie.indexOf(”;”,c_start);
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end));
}
}
return “”
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ “=” +escape(value)+((expiredays==null) ? “” : “; expires=”+exdate.toGMTString());
}

function checkCookie()
{
username=getCookie(’username’);
if (username!=null && username!=”")
{
alert(’Welcome again ‘+username+’!');
}
else
{
username=prompt(’Please enter your name:’,”");
if (username!=null && username!=”")
{
setCookie(’username’,username,365);
}
}
}
</script>

The real important part to take away from this is:

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ “=” +escape(value)+((expiredays==null) ? “” : “; expires=”+exdate.toGMTString());
}

Now we can edit this to what we need like so:

var exdate=new Date();
var CookieValue = ‘Hello World’

exdate.setDate(exdate.getDate()+1);
document.cookie=”CookieName”+ “=” +escape(CookieValue)+((’==null) ? “” : “; expires=”+exdate.toGMTString());

To call this Cookie all you need to do is:

<%
Response.Write Request.Cookies(”CookieName”)
%>

That’s all there is to it.

Classic ASP Cookies

Today I want to review the uses of classic ASP cookies and how to use them. Let us say that we want to save the last item a customer viewed for the next time they return. This is accomplished really easily, let us take a look.

Create the cookie on different item pages:

<%
‘On the item page at the bottom we want to create the cookie
Response.Cookies(”ItemNumber”) = 123

‘We want to keep the cookie for about 7 days
Response.Cookies(”ItemNumber”).Expires = Date() + 7
%>

To call the Cookie all you have to do is:

<%
Dim LastItem
LastItem = Request.Cookies(”ItemNumber”)
Response.Write LastItem
%>

Now here is something that you might find very useful, what if you wanted to pass this cookie along to multiple sub-domains? To do this we need to make some changes to the beginning code.

<%
‘On the item page at the bottom we want to create the cookie
Response.Cookies(”ItemNumber”) = 123

‘We want to keep the cookie for about 7 days
Response.Cookies(”ItemNumber”).Expires = Date() + 7

‘Pass to all sub-domains
Response.Cookies(”ItemNumber “).Domain = “.myserver.com”
%>

And that’s it.

A Href Link Popup

This is a JavaScript tutorial it is a very simple one, nothing really advanced, but a tutorial I think that I should write about. Usually when I search for a popup window using a href link I usually find examples where you have to add a code in the head tag then add the call to your intended link in the body tag, shown below.

Within the head tag Add this

<SCRIPT TYPE=”text/javascript”>
<!–
function popup(Newlink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(Newlink) == ’string’)
href=Newlink;
else
href=Newlink.href;
window.open(href, windowname, ‘width=300,height=300,scrollbars=yes’);
return false;
}
//–>
</SCRIPT>

Within the body tag add this

<A HREF=”your url” onClick=”return popup(this, ‘notes’)”>popup</A>

To me this is too much code to add to the head tag especially if you already use tons of JavaScript on your site along with multiple CSS files. So on my sites I tend to use the following code on a regular basis, shown below.

Within the body tag add this, that’s all

<a href=”javascript:void(0)” onclick=”window.open(’your url’,'windowname’,'width=300,height=300,top=25,scrollbars=yes’)”></a>

Working Example: Click Here

Quick Zombie Effect

Alright in this tutorial I will experiment in making a zombie effect. Let us start by looking for an image that you would like to apply the effect to, Skins.be.

  1. Create a copy of the image layer.
  2. Take the sponge tool and remove as much color as you can without losing some color.
  3. Now burn under and over the eyes to give a dark look.
  4. Next create a new blank layer.
  5. Apply dark make up effects on the eyes and lips using the brush tool setting the layer mode at Soft Light with opacity of 75%.
  6. Finally create a new blank layer and color in the image with a dark green setting this layer to Soft Light as well.

Quick Text Reflection

Now in this tutorial I will show you how to make a quick text reflection.

  1. Open Photoshop and create a new layer.
  2. Fill the background layer with a dark color for a better result.
  3. Then type the text you would like to apply the effect to.
  4. Next duplicate the layer.
  5. Then on the copied layer that is on top Edit > Transform > Flip Vertical.
  6. Nudge the top layer down until the two layers are separated bye about two spaces.
  7. On the top layer change the opacity to about 15%.
  8. Then resterize the top layer.
  9. Then make select about half of the top layer.
  10. While selected right click and choose Feather about 3 pixels or so.
  11. Then hit delete.
  12. And there you have it.


Cartoon Air Brush Look

Today I will show you a quick tutorial on how to make a photo look a cartoon but with an air brush type effect. So let us start off by finding an image that we want to apply the effect to, I went to Skins.be and found this image.

  1. First open the image in Photoshop
  2. Apply this effect Filter > Artistic > Poster Edges with these settings; Edge Thickness 4, Edge Intensity 1, and Posterization 6
  3. Finally using the Smudge Tool set at a strength of 17%, smudge away any marks from the skin.
  4. And that is it check it out below