/*********************************************************

use-converter.js : copyright 2001, Essam Ahmed

This sample is from the book JScript.NET Programming (2001)
by Essam Ahmed


This script demonstrates how to use a Windows Script component. Simply run this sample; 
it will determine if it needs to register the demo component and will register it for
you. If this happens, just follow the driections on the screen and re-run the demo.

If you want to un-reigster the sample component, unregister it using the command:
regsvr32 /u distanceConverter.wsc


*********************************************************/
var cvt;
try{

  cvt=new ActiveXObject("distanceConverter.WSC");

  var nMiles=5;
  var nKm;

  nKm=cvt.miTOkm(nMiles);
  WScript.Echo(nMiles + " miles is " + nKm + " Kilometers");
  nKm=104;
  nMiles=cvt.kmTOmi(nKm);
  WScript.Echo(nKm + " Kilometers is " + nMiles + " miles");

}
catch (e)
{
   WScript.Echo("** Error\n" + e.description + "\n["+(e.number & 0xffff)+"]");
   try{

     WScript.Echo("\n**The component is not registered...attempting to register...");
     var fso = new ActiveXObject("Scripting.FileSystemObject");
     var fileObj=fso.GetFile("distanceConverter.wsc");
     var runcmd;
     runcmd="regsvr32 /s ";
     runcmd+=fileObj.Path;


     WScript.Echo("Attempting to run " + runcmd);

     var ws=new ActiveXObject("WScript.Shell")
     ws.Run(runcmd,1,true);
     } catch(ce) {
          WScript.Echo("** Error\n" + e.description + "\n["+(e.number & 0xffff)+"]");
          WScript.Echo("Quitting!");
          WScript.Quit();
     }
     WScript.Echo("");
     WScript.Echo("Component registered , please re-run this demo to excercise the component");

}

WScript.Echo("\nCommand completed");
