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