|
||||||
VBScript and the ASCII Greek AlphabetHow to Display Greek Letters on a Web Site by Using VBSriptGreek letters cannot be added directly to a web page - they need ASCII codes. And a little VBScript code makes life a lot easier.
Normally any web site developer can add informatio to a web page by typing text and by using the letters that they can see on their keyboards. However the Greek Alphabet is not like that. The web site developer will find keys for neither α nor ψ, and that means that they can't directly add something like: Circle Area = π * (Radius squared)
Or: sin (-θ) = -sine θ
For that they'll need to turn to ASCII Codes and, to make life a little simpler, they'll need some VBScript code. ASCII Codes and the Greek AlphabetASCII (American Standard Code for Information Interchange) code is added a web page's text and is interpreted by the web browser so that:
It's then just a matter of writing a little VBScript that will handle the ASCII codes for the web page designer. Defining the ASCII Codes for the Greek AlphabetThe names for the Greek letters can be stored in an array: Dim Letters : Letters = Array ( _
"Alpha","Beta","Gamma","Delta", "Epsilon", "Zeta", _
"Eta", "Theta", "Iota", "Kappa", "Lambda", "Mu", _
"Nu", "Xi", "Omicron", "Pi", "Rho", "Sigma", _
"Tau", "Upsilon", "Phi", "Chi", "Psi", "Omega")
There are also some important points to take into account:
And these important facts can be represented by a few variables: Dim l_start :l_start = 913
Dim l_end : l_end = l_start + ubound(Letters)
Dim l_space: l_space = 32
With those in place the programmer can use them in a function that will enable them to display the Greek letters with ease. A Function to Display Greek LettersThe requirements of the function are quite simple:
And so the first step is to give the function a suitable name and to define the variables to be used: Function greek_letter (name)
Dim I, L
The next step is to step through the array, comparing the input to each element in the array: For I = lbound(Letters) to ubound(Letters)
If ucase(Letters(I)) = ucase(name) Then
L = I
End If
Next
At the end of the process the index number of the letter will have been identified, and this can be used to create the correct ASCII code: If L <> "" Then
If name = lcase(name) Then
greek_letter = "&#" & Ascii_start + L + Ascii_space
Else
greek_letter = "&#" & Ascii_start + L
End If
Else
greek_letter = "undefined"
End If
End Function
This can be seen in action by creating an array of different possible inputs: Dim letter_list : letter_list = Array("Pi", "PI", "pi", "fi")
And then the array elements can be used as inputs to the function: Dim I
For I = lbound(letter_list) to ubound(letter_list)
document.write(letter_list(I) & ": " & greek_letter(letter_list(I)) & "<br>")
Next
The results can be seen in figure 1 at the bottom of this article, and they show how easily a web developer can work with Greek letters in a web page either individually or en mass as discussed in Display the Greek Alphabet with VBScript .
The copyright of the article VBScript and the ASCII Greek Alphabet in Computer Programming Languages is owned by Mark Alexander Bain. Permission to republish VBScript and the ASCII Greek Alphabet in print or online must be granted by the author in writing.
|
||||||
|
|
||||||
|
|
||||||