Learning ASP

Well, it looks like I’m resigned to learning several new languages if I’m going to program in them for the next several years. So I figured out how to turn on the IIS in Windows Vista (dreadful OS, I know) and start the server up and running so I can practice before I start coding this coming Monday. If you have Vista then you can easily write and test your own ASP scripts without downloading a thing you just have to setup IIS. Here’s how you do it:

Setting up IIS for Vista

1) Go to your control panel > programs > turn windows features on or off

2) A box will popup with a bunch of expandable folders. Find the Internet Information Services and check the box. Also make sure the sub-folders Web Management Tools and World Wide Web Services is checked.

3) Say okay to the changes. A box will come up saying its configuring the changes. Might take a few minutes, just let it do its thing.

4) Once its done you’ll notice a new folder under C:\inetpub

5) Inside inetpub there should be several folders. Any work you do should go into the wwwroot folder. If you want it to be the page that loads by default you should call it default.asp which is synonymous with html’s index.html and php’s index.php.

6) If you want to look at your files all you have to do is go to http://localhost in your browser window. You shouldn’t see a 404 File Not Found error. If you did then something went wrong. It could be 1 of 3 things:

1. IIS wasn’t installed correctly

2. Your IIS server isn’t turned on (see further down)

3. Your permissions on the folder aren’t chmod 777

7) Before you can put up any ASP pages you need to do one more configuration. Go back to control panel > programs > turn windows features on or off. Find the Internet Information Services folder again and click the + to expand it. Click the + next to the folder World Wide Web Services and again on Application Development Features. Make sure all of those things are checked.

8) Click okay to save your changes. It’ll take a few minutes again. Once that’s done you can put in your own .asp pages and start programming to your heart’s content.

9) If you want to turn the server on or off you’ll need to run the server on. To do that you have to open the IIS manager. Go to control panel > system and maintance > internet information services manager. I suggest you put a copy on your desktop so its easier to get to later. On the right hand side of the IIS manager you’ll see text links that say start the server, restart the server, and stop the server. Use those to turn the server on, off, or reset it.

10) Take a look around the manager. You can change the settings in there if you’re an advanced user and know what you’re doing, otherwise I suggest you leave all the default settings. All done!

Active Server Pages (ASP)

These are a lot like PHP, everything is run server side before the page is returned to the browser so you’ll never actually see the ASP code when the html is displayed. I’m going to assume you’ve programmed before and the stuff below will make sense, when writing an ASP file make sure you put the .asp extension at the end. ASP looks a lot like Visual Basic (VB) so there’s not much new to learn. For an editor I use notepad++, notepad or vim but you can use pretty much any text editor out there.

Tags

Start tags and end tags for asp scripts are <% and %>.

Base Encoding Language

You can change the coding language from VB to Javascript. By default its VB but if you’d like to use javascript you need to include this at the top of every ASP page:

<%@ language=”javascript” %>

Comments

All comments start with a single quote (‘) and can only be 1 line long. I’m sure there’s a way to do a block quote but I haven’t figured it out yet:

‘This is a comment

Variables

Declaring a variable is easy, although so far I haven’t found any way to declare and set a variable at the same time. Perhaps you can’t. Capitalization is important in ASP, don’t neglect it!:

dim varname

varname = “mystring goes here”

varname = 2

varname = 7.14

Writing Text & Variables

In order to write to the screen you have to use the response object. If you want to concatenate variables into a string you have to use the & sign. You can include any of the regular html tags as well. If you use a double quote (“) make sure you escape it:

dim mystring

mystring = “Hello”

response.write(“<b>” & mystring & ” world</b>”)

Arrays

These have a weird syntax in my opinion but who am I to judge?

dim length
length = 3

response.write(“this is an array syntax: <br/>”)

dim array(length),i
array(0) = “Hey”
array(1) = ” There”
array(2) = ” World!”

‘Print out the array

For i = 0 to length
response.write(array(i) & “<br />”)
Next

You may also like...

Leave a Reply