Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Passing Arguments with an HTA

648 views
Skip to first unread message

Unknown

unread,
Dec 16, 2007, 8:07:41 PM12/16/07
to
Hi Everyone,

This is my first time posting to this group, and was wondering if
someone might be able to help me with the problem below.

I need to pass arguments from one sub to another through an html
button. However, when I run my test code below, neither of the
arguments are outputted to the page.

Any help would be greatly appreciated.

TIA!

<html>

<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>Multiple Args Test</title>

<script language="vbscript">
Sub MakeButton
firstVar = "one"
secondVar = "two"

document.all.Results.innerHTML = "<input type='button'
onclick='PrintOut firstVar,secondVar' value='Test Print'>"
End Sub

Sub PrintOut(firstArg, secondArg)
document.all.Results.innerHTML = "Arg1: " & firstArg &
"<br>" & "Arg2: " & secondArg
End Sub
</script>

<hta:application
applicationname="MyHTA"
border="dialog"
borderstyle="normal"
caption="My HTML Application"
contextmenu="no"
icon="myicon.ico"
maximizebutton="no"
minimizebutton="yes"
navigable="no"
scroll="no"
selection="no"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
version="1.0"
windowstate="normal"
>
</head>

<body>
<input type="button" onclick="MakeButton" value="Test">
<hr>
<div id="Results"></div>
</body>
</html>

Kai.Bluesky

unread,
Dec 16, 2007, 9:41:02 PM12/16/07
to
Dear,

<html>

<head>
<meta http-equiv="Content-Type" content="text/

html;charset=windows-1252">


<title>Multiple Args Test</title>

<script language="vbscript">
Sub MakeButton
firstVar = "one"
secondVar = "two"

document.all.Results.innerHTML = "<input type='button'

onclick='call PrintOut(""" & firstVar & """,""" & secondVar & """)'
value='Test Print'>"
'call PrintOut((firstVar), (secondVar))
End Sub

Some info about "cannot use parentheses"
http://blogs.msdn.com/ericlippert/archive/2003/09/15/52996.aspx

Hope it may Help.

Best Regards,
Kai

Unknown

unread,
Dec 17, 2007, 12:03:38 AM12/17/07
to
Thanks Kai for your quick response and for the link to the parenthesis
article.

I've changed the line that calls the sub to read the following:

document.all.Results.innerHTML = "<input type='button'
onclick='PrintOut firstVar,secondVar' value='Test Print'>"

...and I've also tried:

document.all.Results.innerHTML = "<input type='button'

onclick='PrintOut " & firstVar & "," & secondVar & "' value='Test
Print'>"

...but for some reason the sub still doesn't seem to receive the
values passed to it. (Calling msgbox to output the values for
firstValue and secondValue in the MakeButton sub outputs correctly,
but calling msgbox in the PrintOut sub just displays nothing.)

Kai.Bluesky

unread,
Dec 17, 2007, 1:01:47 AM12/17/07
to
Dear

Actually, I have changed the code in the previous post. Please try
this.

document.all.Results.innerHTML = "<input type='button'onclick='call
PrintOut(""" & firstVar & """,""" & secondVar & """)'value='Test
Print'>"

Best Regards,
Kai


On Dec 17, 1:03 pm, AlterEgo <> wrote:
> Thanks Kai for your quick response and for the link to the parenthesis
> article.
>
> I've changed the line that calls the sub to read the following:
>
> document.all.Results.innerHTML = "<input type='button'
> onclick='PrintOut firstVar,secondVar' value='Test Print'>"
>
> ...and I've also tried:
>
> document.all.Results.innerHTML = "<input type='button'
> onclick='PrintOut " & firstVar & "," & secondVar & "' value='Test
> Print'>"
>
> ...but for some reason the sub still doesn't seem to receive the
> values passed to it. (Calling msgbox to output the values for
> firstValue and secondValue in the MakeButton sub outputs correctly,
> but calling msgbox in the PrintOut sub just displays nothing.)
>
> On Sun, 16 Dec 2007 18:41:02 -0800 (PST), "Kai.Bluesky"
>

Unknown

unread,
Dec 17, 2007, 1:11:11 AM12/17/07
to
Thanks Kai, that works perfectly!

Michael Harris

unread,
Dec 17, 2007, 11:32:29 PM12/17/07
to
AlterEgo wrote:
> Hi Everyone,
>
> This is my first time posting to this group, and was wondering if
> someone might be able to help me with the problem below.
>
> I need to pass arguments from one sub to another through an html
> button. However, when I run my test code below, neither of the
> arguments are outputted to the page.
>
> Any help would be greatly appreciated.
>

It's an issue fo variabke scope...

> <html>
>
> <head>
> <meta http-equiv="Content-Type" content="text/html;
> charset=windows-1252">
> <title>Multiple Args Test</title>
>
> <script language="vbscript">

'declare the variables in global page level scope...
Dim firstVar, secondVar


> Sub MakeButton

'Now your local Sub variable assignments are to the page level scoped
variables,
'not implicitly declared local scope variables...

> firstVar = "one"
> secondVar = "two"
>
> document.all.Results.innerHTML = "<input type='button'
> onclick='PrintOut firstVar,secondVar' value='Test Print'>"
> End Sub
>

...

--
Michael Harris


0 new messages