Archive for June, 2009

My Laptop Digital Photo Frame

So I recently decided to try something that I have seen on the internet but with no real explanation as to how to accomplish this I figured let me try it out for myself. I got a laptop free of charge from my sister-in law she wasn’t using it any longer so I decided to convert it into a digital photo frame. I disassembled the IBM Thinkpad A21m, Intel Pentium 3 128mb of RAM really slow. All I basically needed was the motherboard, memory, hard drive, network adapter, and LCD screen. Once disassembled I purchased two mat boards and a custom shadow box frame. I then fastened the board to the mat using bolts from Home Depot along with the other necessary parts. On the second mat board I cut a hole for the LCD to be shown through about 14 inches. I then duct taped the screen to the mat board and placed it in the 15 inch custom frame. And placed the boarded mat on the top using spacers in between not to put pressure on the LCD screen. The only down side is that the power button is built on the keyboard so this had to stay on as well, see below for the final result, currently I am trying to trouble shoot a power issue I get to the windows login then it powers down I think it is a memory issue but I shall have to see.

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.