help with hta programing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chuck clark

    #1

    help with hta programing

    Hi,
    I am sorry if this is not the most appropriate group to ask this in
    (if not, please
    point me in the right direction). I am following examples from this page,
    This website is for sale! vbwm.com is your first and best source for information about vbwm. Here you will also find topics relating to issues of general interest. We hope you find what you are looking for!


    I have a some questions about Figure 5 (below). This hta file will view a
    text file when a button is pushed.

    1. Why do the paths require double '\' ? like
    F:\documents\ra ndom text\realpongfa q.txt needs to be
    F:\\documents\\ random text\\realpongf aq.txt

    2. How would i store the path as a variable instead
    of putting it directly in the BUTTON tag

    <BUTTON style= "border: 1px outset; width:100px"
    onClick="ReadFi le('c:\\autoexe c.bat');">
    Read File
    </BUTTON>

    instead do something like (which doesn't work)
    var filePath = 'F:\\documents\ \random text\\realpongf aq.txt'

    <BUTTON style= "border: 1px outset; width:100px"
    onClick="ReadFi le(filePath);">
    Read File
    </BUTTON>

    3. How can I creat a File Field form to select the file instead
    of hard coding the path? similar to this to select the file.


    Thanks,
    Chuck




    Figure 5

    <HTML>

    <HEAD>
    <TITLE>Read File</TITLE>


    <HTA:APPLICATIO N
    ID = "oApp"
    APPLICATIONNAME = "My HTA App 2001"
    BORDER = "thick"
    CAPTION = "yes"
    ICON = "app.ico"
    SHOWINTASKBAR = "yes"
    SINGLEINSTANCE = "yes"
    SYSMENU = "yes"
    WINDOWSTATE = "normal"
    SCROLL = "yes"
    SCROLLFLAT = "yes"
    VERSION = "1.0">


    <SCRIPT Language="JScri pt">

    function ReadFile(filena me)
    {
    var fso, f;
    var ForReading = 1;
    fso = new ActiveXObject(
    "Scripting.File SystemObject");

    f = fso.OpenTextFil e(filename,
    ForReading);
    txtbox.innerTex t = f.ReadAll();
    }

    </SCRIPT>

    </HEAD>



    <BODY scroll="no" style=
    "background:but tonface; color:buttontex t;
    border:0px; padding:0px; margin:0px">

    <table cellspacing=0 cellpadding=0
    border=0 width=100% height=100%>

    <tr>
    <td height=4></td>
    </tr>

    <tr>
    <td height=20>
    <BUTTON style=
    "border: 1px outset;
    width:100px"
    onClick="ReadFi le(
    'c:\\autoexec.b at');">
    Read File</BUTTON>
    </td>
    </tr>


    <tr>
    <td height=4></td>
    </tr>


    <tr>
    <td>
    <div id="txtbox" style=
    "overflow:scrol l;
    background:wind ow;
    border: 1px inset;
    font: 8pt Arial; width:100%;
    height:100%"></div>
    </td>
    </tr>

    </table>

    <OBJECT ID="oShell" CLASSID=
    "clsid:1370 9620-C279-11CE-
    A49E-444553540000">
    </OBJECT>

    </BODY>

    </HTML>


  • kaeli

    #2
    Re: help with hta programing

    In article <cEvNb.25151$RV 5.11506@fe2.tex as.rr.com>, chuck@no-
    spam.mail.utexa s.edu enlightened us with...[color=blue]
    >
    > 1. Why do the paths require double '\' ? like
    > F:\documents\ra ndom text\realpongfa q.txt needs to be
    > F:\\documents\\ random text\\realpongf aq.txt
    >[/color]

    The computer eats a slash as a special character. Putting another slash
    in front escapes it so it doesn't get eaten.
    [color=blue]
    > 2. How would i store the path as a variable instead
    > of putting it directly in the BUTTON tag
    >[/color]

    I had a real problem with this.
    The solution was convoluted and had to do with some obscure issue I
    don't quite remember.

    Searching the archives, I found my old post.

    --------
    vbscript

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <HTML>
    <HEAD>
    <TITLE>Run Executable HTA</TITLE>
    </HEAD>
    <body bgcolor=#565656 >
    <script language="VBScr ipt" type="text/vbscript">
    set oShell = CreateObject("W Script.Shell")
    oShell.run """C:\Progr am Files\Microsoft Office\Office\E xcel.exe""",1
    window.close
    </script>
    </BODY>
    </HTML>


    This worked with javascript.
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <HTML>
    <HEAD>
    <TITLE>Run Executable HTA</TITLE>
    </HEAD>
    <body bgcolor=#565656 >
    <script language="javas cript" type="text/javascript">
    var oShell = new ActiveXObject(" WScript.Shell") ;
    var prog = "C:\\Progra m Files\\Microsof t Office\\Office\ \Excel.exe";
    oShell.run ('"'+prog+'"',1 );
    window.close();
    </script>
    </BODY>
    </HTML>

    ---------------------[color=blue]
    >
    > 3. How can I creat a File Field form to select the file instead
    > of hard coding the path? similar to this to select the file.
    > http://largebuttons.com/fileupload.htm
    >[/color]

    Dunno. :)
    Don't use HTAs enough.

    If you don't mind using vbscript or know how to convert it to JScript,
    this group is pretty good.
    microsoft.publi c.scripting.vbs cript


    --
    --
    ~kaeli~
    Kill one man and you are a murderer. Kill millions and you
    are a conqueror. Kill everyone and you are God.



    Comment

    • MikeB

      #3
      Re: help with hta programing


      "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
      news:MPG.1a706b 557ef74854989af 9@nntp.lucent.c om...[color=blue]
      > In article <cEvNb.25151$RV 5.11506@fe2.tex as.rr.com>, chuck@no-
      > spam.mail.utexa s.edu enlightened us with...[color=green]
      > >
      > > 1. Why do the paths require double '\' ? like
      > > F:\documents\ra ndom text\realpongfa q.txt needs to be
      > > F:\\documents\\ random text\\realpongf aq.txt
      > >[/color]
      >
      > The computer eats a slash as a special character. Putting another slash
      > in front escapes it so it doesn't get eaten.[/color]

      This is true within a JavaScript.
      Not true within a VBScript.
      Both Scripting languages can coexist within the same HTA and can call each others subs(vb) and
      functions(vb/js).

      The following utilizes the VB MsgBox to capture a result of a keypress.

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
      <HTML>
      <HEAD>
      <TITLE></TITLE>
      <HTA:APPLICATIO N ID="oHTA"
      APPLICATIONNAME ="AltDialog"
      CAPTION="yes"
      SYSMENU="yes"
      MAXIMIZEBUTTON= "no"
      MINIMIZEBUTTON= "no"
      SHOWINTASKBAR=" no"
      SINGLEINSTANCE= "yes"
      SCROLL="NO"
      BORDER="thin"
      BORDERSTYLE="di alog"
      VERSION="1.0"
      WINDOWSTATE="no rmal"
      ICON="time.ico" >
      <SCRIPT LANGUAGE="VBSCR IPT">

      option Explicit

      Public Function Getmsgbox(msgIN )
      Select Case( msgbox( msgIN ,vbYesNoCancel) )
      Case vbYes
      Getmsgbox="YES"
      Case vbNo
      Getmsgbox="NO"
      case else
      Getmsgbox="Canc el"
      end select
      End Function
      </SCRIPT>
      <SCRIPT language="jscri pt">
      <!-- Begin Author Info For HTA

      function ClickMe(strIN)
      {
      var result=GetMsgbo x(strIN);
      alert(result + ' was pressed');

      }


      // End -->
      </Script>
      </HEAD>
      <body bgcolor=#BBBBBB >
      <input type="text" id="txtMsg" length="40">
      <input type="button" value="Click" onclick="ClickM e(txtMsg.value) ">
      </BODY>
      </HTML>




      [color=blue][color=green]
      > > 2. How would i store the path as a variable instead
      > > of putting it directly in the BUTTON tag
      > >[/color]
      >
      > I had a real problem with this.
      > The solution was convoluted and had to do with some obscure issue I
      > don't quite remember.
      >
      > Searching the archives, I found my old post.
      >
      > --------
      > vbscript
      >
      > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
      > <HTML>
      > <HEAD>
      > <TITLE>Run Executable HTA</TITLE>
      > </HEAD>
      > <body bgcolor=#565656 >
      > <script language="VBScr ipt" type="text/vbscript">
      > set oShell = CreateObject("W Script.Shell")
      > oShell.run """C:\Progr am Files\Microsoft Office\Office\E xcel.exe""",1
      > window.close
      > </script>
      > </BODY>
      > </HTML>
      >
      >
      > This worked with javascript.
      > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
      > <HTML>
      > <HEAD>
      > <TITLE>Run Executable HTA</TITLE>
      > </HEAD>
      > <body bgcolor=#565656 >
      > <script language="javas cript" type="text/javascript">
      > var oShell = new ActiveXObject(" WScript.Shell") ;
      > var prog = "C:\\Progra m Files\\Microsof t Office\\Office\ \Excel.exe";
      > oShell.run ('"'+prog+'"',1 );
      > window.close();
      > </script>
      > </BODY>
      > </HTML>
      >
      > ---------------------[color=green]
      > >
      > > 3. How can I creat a File Field form to select the file instead
      > > of hard coding the path? similar to this to select the file.
      > > http://largebuttons.com/fileupload.htm
      > >[/color]
      >
      > Dunno. :)
      > Don't use HTAs enough.
      >
      > If you don't mind using vbscript or know how to convert it to JScript,
      > this group is pretty good.
      > microsoft.publi c.scripting.vbs cript
      >
      >
      > --
      > --
      > ~kaeli~
      > Kill one man and you are a murderer. Kill millions and you
      > are a conqueror. Kill everyone and you are God.
      > http://www.ipwebdesign.net/wildAtHeart
      > http://www.ipwebdesign.net/kaelisSpace
      >[/color]


      Comment

      • Douglas Crockford

        #4
        Re: help with hta programing

        > > > 1. Why do the paths require double '\' ? like[color=blue][color=green][color=darkred]
        > > > F:\documents\ra ndom text\realpongfa q.txt needs to be
        > > > F:\\documents\\ random text\\realpongf aq.txt[/color][/color][/color]
        [color=blue][color=green]
        > > The computer eats a slash as a special character. Putting another slash
        > > in front escapes it so it doesn't get eaten.[/color][/color]
        [color=blue]
        > This is true within a JavaScript.
        > Not true within a VBScript.
        > Both Scripting languages can coexist within the same HTA and can call each[/color]
        others subs(vb) and[color=blue]
        > functions(vb/js).[/color]

        To be clear here: The Windows File System (which both JScript and VBScript can
        access) uses single backslashes to partition pathnames.

        JScript (like all C-family languages) uses backslash as an escape character in
        strings. Backslash was chosen for this purpose because it is rarely used.
        Unfortunately, Paul Allen made a horrendously bad choice when he chose \ for the
        pathname partition character for MS-DOS. This, like many other inexcusable
        design errors, was carried forward into Windows.

        The JScript compiler sees the source text

        "F:\documents\r andom text\realpongfa q.txt"

        as containing the escape sequences

        \d \r \r

        To avoid that wrong interpretation, the backslashes themselves must be escaped.

        "F:\\documents\ \random text\\realpongf aq.txt"

        Strings that come from the DOM or from the user do not need to be escaped.




        Comment

        • kaeli

          #5
          Re: help with hta programing

          In article <s5-dnShN_8UWRZvdRV n-sw@comcast.com> , "MikeB"
          <m.byerleyATVer izonDottieNetti e> enlightened us with...[color=blue][color=green]
          > >
          > >
          > > The computer eats a slash as a special character. Putting another slash
          > > in front escapes it so it doesn't get eaten.[/color]
          >
          > This is true within a JavaScript.
          > Not true within a VBScript.[/color]

          No, in vbscript, it eats double quotes. :)


          --
          --
          ~kaeli~
          A man needs a mistress... just to break the monogamy.



          Comment

          • MikeB

            #6
            Re: help with hta programing


            "Douglas Crockford" <nospam@covad.n et> wrote in message
            news:cfb20$4006 de68$4365637e$3 0961@msgid.mega newsservers.com ...[color=blue][color=green][color=darkred]
            > > > > 1. Why do the paths require double '\' ? like
            > > > > F:\documents\ra ndom text\realpongfa q.txt needs to be
            > > > > F:\\documents\\ random text\\realpongf aq.txt[/color][/color]
            >[color=green][color=darkred]
            > > > The computer eats a slash as a special character. Putting another slash
            > > > in front escapes it so it doesn't get eaten.[/color][/color]
            >[color=green]
            > > This is true within a JavaScript.
            > > Not true within a VBScript.
            > > Both Scripting languages can coexist within the same HTA and can call each[/color]
            > others subs(vb) and[color=green]
            > > functions(vb/js).[/color]
            >
            > To be clear here: The Windows File System (which both JScript and VBScript can
            > access) uses single backslashes to partition pathnames.
            >
            > JScript (like all C-family languages) uses backslash as an escape character in
            > strings. Backslash was chosen for this purpose because it is rarely used.
            > Unfortunately, Paul Allen made a horrendously bad choice when he chose \ for the
            > pathname partition character for MS-DOS. This, like many other inexcusable
            > design errors, was carried forward into Windows.[/color]

            Well, going from Dos 1.0, which had no directory structure (progs and data all in the root of the
            boot drive) to dos 2.0 which had directories, I would guess they fancied themselves pretty smart
            cookies at the time.. :^)
            [color=blue]
            > The JScript compiler sees the source text
            >
            > "F:\documents\r andom text\realpongfa q.txt"
            >
            > as containing the escape sequences
            >
            > \d \r \r
            >
            > To avoid that wrong interpretation, the backslashes themselves must be escaped.
            >
            > "F:\\documents\ \random text\\realpongf aq.txt"
            >
            > Strings that come from the DOM or from the user do not need to be escaped.
            >
            > http://www.crockford.com/javascript/javascript.html
            >
            >[/color]


            Comment

            • Steve van Dongen

              #7
              Re: help with hta programing

              kaeli <tiny_one@NOSPA M.comcast.net> wrote:
              [color=blue]
              >In article <cEvNb.25151$RV 5.11506@fe2.tex as.rr.com>, chuck@no-
              >spam.mail.utex as.edu enlightened us with...[color=green]
              >>[/color][/color]
              <snip />
              [color=blue][color=green]
              >> 3. How can I creat a File Field form to select the file instead
              >> of hard coding the path? similar to this to select the file.
              >> http://largebuttons.com/fileupload.htm
              >>[/color][/color]

              <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
              <HTML>
              <HEAD>
              <TITLE>Run Executable HTA</TITLE>
              <script language="javas cript" type="text/javascript">
              function RunCmd(cmdLine)
              {
              var oShell = new ActiveXObject(" WScript.Shell") ;
              oShell.Run ('"' + cmdLine + '"',1);
              }
              </script>
              </HEAD>
              <body>
              <form>
              <input name="SelectFil e" type=file></input>
              <br/>
              <button onclick="RunCmd (this.form.Sele ctFile.value)"> Run</button>
              </form>
              </BODY>
              </HTML>

              Regards,
              Steve

              Comment

              • MikeB

                #8
                Re: help with hta programing


                "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
                news:MPG.1a706b 557ef74854989af 9@nntp.lucent.c om...[color=blue]
                > In article <cEvNb.25151$RV 5.11506@fe2.tex as.rr.com>, chuck@no-
                > spam.mail.utexa s.edu enlightened us with...[color=green]
                > >
                > > 1. Why do the paths require double '\' ? like
                > > F:\documents\ra ndom text\realpongfa q.txt needs to be
                > > F:\\documents\\ random text\\realpongf aq.txt
                > >[/color]
                >
                > The computer eats a slash as a special character. Putting another slash
                > in front escapes it so it doesn't get eaten.
                >[color=green]
                > > 2. How would i store the path as a variable instead
                > > of putting it directly in the BUTTON tag
                > >[/color]
                >
                > I had a real problem with this.
                > The solution was convoluted and had to do with some obscure issue I
                > don't quite remember.
                >
                > Searching the archives, I found my old post.
                >
                > --------
                > vbscript
                >
                > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
                > <HTML>
                > <HEAD>
                > <TITLE>Run Executable HTA</TITLE>
                > </HEAD>
                > <body bgcolor=#565656 >
                > <script language="VBScr ipt" type="text/vbscript">
                > set oShell = CreateObject("W Script.Shell")
                > oShell.run """C:\Progr am Files\Microsoft Office\Office\E xcel.exe""",1
                > window.close
                > </script>
                > </BODY>
                > </HTML>
                >
                >
                > This worked with javascript.
                > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
                > <HTML>
                > <HEAD>
                > <TITLE>Run Executable HTA</TITLE>
                > </HEAD>
                > <body bgcolor=#565656 >
                > <script language="javas cript" type="text/javascript">
                > var oShell = new ActiveXObject(" WScript.Shell") ;
                > var prog = "C:\\Progra m Files\\Microsof t Office\\Office\ \Excel.exe";
                > oShell.run ('"'+prog+'"',1 );
                > window.close();
                > </script>
                > </BODY>
                > </HTML>
                >
                > ---------------------[color=green]
                > >
                > > 3. How can I creat a File Field form to select the file instead
                > > of hard coding the path? similar to this to select the file.
                > > http://largebuttons.com/fileupload.htm[/color][/color]

                Also, if you have VB, you could write a wrapper ActiveX around the MsComDlg control and have an
                actual File Open dialog box. There are many freebies of this on the web, but most people wouldn't
                trust a 3rd party control and it is little work to roll your own. It adds a nice touch on your in
                house app and of course could be reused many times...

                [color=blue]
                >
                > Dunno. :)
                > Don't use HTAs enough.
                >
                > If you don't mind using vbscript or know how to convert it to JScript,
                > this group is pretty good.
                > microsoft.publi c.scripting.vbs cript
                >
                >
                > --
                > --
                > ~kaeli~
                > Kill one man and you are a murderer. Kill millions and you
                > are a conqueror. Kill everyone and you are God.
                > http://www.ipwebdesign.net/wildAtHeart
                > http://www.ipwebdesign.net/kaelisSpace
                >[/color]


                Comment

                • Jim Ley

                  #9
                  Re: help with hta programing

                  On Thu, 15 Jan 2004 10:39:08 -0800, "Douglas Crockford"
                  <nospam@covad.n et> wrote:
                  [color=blue]
                  >To be clear here: The Windows File System (which both JScript and VBScript can
                  >access) uses single backslashes to partition pathnames.[/color]

                  One thing to note is that the FSO (aswell as many windows
                  applications/components) allow you to use / as an alternative to \ so
                  you can do:

                  fso=new ActiveXObject(" Scripting.fileS ystemObject");
                  alert(fso.fileE xists("C:/windows/fonts/arial.ttf"));

                  This may not be all windows O/S's so test on your own machine of
                  course!

                  Jim.
                  --
                  comp.lang.javas cript FAQ - http://jibbering.com/faq/

                  Comment

                  Working...