In our demo it resizes the HTAs window (line 60) and sets the HTAs title (line 61). The code in lines 51 and 54 changes the output text from result to description. The code in line 50 writes the corrected input back into the textbox. The subroutine then uses a regular expression to remove everything but numbers (line 49). The code in line 44 reads the input just like the CheckIfPrime( ) does. It is triggered when the content of the textbox (line 67, ID InputNumber ) is changed ( onchange event handler, i.e. Unlike true web pages, you dont have to include a tag here, you can set it later, on-the-fly, which is demonstrated in the WindowOnLoad subroutine, on line 61.Ĭopy and paste it from this page or from any other HTA and use Microsofts HTML Applications Reference to add or modify its properties.Īfter checking if the number is a prime number, the result has to be presented (lines 30, 34 38). Specifying a DocType (line 1) is optional, but it may help getting more predictable results when running the HTA in different Windows versions. It used to come with a separate program HTAEdit in a single package, but recently these programs have been merged, and the new VBSEdit now handles HTAs too.Īnd you dont have to retype the code, it can be downloaded here.Įlse For i 2 To intInput - 1 If intInput Mod i 0 Then document.getElementById( OutputResult ).innerHTML No, intInput is not a prime number.Įxit Sub End If Next document.getElementById( OutputResult ).innerHTML Yes, intInput is a prime number.Įnd 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.Įnd If If strInput Then document.getElementById( OutputResult ).innerHTML Enter a number, and click the Check button to check if it is a prime number.Įnd If Set objRE Nothing End Sub Sub WindowOnLoad 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 nbsp input type button value Check onclick CheckIfPrime p p nbsp p p id OutputResult Enter a number, and click the Check button to find out if it is a prime number.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |