ASP: Progress Bar
Introduction
Author: Martin WarningYear: 2008
License: Free
This code shows an example on how to create a list with all the letters in the alphabet. The concept is simple, it use the Chr() function to write the characters and uses a for next to loop through all the letters. This function could be use for navigational purposes where each letter is a link to a section on a website.
Code
Languages:- XHTML
- CSS
- ASP
- VBScript
<% ' Declare variables Dim i ' Loop through all characters For i = 0 To 25 Response.Write(Chr(65+i)) Next %>
The first example is the basics of this function. It writes the 26 letters of the alphabet in upper case. If you require the alphabet in lower case you can change Chr(65+i) to Chr(97+i).
The following code adds numbers:
<% ' Declare variables Dim i ' Loop through all numbers For i = 0 To 9 Response.Write(i) Next ' Loop through all characters For i = 0 To 25 Response.Write(Chr(65+i)) Next %>
In this example we add a for next to loop through the numbers.
The following code creates a function with parameters
<% Function fncDisplayAlphabet(blnNumbers,intCase) ' This function accepts the following variables ' blnNumbers, 1 to show numbers otherwise no numbers ' intCase, 0 None, 1 Upper Case, 2 Lower Case, 3 Both ' Declare variables Dim i ' See if numbers should be written If blnNumbers = 1 Then ' Loop through all numbers For i = 0 To 9 Response.Write(i) Next End If ' See if letters should be written If intCase <> 0 Then ' Lower case If intCase = 2 OR intCase = 3 Then ' Loop through all characters For i = 0 To 25 Response.Write(Chr(97+i)) Next End If ' Upper case If intCase = 1 OR intCase = 3 Then ' Loop through all characters For i = 0 To 25 Response.Write(Chr(65+i)) Next End If End If End Function %>and calling the function:
<%=fncDisplayAlphabet(1,3)%>
This example converts the code into a function that can be called. This funcion takes 2 parameters to customize the output. The first is blnNumbers that is used to indicate if numbers should be shown. intCase is used to allow characters to be shown and defines if in lower case, upper case or both. The display order can be changed by changing the order of the numbers, lower case and upper case sections in the function itself.
An example with formatting to display the output:
<%
Function fncDisplayAlphabet(blnNumbers,intCase)
' This function accepts the following variables
' blnNumbers, 1 to show numbers otherwise no numbers
' intCase, 0 None, 1 Upper Case, 2 Lower Case, 3 Both
' Declare variables
Dim i
' See if numbers should be written
If blnNumbers = 1 Then
' Loop through all numbers
For i = 0 To 9
Response.Write("<span class=""letter"">" & i & "</span>")
Next
End If
' See if letters should be written
If intCase <> 0 Then
' Lower case
If intCase = 2 OR intCase = 3 Then
' Loop through all characters
For i = 0 To 25
Response.Write("<span class=""letter"">" & Chr(97+i) & "</span>")
Next
End If
' Upper case
If intCase = 1 OR intCase = 3 Then
' Loop through all characters
For i = 0 To 25
Response.Write("<span class=""letter"">" & Chr(65+i) & "</span>")
Next
End If
End If
End Function
%>
and the CSS code in the <head></head>:
<style type="text/css">
.letter{font-size:20px;width:50px;height:35px;margin:10px;background-color:#dfd;color:#050;float:left;text-align:center;padding-top:15px;}
.letter:hover{background-color:#bdb;color:#f00;}
</style>
and calling the function:
<%=fncDisplayAlphabet(1,3)%>
This example builds on the last by adding some styling to the output of the function.
