[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to call a VBScript function from button "on click"

Posted on 2008-11-04
6
Medium Priority
?
4,251 Views
Last Modified: 2010-08-05
I've got the following code trying to call a function and pass variables to the function, but I get the message that I cannot use parantheses while calling a sub....

I'm not calling a sub though....
<HTML>
<HEAD>
<link rel="stylesheet" type="text/css"
href="\\server\path\CSS.css"/>
<TITLE>Profile Cleanup Utility</TITLE>
<HTA:APPLICATION 
     APPLICATIONNAME="Program"
     SCROLL="no"
     BORDER="THIN"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
     MINIMIZEBUTTON="no"
     MAXIMIZEBUTTON="no"
     ICON="\\server\path\icon.ico"
>
 
<script language="VBScript">
 
'=====================
'Defining variables
'=====================
Const ForReading = 1
const ForWriting = 2
Const ForAppending = 8
Const ADS_SCOPE_SUBTREE = 2
 
strDate = Date()
intDel = 60
 
strTotalSize = 0
strMonth = Month(Now)
strDay = Day(Now)
strYear = Year(Now)
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
 
'================================
'Determine location to run script
'================================    
    Sub RunLocation
	
		strLocation = SelectLocation.Value
		select case strLocation
			case ""
				GroupSelect.innerHTML = ""
				
			case "Boise"
				GroupSelect.innerHTML = "<select size='1' width='50' name='SelectGroup' onchange='BoiseSetGroupInfo'>" &_
					"<option selected value=''>Make a Selection</option>" &_
					"<option value='PPD'>PPD</option>" &_
					"<option value='WDTS'>WDTS</option>" &_
					"<option value='TRN'>TRN</option></select>"
	
		End Select
	
	End Sub
	
	Sub BoiseSetGroupInfo
		
		strGroup = SelectGroup.Value
				
				select case strGroup
				
					case ""
					'nothing
					case "PPD"
						Offline = "\\server\path\file.txt"
						Deleted = "\\server\path\file.txt"
						Checked = "\\server\path\file.txt"
						strExcelPath = "\\server\path\file.txt"
						strMachineGroup = "PPD*"
						strGroupLocation = "LDAP://ou=path,ou=path,ou=path,dc=dc,dc=domain,dc=com"
						StartAction.innerHTML = "<input type='button' value='Start Cleanup' name='start_cleanup' onClick='ProcessGroup(Offline,Deleted,Checked,strExcelPath,strMachineGroup,strGroupLocation)'>"								End Select		
	End Sub
	
	Function ProcessGroup(Offline,Deleted,Checked,strExcelPath,strMachineGroup,strGroupLocation)
		
		objCommand.CommandText = "SELECT Name, dNSHostName FROM '" & strGroupLocation & "' WHERE objectCategory='computer' AND dNSHostName='" & strMachineGroup & "'"
		Set objRecordSet = objCommand.Execute
		
		objRecordSet.MoveFirst
		
		Do Until objRecordSet.EOF
			strComputer = objRecordSet.Fields("Name").Value
			msgbox(strcomputer)
			objRecordSet.MoveNext
		Loop
		
		msgbox("Action Complete")
	End Function
	
</script>
 
</HEAD>
<BODY>
<DIV id="Background_DIV">
<img src= "\\server\path\image.bmp" height=100% width=100%/>
<script type="text/javascript">
	{
	window.resizeTo(400,300)
	window.moveTo(0,0);
	}	
</script>
 
<DIV id="LocationSelect_DIV">
<select size="1" width="30" name="SelectLocation" onchange="RunLocation">
    <option selected value="">Make a Selection</option>
    <option value="Boise">Boise</option>
    <option value="Seattle">Seattle</option>
</select>
</DIV>
 
<DIV id="GroupSelect_DIV" align="Center">
<span id="GroupSelect"></span>
</DIV>
<DIV id="ActionButton_DIV" align="Center">
<span id="StartAction"></span>
</DIV>
<DIV id="Status_DIV">
<span id="CurrentStatus"></span>
</DIV>
</DIV>
</BODY>
</HTML>

Open in new window

0
Comment
Question by:piattnd
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:rejoinder
ID: 22882457
The function call should not have parenthesis when you use multiple variables.  Use the following in your code and all should work fine (at least for me it did);
StartAction.innerHTML = "<input type='button' value='Start Cleanup' name='start_cleanup' onClick='ProcessGroup Offline,Deleted,Checked,strExcelPath,strMachineGroup,strGroupLocation'>"
0
 
LVL 7

Expert Comment

by:Valleriani
ID: 22882464
Try using:

                                                StartAction.innerHTML = "<input type='button' value='Start Cleanup' name='start_cleanup' onClick='Call ProcessGroup(Offline,Deleted,Checked,strExcelPath,strMachineGroup,strGroupLocation)'>"


(Add Call infront of it)
0
 
LVL 12

Author Comment

by:piattnd
ID: 22888058
I've tried using call and it doesn't work.

I also rtied what you said, rejoinder, and I don't get a script error,  but the echo returns a null value for any of my variables.  In other words, the values aren't being passed.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 12

Author Comment

by:piattnd
ID: 22888167
Ok so I talked to my scripting buddy and he said I should change the "onclick" portion to something similar to this:

<....onclick= FunctionName '" & variablename & "'>

I was able to get it to work for one of my variables, then tried to do the same thing for all of them, and now I consistently get the error:

"Wrong number of arguments or invalid property assignment"

Keep in mind I have adjusted my Function to reflect that I'm only trying to pass 1 variable for the time being (until I get the dang thing to work with 1 variable).

Thoughts?
0
 
LVL 14

Accepted Solution

by:
rejoinder earned 2000 total points
ID: 22888918
I know why my method returned null... please use this line instead;
StartAction.innerHTML = "<input type='button' value='Start Cleanup' name='start_cleanup' onClick='ProcessGroup """ & Offline & """,""" & Deleted & """,""" & Checked & """,""" & strExcelPath & """,""" & strMachineGroup & """,""" & strGroupLocation & """'>"

Drop the () and use double quotes plus ampersand to get your variables into the line.  So easy I forgot that you were passing variables from above :-)

I tested this by using a msgbox in the function and I was able to see all the variables being passed.
0
 
LVL 12

Author Closing Comment

by:piattnd
ID: 31513376
Holy cow, thank you so much!  I was literally bashing my head on my desk all morning......
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question