|
||||||
Display the Greek Alphabet with VBScriptHow to Use VBScript to Display Tables of Greek Letters on a Web PageThe Greek alphabet cannot typed directly into a web page. Instead ASCII codes must be used. So, intead of having to remember 48 separate codes just use VBScript code.
A web site designer will often wish to use Greek letters on their web pages. For example, they may want to display something like: Circle Circumference = 2 * π * Radius
or: a sin θ + b cos θ = A sin ( θ + α)
If that's the case then they'll need to know some ASCII (American Standard Code for Information Interchange) codes, for example:
On the other hand, if they don't want to remember these codes (and the other 46 codes for all of the upper and lower case Greek letters) then they can just write some VBScript to display all of the Greek letters in a table. The Greek LettersThe first step is to create an array containing the names of the Greek letters: Dim Letters : Letters = Array( _
The ASCII codes for the letters lie in two ranges:
And so with this knowledge, and the array of letter names, the developer can create the operating parameters of the VBScript functionality: Dim Ascii_start : Ascii_start = 913 ' Range starts at 913
Dim Ascii_end : Ascii_end = Ascii_start + ubound(Letters) 'Range ends at 936
Dim Ascii_space: Ascii_space = 32 'Lower case range is 32 higher than upper case
The programmer can now uses this information to create the required subroutines and functions. A VBScript Subroutine for Displaying all of the Greek Letters in a TableIt's interesting to view all of the Greek letters in a table on a web page, and a programmer can achieve this easily with VBScript. The programmer must, therefore, add a suitably named subroutine and the local variables that it will require: Sub all_greek_letters
Dim L0 'Letter number
Dim L1 'Upper Case range start
Dim L2 'Lower Case range start
Next the table headings can be defined: document.write ("<table width=100%>")
document.write ("<th>Name")
document.write ("<th>HTML Code<th>Upper Case Greek Letter")
document.write ("<th>HTML Code<th>Lower Case Greek Letter")
The code for displaying the Greek letters is quite simple. It:
And this code will be something like: For L1 = Ascii_start to Ascii_end
L0 = L1 - Ascii_start L2 = L1 + Ascii_space
document.write ("<tr>")
document.write ("<td align=center>" & Letters(L0) & "</td>")
document.write ("<td align=center>&#" & L1 & "</td>")
document.write ("<td align=center>&#" & L1 & "</td>")
document.write ("<td align=center>&#" & L2 & "</td>")
document.write ("<td align=center>&#" & L2 & "</td>")
document.write ("</tr>")
Next
document.write ("</table>")
End Sub
The subroutine itself is called by adding the code: all_greek_letters
If this VBScript is added to a web page then a table containing all of the Greek letters (in both upper and lower case) and their ASCII codes will be displaying (as shown in figure 1 at the bottom of this article). Of course, any programmer's should now be thinking about how to convert the above code, so that they can display α to ψ as individual letters rather than all of the letters at the same time.
The copyright of the article Display the Greek Alphabet with VBScript in Computer Programming Tutorials is owned by Mark Alexander Bain. Permission to republish Display the Greek Alphabet with VBScript in print or online must be granted by the author in writing.
|
||||||
|
|
||||||
|
|
||||||