ASP: Progress Bar


Introduction

Author: Martin Warning
Year: 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: The following code is an example to display the letters of the alphabet:
<%
' Declare variables
Dim i

' Loop through all characters
For i = 0 To 25
	Response.Write(Chr(65+i))
Next
%>
Example 1: See it in action

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
%>
Example 2: See it in action

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)%>
Example 3: See it in action

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)%>
Example 4: See it in action

This example builds on the last by adding some styling to the output of the function.




Pinternet.net: The world of beer on the Internet
Printed from: http://flyinglowlander.com/ (5/20/2012)
© FlyingLowander.com 2006 - 2012

Visit http://flyinglowlander.com for more XHTML, CSS, ASP and JavaScript examples, templates and tutorials.