Mittwoch, 27. August 2014

Once I needed to implement a small script that should read rows from a database and create a CSV file based on a particular filtering. I knew much about command line VB and Java scripting but a main requirement was to have a simple GUI which for entering the filter criteria.

After a while I ’ve found a tutorial about HTML Applications and immediately liked the way of implementing scripted GUI's. A HTML Application (HTA) is not hing more than a normal HTML page with an additional HTA: APPLICATION tag and the .hta file extension telling windows to execute the file with different permissions. That means that you can access the filesystem, databases or other activex libraries. And one of the really nice thing is that you can even style your page with CSS.

So I ’ve decided to write the requested script as a HTML Application which accesses the database and stores the entries as a CSV file. In the following I will post a shorten version of the script for the sake of simplicity. But before you can execute the script you have to install the ODBC Connector for MySQL. As a special gimmick I ’v e added a javascript implementation of a tabpane from WebFX where I ’ve separated the settings from the general view.

<link type="text/css" rel="stylesheet" href="webfx/css/tab.css" />
<script type="text/javascript" src="webfx/js/tabpane.js"></script>
 .button {
  border:1px solid #dedede;
  border-top:1px solid #eee;
  border-left:1px solid #eee;
    window.resizeTo(320, 240);
 function onLoad() {
  //Read the ini file and populate the setting text fields
  document.getElementById("txtDatabaseName").value = "testdb";
  document.getElementById("txtDatabaseUser").value = "root";
  document.getElementById("txtDatabasePassword").value  = "password";
  document.getElementById("txtCSVFile").value  = "testcsv.csv";
  document.getElementById("txtOffer").value = "O";
 function generateCSVFile() {
  var oFS = new ActiveXObject("Scripting.FileSystemObject");
     var adConnection, adRS;

  adConnection = new ActiveXObject("ADODB.Connection");
  adConnection.Provider = "MSDASQL";
  adConnection.Mode = 1;
  adConnection.CursorLocation = 3;
  adConnection.Open("Driver={MySQL ODBC 3.51 Driver};" + 
   "DATABASE=" + document.getElementById("txtDatabaseName").value + ";" + 
  adRS = new ActiveXObject("ADODB.Recordset");
  adRS.ActiveConnection = adConnection
  adRS.CursorLocation = 3;
  adRS.CursorType = 0;
  adRS.LockType = 1;
  adRS.Source = "Select * from article;";

  var csvFileName = document.getElementById("txtCSVFile").value;
  var csvFile = oFS.OpenTextFile(csvFileName, 2, true);

  while(!adRS.EOF) {
   if (adRS.Fields.Item("identification").Value == document.getElementById("txtOffer").value) {
    csvFile.WriteLine(adRS.Fields.Item("ID").Value + "," + adRS.Fields.Item("name").Value)
<body onload="onLoad();">
 <div class="tab-pane" id="tabPane1">
  <script type="text/javascript">tp1 = new WebFXTabPane( document.getElementById( "tabPane1" ) );</script>
  <div class="tab-page" id="tabPage1">
   <h2 class="tab">General</h2>
   <script type="text/javascript">tp1.addTabPage( document.getElementById( "tabPage1" ) );</script>
   <div style="font:11px MS Sans Serif;font-weight:bold;">Identifier in K1</div>
    <table border="0" cellspacing="2" cellpadding="0">
      <td style="font:11px MS Sans Serif;" width="200">Offering</td><td width="60"><input type="text" id="txtOffer" size="2"></td>
    <input type="button" class="button" value="Generate CSV file" name="run_button"  onClick="generateCSVFile();">
  <div class="tab-page" id="tabPage2">
   <h2 class="tab">Settings</h2>
   <script type="text/javascript">tp1.addTabPage( document.getElementById( "tabPage2" ) );</script>
   <table border="0" cellspacing="2" cellpadding="0">
     <td style="font:11px MS Sans Serif;" width="150">Database</td><td width="120"><input type="text" id="txtDatabaseName"></td>
     <td style="font:11px MS Sans Serif;" width="150">User</td><td width="120"><input type="text" id="txtDatabaseUser"></td>
     <td style="font:11px MS Sans Serif;" width="150">Password</td><td width="120"><input type="text" id="txtDatabasePassword"></td>
     <td style="font:11px MS Sans Serif;" width="150">CSV file</td><td width="120"><input type="text" id="txtCSVFile"></td>
   <input width="100%" type="button" class="button" value="Save settings" name="run_button"  onClick="saveSettings();"></td>


  1. nice blog too informative. looking and reading your points its so impressive. doing more blog like this. i really appreciated doing like this.
    School Signs UK

  2. Thanks for the above post.I am using gmail from so long time. Now its time to change the color and background of my account. I am trying this but I think here is some problem in doing this. Its not done like you mentioned above. I will try again and then send you feedback. Thanks once again.
    IELTS coaching in chennai

  3. As you have now understood the usage of ‘Record and Playback’ tool, the following are the different posts using which you can explore the functioning of ‘Selenium IDE’
    selenium Training in chennai

  4. We can learn a lot about Why Deep Learning Works by studying the properties of the layer weight matrices of pre-trained neural networks. And, hopefully, by doing this, we can get some insight into what a well trained DNN looks like–even without peaking at the training data.
    MACHINE LEARNING training in chennai

  5. Your article is very attractive! I really like your post and l got more info from your post. I want more additional details about this topic. Thank you for your sharing and well done.
    IELTS Coaching in Chennai
    IELTS Coaching Center in Chennai
    TOEFL Coaching in Chennai
    Jmeter Training in Chennai
    Spoken English Classes in Chennai
    Ethical Hacking Course in Chennai
    IELTS coaching in OMR
    IELTS coaching in Tambaram