Tuesday, April 06, 2010

ASP: Determining Variable Types with TypeName Function

If you've been working in ASP for any length of time, you know you don't have to type variables. You just declare them using the DIM statement. Heck, you don't even have to declare them if you don't want to (but I don't recommend it).

But what if you're perofmring some sort of calculation on a variable, or you're doing some sort of boolean check after manupulating it or getting a value from a database? Or you want to put it into a database field that's been typed and you don't know if it matches and you need to convert it first?

Well here's a handy function you can use to determine what type of varient the actual value of the variable is: TypeName()

It works like this:
var = 1
Reponse.write TypeName(var)
In this case, the output would be
Integer
I've found this to be especially handy when dealing with values being returned from a database or when validating variable type to prevent an SQL injection attack.

Let's say I'm using a QueryString variable to pass a record id to a page, and then I use that id to pull a record from the database. So my URL might look like:
http://www.MySite.com/results.asp?rid=223
In this case I can validate it by
intRecordID = Request.QueryString("rid")
If TypeName(intRecordID) = Integer Then....
It's also handy when telling the differnece between NULL and an Empty String. Anyone who's done development knows that just because there's nothing in the variable doen't mean it's actually empty, since NULL and Empty are treated differently.
If TypeName(TheVar) = Empty then...
or
If TypeName(TheVar) = NULL Then...
Handy, especially whn doing some sort of conditional aggregate of data from a database pull where you're combining things.

Here's a list of all the different types than can come back:

Empty
Null
Integer
Long Integer
Single
Double
Currency
Date String
Object
Eror
Boolean
Variant
Byte
Array

Wednesday, March 31, 2010

Don't be a Programmer

My advice as a software engineer since 1999: Get out of programming as fast as you can. Go into Server Admin or Network Security.

Programmers are the ditch diggers of IT. In my experience, at least working in the large corporation world, they are treated like crap, constantly saddled with unrealistic expectations and time lines, and inevitably take direction from someone who has absolutely no experience or knowledge of programming. Even if your immediate manager is a Good Guy, his boss won't be, or his boss.... point being sooner or later as you go up the chain you run into that guy who thinks all programmers are liars and are way overpaid, and everything is easy and should only take 1 day. And testing? We don't have time to test! We need to DELIVER!

Sales people will promise the clients anything to get the sale, then dump it in your lap, take their fat commission, and go on vacation, leaving you to eat the shit sandwich they just made.

Customers will want more more more faster faster faster and, since they write the checks, that's what you'll have to produce. Scope creep? More like scope sprint. And forget about getting extra time. You don't need extra time! It's just a few additional features. How hard can it be?

You'll bust your ass for 8 months to build an in-house accounting system that saves the company 3 million a year and your bonus will be a shitty free breakfast with the CEO. And then the programmers start disappearing because guess what? The system is built and we don't need all those programmers any more!

That's right, programmers are the first to go. They're over paid and no one understands what they do anyway. Beside, you only need carpenters when you're building the house. Once the house is built....

But guess what. The Network still has to Network and be secure, and the Servers need to Server.....

So bail on programming NOW, before it's too late.

If you absolutely, positively are convinced things will be different for you (and they won't) and you want to stick it out, got for a hybrid like database development/admin. You can do database development and design to satisfy your desire to create, but when there's no development to do and all the programmers are getting fired, they'll still need a DBA to keep the Database up and running....

Tuesday, March 02, 2010

Google Keyword Competition Script

In addition to web development, I also do my fair share if Internet marketing and Search Engine Optimization consultation. One of the methods at the core of SEO is keyword research. There are plenty of tools out there for doing keyword research - Micro Niche Finder, Keyword Elite, Market Samauri, just to name a few - but I prefer to do it myself using the Google Adwords Keyword Tool (GAKT) and Google search.

I use GAKT to identify likly keywords related to whatever market I'm researching, and I then go straight to Google to check:

Broad competition (total number of results on a search performed without quotes)
Exact competition (total number of results on a search performed with quotes around the keyword)
AllInUrl (allinurl:keyword)
AllInTitle (allintitle:keyword)
AllInAnchor (allinanchor:keyword)
AllInText (allintest:keyword)

These searches bring back numbers that let me evaluate the competetiveness of the keyword - that is how easy it might be to get well ranked in Google's results.

As you can imagine, typing all that is a pain, so just yesterday I wrote a little ASP script that goes out and gets all the info for you:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Google Keyword Competition Stats </TITLE>
<style type="text/css">
body {font: normal 12pt arial}
</style>
<!--
If would be nice if you left in the below, but if you get some sort of savage glee by deleting it, then have at it.
Script by Dave, AKA Wedango on the WarriorForum
ASP blog: http://retrowebdev.blogspot.com/
He also does web sites and stuff: Webdango.com
-->
</HEAD>

<BODY>
Enter Your Keyword
<br><br>
<FORM METHOD=POST ACTION="goog-stats.asp">
<INPUT TYPE="text" NAME="keyword">
<INPUT TYPE="submit">
</FORM>
<%
Dim strKeyword

strKeyword = ""
strKeyword = Trim(Request.form("keyword"))

If strKeyword <> "" Then
Dim objXMLHTTP, strURL, iBroadComp, iExactComp, iAllInURL, iAllInTitle, iAllInAnchor

Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")

Response.write("Results for <b>"&strKeyword&"</b><br><br>")
'broad competition
Response.write("Broad Competition: "& fKeywordStats("broad",strKeyword) &"<br>")

'exact competition
Response.write("Exact Competition: "& fKeywordStats("exact",strKeyword) &"<br>")

'allintitle
Response.write("All In Title: "& fKeywordStats("allintitle",strKeyword) &"<br>")

'allinurl
Response.write("All In URL: "& fKeywordStats("allinurl",strKeyword) &"<br>")

'allinanchor
Response.write("All In Anchor: "& fKeywordStats("allinanchor",strKeyword) &"<br>")

'allincontent
Response.write("All In Text: "& fKeywordStats("allintext",strKeyword) &"<br><br>")

Set objXMLHTTP = nothing
End If
%>

<%
Function fKeywordStats(TheType, TheKeyword)
Dim strURL, strHTML, vStart, vEnd, vLength

vStart = 0
vEnd = 0
vLength = 0

Select Case TheType
Case "broad"
strURL = "http://www.google.com/search?hl=en&q="&strKeyword&""
Case "exact"
strURL = "http://www.google.com/search?hl=en&q="""&strKeyword&""""
Case "allinurl"
strURL = "http://www.google.com/search?hl=en&q=allinurl%3A"&strKeyword&""
Case "allintitle"
strURL = "http://www.google.com/search?hl=en&q=allintitle%3A"&strKeyword&""
Case "allinanchor"
strURL = "http://www.google.com/search?hl=en&q=allinanchor%3A"&strKeyword&""
Case "allintext"
strURL = "http://www.google.com/search?hl=en&q=allintext%3A"&strKeyword&""
End Select

objXMLHTTP.Open "GET", strURL, false
objXMLHTTP.Send
strHTML = objXMLHTTP.responseText

vStart = Instr(strHTML,"</b> of about <b>") + 17
vEnd = Instr(strHTML,"</b> for <b>")
vLength = vEnd - vStart

If vStart > 17 then
strHTML = Mid(strHTML,vStart,vLength)
Else
strHTML = "no results"
End If

fKeywordStats = strHTML
End Function
%>
</BODY>
</HTML>


The script has to be run on a Windows server with the Microsoft.XMLHTTP object enabled.

Name the script goog-stats.asp. If you name it something different, you have to change the name in the FORM ACTION value.

Happy keyword hunting!

Thursday, January 21, 2010

TextBroker.com Review

I've entered 2010 with a new-found determination to make some extra dough on the net, hence my post about doing sites site again (get yours starting at only $300!).

Part of the plan is to make some money building keyword optimized content sites and populate them with AdSense.

Of course the key to content is to actually have content. Rather than try to crank out 300 words or so on stuff I know nothing about, I've been using a content for hire service that , so far, I'm pleased as punch with.

TextBroker.com is pretty nifty. Sign up, add fund through PayPal, and commission articles. You add an order, specify the the title and what you want it to be about, and choose a quality rating . The higher the rating you choose, the more the article costs, with the choices being from 2 stars to 5 stars.

To put it into perspective, I ask for article from 250 - 300 words and they've been running my right around $5. I've only rejected one article out of the dozen or so I've commissioned.

I tried a couple of others (more about them later) but TextBroker.com is the best by a ling shot so far.

Webdango Tampa Web Development

For anyone who's interested, I'm trying to get some side work again setting up web sites for folks. I can do custom work (for a price) but right now I'm offering custom sites starting at only $300. And if you want an ecommerce site, I can do that too.

I can also host if you need it....

Yeah, it's listed as Webdango Tampa Web Development, but that's so I can get the keyword Tampa Web Development in there....

So if you're looking for a professional looking site, hie thee over to Webdango and contact me.