Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for myfirsthta.hta

(view source code of myfirsthta.hta as plain text)

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>My First HTML Application</title>
  5.  
  6. <HTA:APPLICATION
  7.   APPLICATIONNAME="My First HTML Application"
  8.   ID="MyFirstHTA"
  9.   VERSION="1.0"
  10.   SCROLL="no"/>
  11.  
  12. <style type="text/css">
  1. body {
  2. 	background-color: #fdfeff;
  3. 	color: darkblue;
  4. 	font-family: Calibri;
  5. 	font-size: 12pt;
  6. 	margin: 4em 3em;
  7. }
  1. </style>
  2. </head>
  3.  
  4. <script language="VBScript">
  1. Option Explicit
  2.  
  3. Sub CheckIfPrime( )
  4. 	Dim i, intInput
  5. 	intInput = document.getElementById( "InputNumber" ).value
  6. 	If intInput < 3 Then
  7. 		document.getElementById( "OutputResult" ).innerHTML = "Yes, " & intInput & " is a prime number."
  8. 	Else
  9. 		For i = 2 To intInput - 1
  10. 			If intInput Mod i = 0 Then
  11. 				document.getElementById( "OutputResult" ).innerHTML = "No, " & intInput & " is not a prime number."
  12. 				Exit Sub
  13. 			End If
  14. 		Next
  15. 		document.getElementById( "OutputResult" ).innerHTML = "Yes, " & intInput & " is a prime number."
  16. 	End If
  17. End Sub
  18.  
  19. Sub ValidateInput( )
  20. 	Dim objRE, strInput
  21. 	strInput = document.getElementById( "InputNumber" ).value
  22. 	Set objRE = New RegExp
  23. 	objRE.Global  = True
  24. 	objRE.Pattern = "[^\d]+"
  25. 	If objRE.Test( strInput ) Then
  26. 		strInput = objRE.Replace( strInput, "" )
  27. 		document.getElementById( "InputNumber" ).value      = strInput
  28. 		document.getElementById( "OutputResult" ).innerHTML = "Enter a number, and click the ""Check"" button to check if it is a prime number."
  29. 	End If
  30. 	If strInput = "" Then
  31. 		document.getElementById( "OutputResult" ).innerHTML = "Enter a number, and click the ""Check"" button to check if it is a prime number."
  32. 	End If
  33. 	Set objRE = Nothing
  34. End Sub
  35.  
  36. Sub Window_OnLoad
  37. 	window.resizeTo 640, 480
  38. 	document.title = document.title & ",  Version " & MyFirstHTA.Version
  39. End Sub
  1. </script>
  2.  
  3. <body>
  4.  
  5. <p><input type="text" id="InputNumber" onchange="ValidateInput" onkeyup="ValidateInput" />
  6. &nbsp;
  7. <input type="button" value="Check" onclick="CheckIfPrime" /></p>
  8.  
  9. <p>&nbsp;</p>
  10.  
  11. <p id="OutputResult">Enter a number, and click the "Check" button to find out if it is a prime number.</p>
  12.  
  13. </body>
  14. </html>

page last modified: 2024-02-26; loaded in 0.0387 seconds