Wednesday, May 20, 2009

Hiragana

While studying Japanese I created this HTA a while back.
Here's the code:
<HEAD>
<TITLE>Hiragana - 2009-03-26</TITLE>
<HTA:APPLICATION
APPLICATIONNAME="Hiragana"
BORDER="thin"
CAPTION="yes"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
SCROLL="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
>
</HEAD>

<SCRIPT LANGUAGE="VBScript">
//Documentation goes here.
//Author: Henrik Falk

arrCharacterKeys = Array()

Set Characters = CreateObject("Scripting.Dictionary")

//304x
Characters.Add "a", "x3042"
Characters.Add "i", "x3044"
Characters.Add "u", "x3046"
Characters.Add "e", "x3048"
Characters.Add "o", "x304A"
Characters.Add "ka", "x304B"
Characters.Add "ga", "x304C"
Characters.Add "ki", "x304D"
Characters.Add "gi", "x304E"
Characters.Add "ku", "x304F"

//305x
Characters.Add "gu", "x3050"
Characters.Add "ke", "x3051"
Characters.Add "ge", "x3052"
Characters.Add "ko", "x3053"
Characters.Add "go", "x3054"
Characters.Add "sa", "x3055"
Characters.Add "za", "x3056"
Characters.Add "shi", "x3057"
Characters.Add "ji", "x3058"
Characters.Add "su", "x3059"
Characters.Add "zu", "x305A"
Characters.Add "se", "x305B"
Characters.Add "ze", "x305C"
Characters.Add "so", "x305D"
Characters.Add "zo", "x305E"
Characters.Add "ta", "x305F"

//306x
Characters.Add "da", "x3060"
Characters.Add "chi", "x3061"
Characters.Add "tsu", "x3064"
Characters.Add "te", "x3066"
Characters.Add "de", "x3067"
Characters.Add "to", "x3068"
Characters.Add "do", "x3069"
Characters.Add "na", "x306A"
Characters.Add "ni", "x306B"
Characters.Add "nu", "x306C"
Characters.Add "ne", "x306D"
Characters.Add "no", "x306E"
Characters.Add "ha", "x306F"

//307x
Characters.Add "ba", "x3070"
Characters.Add "pa", "x3071"
Characters.Add "hi", "x3072"
Characters.Add "bi", "x3073"
Characters.Add "pi", "x3074"
Characters.Add "fu", "x3075"
Characters.Add "bu", "x3076"
Characters.Add "pu", "x3077"
Characters.Add "he", "x3078"
Characters.Add "be", "x3079"
Characters.Add "pe", "x307A"
Characters.Add "ho", "x307B"
Characters.Add "bo", "x307C"
Characters.Add "po", "x307D"
Characters.Add "ma", "x307E"
Characters.Add "mi", "x307F"

//308x
Characters.Add "mu", "x3080"
Characters.Add "me", "x3081"
Characters.Add "mo", "x3082"
Characters.Add "ya", "x3084"
Characters.Add "yu", "x3086"
Characters.Add "yo", "x3088"
Characters.Add "ra", "x3089"
Characters.Add "ri", "x308A"
Characters.Add "ru", "x308B"
Characters.Add "re", "x308C"
Characters.Add "ro", "x308D"
Characters.Add "wa", "x308F"

//309x
Characters.Add "wi", "x3090"
Characters.Add "we", "x3091"
Characters.Add "wo", "x3092"
Characters.Add "n", "x3093"
//Characters.Add "vu", "x3094"

arrCharacterKeys = Characters.keys

constNumberOfHiragana = Characters.count
correctAnswerButton = ""
correctCharacterRomaji = ""

Sub AskQuestion
strAnswers = GetUniqueRandomNumber(4)
arrAnswers = split(strAnswers, ",")
Button1.value = arrCharacterKeys(arrAnswers(0) - 1)
Button2.value = arrCharacterKeys(arrAnswers(1) - 1)
Button3.value = arrCharacterKeys(arrAnswers(2) - 1)
Button4.value = arrCharacterKeys(arrAnswers(3) - 1)
correctAnswerButton = GetRandomNumber(1, 4)
correctCharacterRomaji = arrCharacterKeys(arrAnswers(correctAnswerButton - 1) - 1)
question.innerHTML = "&#" & GetHiragana(correctCharacterRomaji) & ";"
End Sub

Function CheckAnswer(number)
if correctAnswerButton = number Then
answer.innerHTML = "<FONT COLOR='green'>Correct!</FONT>"
else
answer.innerHTML = "<FONT COLOR='red'>Wrong!</FONT>"
end if
answer.innerHTML = answer.innerHTML & "<BR>" & "&#" & GetHiragana(correctCharacterRomaji) & ";" & " is pronounced " & correctCharacterRomaji
AskQuestion
End Function

Function GetRandomNumber(intLow, intHigh)
intLowNumber = intLow
intHighNumber = intHigh
Randomize
GetRandomNumber = Int((intHighNumber - intLowNumber + 1) * Rnd + intLowNumber)
End Function

Function GetRomaji(hiragana)
GetRomaji = Characters.item(hiragana)
End Function

Function GetHiragana(romaji)
GetHiragana = Characters.item(romaji)
End Function

Function GetUniqueRandomNumber(number)
On Error Resume Next
Set Dict = CreateObject("Scripting.Dictionary")
Do Until Counter = number
num = GetRandomNumber(1, constNumberOfHiragana)
Dict.Add num, num
If Err = 0 Then
Counter = Counter + 1
Else
Err.Clear
End If
Loop
a = Dict.Items
For i = 0 To Dict.Count -1
temp = temp & a(i) & ", "
Next
GetUniqueRandomNumber = left(temp, len(temp) - 2)
End Function

Sub Window_onLoad
window.resizeTo 180,210
AskQuestion
End Sub
</SCRIPT>

<BODY>
<CENTER>
<DIV ID="question"></DIV>
<TABLE>
<TR><TD><INPUT TYPE="button" STYLE="width:25" TITLE="" VALUE="" NAME="button1" onClick="CheckAnswer(1)"></TD>
<TD><INPUT TYPE="button" STYLE="width:25" TITLE="" VALUE="" NAME="button2" onClick="CheckAnswer(2)"></TD></TR>
<TR><TD><INPUT TYPE="button" STYLE="width:25" TITLE="" VALUE="" NAME="button3" onClick="CheckAnswer(3)"></TD>
<TD><INPUT TYPE="button" STYLE="width:25" TITLE="" VALUE="" NAME="button4" onClick="CheckAnswer(4)"></TD></TR>
</TABLE>
<DIV ID="answer"></DIV>
</CENTER>
</BODY>

Simply copy this code and put it into a file with a name ending in .hta

No comments: