(view source code of myfirsthta.hta as plain text)
body {
background-color: #fdfeff;
color: darkblue;
font-family: Calibri;
font-size: 12pt;
margin: 4em 3em;
}
Option Explicit
Sub CheckIfPrime( )
Dim i, intInput
intInput = document.getElementById( "InputNumber" ).value
If intInput < 3 Then
document.getElementById( "OutputResult" ).innerHTML = "Yes, " & intInput & " is a prime number."
Else
For i = 2 To intInput - 1
If intInput Mod i = 0 Then
document.getElementById( "OutputResult" ).innerHTML = "No, " & intInput & " is not a prime number."
Exit Sub
End If
Next
document.getElementById( "OutputResult" ).innerHTML = "Yes, " & intInput & " is a prime number."
End If
End Sub
Sub ValidateInput( )
Dim objRE, strInput
strInput = document.getElementById( "InputNumber" ).value
Set objRE = New RegExp
objRE.Global = True
objRE.Pattern = "[^\d]+"
If objRE.Test( strInput ) Then
strInput = objRE.Replace( strInput, "" )
document.getElementById( "InputNumber" ).value = strInput
document.getElementById( "OutputResult" ).innerHTML = "Enter a number, and click the ""Check"" button to check if it is a prime number."
End If
If strInput = "" Then
document.getElementById( "OutputResult" ).innerHTML = "Enter a number, and click the ""Check"" button to check if it is a prime number."
End If
Set objRE = Nothing
End Sub
Sub Window_OnLoad
window.resizeTo 640, 480
document.title = document.title & ", Version " & MyFirstHTA.Version
End Sub
</script>
<body>
<p><input type="text" id="InputNumber" onchange="ValidateInput" onkeyup="ValidateInput" />
<input type="button" value="Check" onclick="CheckIfPrime" /></p>
<p> </p>
<p id="OutputResult">Enter a number, and click the "Check" button to find out if it is a prime number.</p>
</body>
</html>
page last modified: 2024-04-16; loaded in 0.0167 seconds