469,903 Members | 1,525 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

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,
http://www.vbwm.com/articles/2002/abarfield/hta01/

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\random text\realpongfaq.txt needs to be
F:\\documents\\random text\\realpongfaq.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="ReadFile('c:\\autoexec.bat');">
Read File
</BUTTON>

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

<BUTTON style= "border: 1px outset; width:100px"
onClick="ReadFile(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.
http://largebuttons.com/fileupload.htm

Thanks,
Chuck


Figure 5

<HTML>

<HEAD>
<TITLE>Read File</TITLE>
<HTA:APPLICATION
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="JScript">

function ReadFile(filename)
{
var fso, f;
var ForReading = 1;
fso = new ActiveXObject(
"Scripting.FileSystemObject");

f = fso.OpenTextFile(filename,
ForReading);
txtbox.innerText = f.ReadAll();
}

</SCRIPT>

</HEAD>

<BODY scroll="no" style=
"background:buttonface; color:buttontext;
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="ReadFile(
'c:\\autoexec.bat');">
Read File</BUTTON>
</td>
</tr>
<tr>
<td height=4></td>
</tr>
<tr>
<td>
<div id="txtbox" style=
"overflow:scroll;
background:window;
border: 1px inset;
font: 8pt Arial; width:100%;
height:100%"></div>
</td>
</tr>

</table>

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

</BODY>

</HTML>
Jul 20 '05 #1
8 7243
In article <cE*******************@fe2.texas.rr.com>, chuck@no-
spam.mail.utexas.edu enlightened us with...

1. Why do the paths require double '\' ? like
F:\documents\random text\realpongfaq.txt needs to be
F:\\documents\\random text\\realpongfaq.txt

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

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="VBScript" type="text/vbscript">
set oShell = CreateObject("WScript.Shell")
oShell.run """C:\Program Files\Microsoft Office\Office\Excel.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="javascript" type="text/javascript">
var oShell = new ActiveXObject("WScript.Shell");
var prog = "C:\\Program Files\\Microsoft Office\\Office\\Excel.exe";
oShell.run ('"'+prog+'"',1);
window.close();
</script>
</BODY>
</HTML>

---------------------
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


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.public.scripting.vbscript
--
--
~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

Jul 20 '05 #2

"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <cE*******************@fe2.texas.rr.com>, chuck@no-
spam.mail.utexas.edu enlightened us with...

1. Why do the paths require double '\' ? like
F:\documents\random text\realpongfaq.txt needs to be
F:\\documents\\random text\\realpongfaq.txt


The computer eats a slash as a special character. Putting another slash
in front escapes it so it doesn't get eaten.


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:APPLICATION ID="oHTA"
APPLICATIONNAME="AltDialog"
CAPTION="yes"
SYSMENU="yes"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SHOWINTASKBAR="no"
SINGLEINSTANCE="yes"
SCROLL="NO"
BORDER="thin"
BORDERSTYLE="dialog"
VERSION="1.0"
WINDOWSTATE="normal"
ICON="time.ico">
<SCRIPT LANGUAGE="VBSCRIPT">

option Explicit

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

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

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


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


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="VBScript" type="text/vbscript">
set oShell = CreateObject("WScript.Shell")
oShell.run """C:\Program Files\Microsoft Office\Office\Excel.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="javascript" type="text/javascript">
var oShell = new ActiveXObject("WScript.Shell");
var prog = "C:\\Program Files\\Microsoft Office\\Office\\Excel.exe";
oShell.run ('"'+prog+'"',1);
window.close();
</script>
</BODY>
</HTML>

---------------------

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


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.public.scripting.vbscript
--
--
~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

Jul 20 '05 #3
> > > 1. Why do the paths require double '\' ? like
F:\documents\random text\realpongfaq.txt needs to be
F:\\documents\\random text\\realpongfaq.txt
The computer eats a slash as a special character. Putting another slash
in front escapes it so it doesn't get eaten.
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).


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\random text\realpongfaq.txt"

as containing the escape sequences

\d \r \r

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

"F:\\documents\\random text\\realpongfaq.txt"

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

http://www.crockford.com/javascript/javascript.html
Jul 20 '05 #4
In article <s5********************@comcast.com>, "MikeB"
<m.byerleyATVerizonDottieNettie> enlightened us with...


The computer eats a slash as a special character. Putting another slash
in front escapes it so it doesn't get eaten.


This is true within a JavaScript.
Not true within a VBScript.


No, in vbscript, it eats double quotes. :)
--
--
~kaeli~
A man needs a mistress... just to break the monogamy.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #5

"Douglas Crockford" <no****@covad.net> wrote in message
news:cf***************************@msgid.meganewss ervers.com...
> 1. Why do the paths require double '\' ? like
> F:\documents\random text\realpongfaq.txt needs to be
> F:\\documents\\random text\\realpongfaq.txt The computer eats a slash as a special character. Putting another slash
in front escapes it so it doesn't get eaten.
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).


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.


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.. :^)
The JScript compiler sees the source text

"F:\documents\random text\realpongfaq.txt"

as containing the escape sequences

\d \r \r

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

"F:\\documents\\random text\\realpongfaq.txt"

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

http://www.crockford.com/javascript/javascript.html

Jul 20 '05 #6
kaeli <ti******@NOSPAM.comcast.net> wrote:
In article <cE*******************@fe2.texas.rr.com>, chuck@no-
spam.mail.utexas.edu enlightened us with...
<snip />
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


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

Regards,
Steve
Jul 20 '05 #7

"kaeli" <ti******@NOSPAM.comcast.net> wrote in message
news:MP************************@nntp.lucent.com...
In article <cE*******************@fe2.texas.rr.com>, chuck@no-
spam.mail.utexas.edu enlightened us with...

1. Why do the paths require double '\' ? like
F:\documents\random text\realpongfaq.txt needs to be
F:\\documents\\random text\\realpongfaq.txt

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


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="VBScript" type="text/vbscript">
set oShell = CreateObject("WScript.Shell")
oShell.run """C:\Program Files\Microsoft Office\Office\Excel.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="javascript" type="text/javascript">
var oShell = new ActiveXObject("WScript.Shell");
var prog = "C:\\Program Files\\Microsoft Office\\Office\\Excel.exe";
oShell.run ('"'+prog+'"',1);
window.close();
</script>
</BODY>
</HTML>

---------------------

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


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...


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.public.scripting.vbscript
--
--
~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

Jul 20 '05 #8
On Thu, 15 Jan 2004 10:39:08 -0800, "Douglas Crockford"
<no****@covad.net> wrote:
To be clear here: The Windows File System (which both JScript and VBScript can
access) uses single backslashes to partition pathnames.


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.fileSystemObject");
alert(fso.fileExists("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.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by cyshao | last post: by
2 posts views Thread by continium | last post: by
13 posts views Thread by Xah Lee | last post: by
12 posts views Thread by Xah Lee | last post: by
8 posts views Thread by SanjaiGandhi | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.