title: Edit text and save
body: <p>I'm making a script in hta and needed him to have the following functions:</p>
  
  <p>It has the following functions: </p>
  
  <ol>
  <li>Do not open the script if the file .txt does not exist.</li>
  <li>Remove the the inputbox and still be able to save the changes.</li>
  <li>If the User try to save an empty text it presents an error.</li>
  <li>If the User makes a valid modification (not empty) present a message
  stating that it was saved.</li>
  </ol>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code> &lt;HTML&gt;
   &lt;head&gt;&lt;title&gt;Name&lt;/Title&gt;
   &lt;HTA:Application
        Border= "thin"
        Application="/md/input"
        Scoll="NO"
        Singleinstance="Yes"
        Icon="01.ico"&gt;
        ShowInTaskbar="Yes"
        Caption="Yes"&gt;
   &lt;/Head&gt;
   &lt;Script Language="VBSCRIPT" Type = "text/vbscript"&gt;
   Sub Window_Onload
      Window.resizeTo 400,500
   End Sub
     Const ForReading = 1
     Const ForWriting = 2
     Const ForAppending = 8
     Set fSo1 = CreateObject("Scripting.FileSystemObject")
     wkDir = "test.txt"
   '----------------------------------------------------------
       sub Window_onLoad()
      Window.resizeTo 400,500
       set oFSO=CreateObject("Scripting.FileSystemObject")
       set oFile=oFSO.OpenTextFile("Test.txt",1)
       text=oFile.ReadAll
       document.all.DataArea.value=text
       oFile.Close
       end sub
   '----------------------------------------------------------
   FUNCTION SaveFile(FileName, DataArea)
      CALL FileStat(FileName, msg)
      on error resume next
      sFile = wkDir &amp; FileName.value
      Set wrFile = fSo1.OpenTextFile(sFile, ForWriting)
          wrFile.writeline(DataArea.value)
       self.close
   END FUNCTION
   '----------------------------------------------------------
   FUNCTION CloseFile(FileName, DataArea)
      Call FileStat(FileName, msg)
      on error resume next
      cFile = wkDir &amp; FileName.value
      Set wrFile = fSo1.OpenTextFile(cFile, ForAppending)
          wrFile.Close
      DataArea.value = ""
      FileName.Value = ""
   END FUNCTION
   '----------------------------------------------------------
   FUNCTION QuitEdit
       self.close
   END FUNCTION
   '----------------------------------------------------------
   FUNCTION FileStat(FileName, msg)
     eFile = wkDir &amp; FileName
     IF (fSo1.FileExists(eFile)) THEN
         msg = oFile &amp; " exists."
         ELSE
         on error resume next
     END IF
   END FUNCTION
   '----------------------------------------------------------
   &lt;/Script&gt;
   &lt;body bgcolor="C0C0C0"&gt;
   &lt;Table&gt;
   &lt;Th&gt; Name &lt;/Th&gt;
  &lt;TR&gt;&lt;td&gt;&lt;input type="text" name="FileName"&gt;&lt;/td&gt;&lt;/TR&gt;
   &lt;/Table&gt;
   &lt;Table border="2"&gt;
   &lt;TR&gt;&lt;td&gt;
   &lt;textarea name="DataArea" rows="18" cols=37&gt;&lt;/textarea&gt;
   &lt;/td&gt;&lt;/TR&gt;
   &lt;TR&gt;&lt;td&gt;
   &lt;input type="BUTTON" value="Save"  onclick="SaveFile FileName, DataArea"&gt;
   &lt;input type="BUTTON" value="Cancel"  onclick="QuitEdit"&gt;
   &lt;/td&gt;&lt;/TR&gt;
   &lt;/Table&gt;
   &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>