I have a timer which I would like to start after a button is clicked versus using the now() variable on launch. I'm lifting the code from MSFT Script Centre. I believe the correct implementation would be to wrap the
pbStartTime = Now
line around an if argument. However, I'm not sure about the logic behind button clicked. Thanks in advance.
<html>
<title>Report Generation</title>
<head>
<HTA:APPLICATION
APPLICATIONNAME="Report Generation"
SCROLL="No"
CAPTION="yes"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
SYSMENU="no"
BORDER="thin"
BORDERSTYLE="Normal"
CONTEXTMENU="no"
SELECTION="no">
</head>
<style>
BODY
{
background-color: buttonface;
Font: arial,sans-serif
margin-top: 10px;
margin-left: 20px;
margin-right: 20px;
margin-bottom: 5px;
}
.button
{
width: 91px;
height: 25px;
font-family: arial,sans-serif;
font-size: 8pt;
}
td
{
font-family: arial,sans-serif;
font-size: 10pt;
}
#scroll
{
height:100%;
overflow:auto;
}
SELECT.FixedWidth
{
width: 17em; /* maybe use px for pixels or pt for points here */
}
</style>
<script language="vbscript">
Dim pbTimerID
Dim pbHTML
Dim pbWaitTime
Dim pbHeight
Dim pbWidth
Dim pbBorder
Dim pbUnloadedColor
Dim pbLoadedColor
Dim pbStartTime
Dim WinWidth : WinWidth = 350
Dim WinHeight : WinHeight = 330
Window.ResizeTo WinWidth, WinHeight
Sub Sleep(lngDelay)
CreateObject("WScript.Shell").Run "Timeout /T " & lngDelay & " /nobreak", 0, True
End Sub
Sub CheckBoxChange
If CheckBox(0).Checked Then
ExecuteScoreCard
Else
MsgBox "CheckBox is not checked"
End If
End Sub
Sub ExecuteScoreCard()
disablebtns
Dim sitecode
Dim objExcel
Dim objWorkbook
Dim objSheet
Window_OnLoad
dim fso: set fso = CreateObject("Scripting.FileSystemObject")
dim path: path = fso.GetAbsolutePathName(".")
Set objExcel = CreateObject("Excel.Application")
objExcel.Automationsecurity = 1
Set objWorkbook = objExcel.Workbooks.Open(path & "\SCORECARD.xlsm")
Set objSheet = objWorkbook.Worksheets("Cover Tab")
sitecode = document.getElementById("sitecode").value
objSheet.Cells(4, 2) = sitecode
objExcel.Run "SCORECARD.xlsm!Module2.RefreshConns"
Sleep 60
objExcel.ActiveWorkbook.SaveAs path & "\Scorecards\" & "Scorecard_" & sitecode & "_" & Year(Now()) & Month(Now()) & Day(Now()) & "_" & Hour(Now()) & Minute(Now()) &".xlsm", 52
objExcel.ActiveWorkbook.Close
objExcel.Quit
DoAction1
enablebtns
End Sub
Sub Window_OnLoad
' Progress Bar Settings
pbWaitTime = 180 ' How many seconds the progress bar lasts
pbHeight = 20 ' Progress bar height
pbWidth= 285 ' Progress bar width
pbUnloadedColor="white" ' Color of unloaded area
pbLoadedColor="black" ' Color of loaded area
pbBorder="grey" ' Color of Progress bar border
' Don't edit these things
pbStartTime = now()
rProgressbar
pbTimerID = window.setInterval("rProgressbar", 200)
end sub
Sub rProgressbar
pbHTML = ""
pbSecsPassed = DateDiff("s",pbStartTime,Now)
pbMinsToGo = Int((pbWaitTime - pbSecsPassed) / 60)
pbSecsToGo = Int((pbWaitTime - pbSecsPassed) - (pbMinsToGo * 60))
if pbSecsToGo < 10 then
pbSecsToGo = "0" & pbSecsToGo
end if
pbLoadedWidth = (pbSecsPassed / pbWaittime) * pbWidth
pbUnloadedWidth = pbWidth - pbLoadedWidth
pbHTML = pbHTML & "<table border=1 bordercolor=" & pbBorder & " cellpadding=0 cellspacing=0 width=" & pbWidth & "><tr>"
pbHTML = pbHTML & "<th width=" & pbLoadedWidth & " height=" & pbHeight & "align=left bgcolor=" & pbLoadedColor & "></th>"
pbHTML = pbHTML & "<th width=" & pbUnloadedWidth & " height=" & pbHeight & "align=left bgcolor=" & pbUnLoadedColor & "></th>"
pbHTML = pbHTML & "</tr></table><br>"
pbHTML = pbHTML & "<table border=0 cellpadding=0 cellspacing=0 width=" & pbWidth & "><tr>"
pbHTML = pbHTML & "<td align=center width=" & pbWidth & "% height=" & pbHeight & ">" & pbMinsToGo & ":" & pbSecsToGo & " remaining</td>"
pbHTML = pbHTML & "</tr></table>"
progressbar.InnerHTML = pbHTML
if DateDiff("s",pbStartTime,Now) >= pbWaitTime then
StopTimer
end if
End Sub
Sub disablebtns
btnSubmit.disabled = True
btnExit.disabled = True
end Sub
Sub enablebtns
btnSubmit.disabled = False
btnExit.disabled = False
end Sub
Sub StopTimer
window.clearInterval(PBTimerID)
End Sub
Sub DoAction1
MsgBox ("Successfully generated scorecard.")
End Sub
Sub DoAction2
MsgBox ("Successfully generated report2.")
End Sub
Sub DoAction3
MsgBox ("Successfully generated report3.")
End Sub
Sub ExitProgram
window.close()
End Sub
</script>
<body>
Site Code: <input type="inputbox" name="sitecode" id="sitecode">
<br><br>
<input type="checkbox" name="CheckBox"> Scorecard
<br>
<input type="checkbox" name="CheckBox"> Report2
<br>
<input type="checkbox" name="CheckBox"> Report3
<br>
<br>
<span id = "progressbar"></span>
<br>
<div align="center">
<input type="button" name="accept" id="btnSubmit" value="Submit" onclick="CheckBoxChange" style="height:30px; width:100px">
<input type="button" name="abort" id="btnExit" value="Exit" onClick="ExitProgram" style="height:30px; width:100px">
<br>
</body>
</html>
You could add a Start button, just like your ABORT button. Modify your Sub Window_OnLoad rename it to Sub StartProcess or something. Then in the new Start button that you created, add an onClick="StartProcess" attribute.
<input type="Button" value="START" name="button2" onClick="StartProcess" class="button">
Related
I have an HTA that I want to pop into focus every hour as a reminder in case it's minimised or has the focus taken away from it. The problem I'm having is there's a Sub that's not recognising variables. I'll post the code and then explain:
<HTML>
<HEAD>
<style type="text/css">
p {font-family: 'Segoe UI Light'; font-size: 12pt}
td {font-family: 'Segoe UI Light'; font-size: 12pt}
input {font-family: 'Segoe UI Light'; font-size: 12pt}
body {font-family: 'Segoe UI Light'; font-size: 12pt; color: #4D4C5C; background-color: white}
</style>
<TITLE>QT MOE Upgrade</TITLE>
<HTA:APPLICATION ID="MOEUpgrade"
APPLICATIONNAME="MOE Upgrade"
BORDER="dialog"
SCROLL="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="no">
</HEAD>
<SCRIPT LANGUAGE="VBScript">
Dim iTimerID, strProcName, strProcID
Set objShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE '%MOEUpgrade.hta%'")
For Each objProcess in colProcesses
strProcName = objProcess.Name
strProcID = objProcess.ProcessID
Next
Sub Window_OnLoad
Set colItems = objWMIService.ExecQuery("Select * From Win32_VideoController WHERE AdapterDACType='Internal'")
For Each objItem in colItems
intHorizontal = objItem.CurrentHorizontalResolution
intVertical = objItem.CurrentVerticalResolution
Next
intLeft = (intHorizontal-1024)/2
intTop = (intVertical-600)/2
self.resizeto 1024,600
self.moveTo intLeft,intTop
self.focus()
iTimerID = window.setInterval("NagWindow",5000)
End Sub
Sub NagWindow
MsgBox strProcName & VBCRLF & strProcID
End Sub
Sub StartUpgradeNow
If MsgBox ("Are you sure you want to start the upgrade now?",vbYesNo+vbExclamation,"Confirm Upgrade") = vbYes Then
self.close()
End If
End Sub
</SCRIPT>
<BODY>
<div align="justify">
<p>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</p>
</div>
<div align="center">
<br>
<span class="tooltip" title="Click OK to start the upgrade now"><input type="button" name="OKButton" value=" OK " onClick="StartUpgradeNow" style="font-family: 'Segoe UI Light'"></span>
</div>
</BODY>
</HTML>
If you're so inclined, you can save this code as MOEUpgrade.hta and it should run for you without any issues. This code works and pops up a message box showing the strProcName and strProcID variables as expected, but when I change line 58 inside the NagWindow Sub to:
objShell.AppActivate strProcName.strProcID
It fails with an object required ('strProcName') error. Does anyone know why the variables are not being recognised when using the objShell function please but are when using MsgBox?
The reason for the error
Object required: 'strProcName'
is because you try to call strProcID as an object property of strProcName but it is clear from the code that both strProcName and strProcID are string variables.
If you are trying to use AppActivate with the Window Process Id you likely want to try;
Call objShell.AppActivate(strProcID)
Useful Links
WshShell.AppActivate doesn't seem to work in simple vbs script
Use AppActivate to change the active window
Ekkehard.Horner helped me a lot with the following code (already modified by me). But now I'm looking for a way to add a counter each time the MsgBox "message 1" is displayed.
<html>
<head>
<title>Sync Tool</title>
<HTA:APPLICATION
APPLICATIONNAME="Sync Tool"
ID="SyncTool"
VERSION="1.0.0"
BORDER="dialog"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SCROLL="no"
SINGLEINSTANCE="yes"
CONTEXTMENU="no"
SELECTION="no"/>
</head>
<script language="VBScript">
Set objShell = CreateObject("WScript.Shell")
Sub Window_OnLoad
Dim width, height
width = 330
height = 310
self.ResizeTo width, height
self.MoveTo (screen.AvailWidth-width)/2, (screen.AvailHeight-height)/2
End Sub
Sub OnClickButtonSyncNow()
' Box A
If BoxAA.checked Then
MsgBox "BoxAA"
Else
'Do nothing
End If
If BoxAB.checked Then
MsgBox "BoxAB"
Else
'Do nothing
End If
If BoxAC.checked Then
MsgBox "BoxAC"
Else
'Do nothing
End If
If BoxAD.checked Then
MsgBox "BoxAD"
Else
'Do nothing
End If
If BoxAE.checked Then
MsgBox "BoxAE"
Else
'Do nothing
End If
' Box B
If BoxBA.checked Then
MsgBox "BoxBA"
Else
'Do nothing
End If
If BoxBB.checked Then
MsgBox "BoxBB"
Else
'Do nothing
End If
If BoxBC.checked Then
MsgBox "BoxBC"
Else
'Do nothing
End If
If BoxBD.checked Then
MsgBox "BoxBD"
Else
'Do nothing
End If
If BoxBE.checked Then
MsgBox "BoxBE"
Else
'Do nothing
End If
Dim bF : bF = False
Dim c1
For Each c1 In Split("A B C D E F G H I J")
Dim n : n = c1
Dim b : Set b = document.getElementById(n)
If b.Checked Then
bF = True
End If
Next
If bF Then
MsgBox "all done"
Else
MsgBox "message 1"
End If
End Sub
Sub ExitTool()
window.close()
End Sub
</script>
<body bgcolor="firebrick">
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg th{font-family:Arial, sans-serif; font-size:14px; font-weight:normal; padding-top:0px ;padding-right:20px; padding-bottom:0px; padding-left:0px ;border-style:solid; border-width:0px; overflow:hidden; word-break:normal;}
.tg td{font-family:Arial, sans-serif; font-size:14px; padding-top:5px ;padding-right:10px; padding-bottom:0px; padding-left:0px ;border-style:solid; border-width:0px; overflow:hidden; word-break:normal;}
.tg .tg-header{color:#FFFB00; font-size:22px; font-weight:bold; font-family:Verdana, Geneva, sans-serif !important;}
.tg .tg-text{color:white; font-family:Verdana, Geneva, sans-serif !important; vertical-align:top}
.button {height:50px; width:136px; font-weight:bold; background-color:#555555; border: 2px solid #FFFB00; color:white; text-align:center; text-decoration:none; display:inline-block; font-size:16px;}
</style>
<table class="tg">
<tr>
<th class="tg-header">Box A</th>
<th class="tg-header">Box B</th>
</tr>
<tr>
<td class="tg-text"><input type="checkbox" name="BoxAA" id="A">AA</td>
<td class="tg-text"><input type="checkbox" name="BoxBA" id="B">BA</td>
</tr>
<tr>
<td class="tg-text"><input type="checkbox" name="BoxAB" id="C">AB</td>
<td class="tg-text"><input type="checkbox" name="BoxBB" id="D">BB</td>
</tr>
<tr>
<td class="tg-text"><input type="checkbox" name="BoxAC" id="E">AC</td>
<td class="tg-text"><input type="checkbox" name="BoxBC" id="F">BC</td>
</tr>
<tr>
<td class="tg-text"><input type="checkbox" name="BoxAD" id="G">AD</td>
<td class="tg-text"><input type="checkbox" name="BoxBD" id="H">BD</td>
</tr>
<tr>
<td class="tg-text"><input type="checkbox" name="BoxAE" id="I">AE</td>
<td class="tg-text"><input type="checkbox" name="BoxBE" id="J">BE</td>
</tr>
</table>
<br>
<input type="button" class="button" name="SyncNow" id="SyncNow" value="Sync Now" onclick="OnClickButtonSyncNow">
<input type="button" class="button" name="Exit" id="Exit" value="Exit" onclick="ExitTool">
</body>
</html>
The result I'm looking for is something like:
If bF Then
MsgBox "all done"
window.close()
Else
MsgBox "message 1" 'counter + 1
ElseIf counter = 2 Then
MsgBox "message 2" 'counter + 1
ElseIf counter = 3 Then
MsgBox "message 3" 'counter + 1
ElseIf counter = 4 Then
MsgBox "message 4" 'counter + 1
ElseIf counter = 5 Then
MsgBox "message 5" 'no more counting needed because of window.close()
window.close()
End If
I tried different things like Do..Loop, but my counter never goes beyond 1.
Really struggling to understand the basics of counting in VBScript.
You need a global variable to preserve the count across procedure calls and an array with the messages that you access using the counter as the index. Change your code to something like this:
<script language="VBScript">
Dim ctr : ctr = 0
messages = Array( "message 1", _
"message 2", _
"message 3", _
"message 4", _
"aborting"
)
...
Sub OnClickButtonSyncNow
...
If bF Then
MsgBox "all done"
window.Close
Else
MsgBox messages(ctr)
If ctr >= 4 Then window.Close
ctr = ctr + 1
End If
End Sub
...
</script>
I am trying to make this HTA working, what it does is to add up all value from each drop down list and search accordingly in a directory that can be selected from another button. I can only make the form of this HTA but dont know how to make the search working.
Also how can I move the directory selection button to the beginning of the line?
so user can pick up directory first then pick what they want to search.
<html>
<head>
<HTA:APPLICATION ID="2014-03"
applicationName="2014-03"
version="1.1"
BORDER="thin"
BORDERSTYLE="static"
CAPTION="Yes"
CONTEXTMENU="no"
ICON="C:\icon\32x32.ico"
INNERBORDER="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
NAVIGATABLE="no"
SCROLL="no"
SCROLLFLAT="no"
SELECTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
>
<SCRIPT LANGUAGE="VBScript">
Sub RunSearch_OnClick()
msgBox "Success!"
End Sub
Sub TestSub
For Each objOption in OptionChooser.Options
If objOption.Selected Then
Msgbox objOption.InnerText
End If
Next
End Sub
Sub TestSub1
For Each objOption in OptionChooser.Options
If objOption.Selected Then
Msgbox objOption.InnerText
End If
Next
End Sub
Sub WindowsLoad
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder (0, "Select The Folder To Enumerate :", (0))
If objFolder Is Nothing Then
Wscript.Quit
Else
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
End If
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(objPath)
For each objFile in objFolder.Files
If objFolder.Files.Count > 0 Then
Window.Document.Title = "Information For " & objPath
strHtml = strHtml & "<td><Font color = Blue>" & objFile.Name & "</font></Br>"
DataArea.InnerHtml = strHtml
End If
Next
End Sub
</SCRIPT>
</head>
<body>
<select id=extension size="1" name="OptionChooser" onChange="TestSub">
<option value="0">Selet File Type</option>
<option value="1">.txt</option>
<option value="2">.pdf</option>
<option value="3">.jpg</option>
<option value="4">.mp3</option>
</select>
<select id=year size="1" name="OptionChooser" onChange="TestSub1">
<option value="0">Select Year</option>
<option value="1">2014</option>
<option value="2">2013</option>
<option value="3">2012</option>
<option value="3">2011</option>
<option value="3">2010</option>
</select>
<select id=month size="1" name="OptionChooser" onChange="TestSub2">
<option value="0">Select Month</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="1">04</option>
<option value="2">05</option>
<option value="3">06</option>
<option value="1">07</option>
<option value="2">08</option>
<option value="3">09</option>
<option value="1">10</option>
<option value="2">11</option>
<option value="3">12</option>
</select>
<input Type = "Button" Value = "Browse For Folder" Name = "Run_Button" onClick = "WindowsLoad"><p></td>
<input type="button" value="Search" name="RunSearch">
</body>
</html>
The final HTA should look like this, the search result need to be displayed below the drop down list as text file within a scrollable window and having full path of the files.
In next HTA only necessary changes made to display the search result below the drop down list as a scrollable text area and having full paths of the files.
On start, a user is prompted to select initial directory (see WindowsLoad call within the Window_Onload procedure; then all files are displayed as no search criteria selected yet.
Search completed in code for extension only to show a possible how-to approach (one of few).
Used a simple StyleSheet.
Some variables defined script (application) global to keep their visibility within all procedures.
Further elementary changes: see the code below.
The code:
<html>
<head>
<HTA:APPLICATION ID="2014-03"
applicationName="2014-03"
version="1.1"
BORDER="thin"
BORDERSTYLE="static"
CAPTION="Yes"
CONTEXTMENU="no"
ICON="C:\icon\32x32.ico"
INNERBORDER="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
NAVIGATABLE="no"
SCROLL="no"
SCROLLFLAT="no"
SELECTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
>
<!--
'************************
'* StyleSheet
'************************
-->
<style>
BODY
{
background-color: buttonface;
font-family: Arial, Helvetica, sans-serif;
font-size: 8pt;
margin-top: 2px;
margin-left: 8px;
margin-right: 3px;
margin-bottom: 3px;
}
.button
{
font-family: Arial, Helvetica, sans-serif;
font-size: 8pt;
width: 40px;
}
textarea
{
background-color: yellow;
font-family: Arial;
font-size: 8pt;
margin-left: 3px;
margin-right: 3px;
}
</style>
<SCRIPT LANGUAGE="VBScript">
'************************
'* Global Variables
'************************
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
objPath = ""
strHtml = ""
Chooser0 = ""
Chooser1 = ""
Chooser2 = ""
'************************
'* Window_Onload
'************************
Sub Window_Onload
self.Focus()
self.ResizeTo 800,600
DataArea.InnerHTML = "<textarea cols=122 rows=25></textarea>"
WindowsLoad
End Sub
Sub RunSearch_OnClick()
'msgBox "Success!"
WindowsLoad
End Sub
Sub TestSub
If OptionChooser.Value = "0" Then
Chooser0 = ""
Else
For Each objOption in OptionChooser.Options
If objOption.Selected Then
Chooser0 = objOption.InnerText
Exit For
End If
Next
End If
End Sub
Sub TestSub1
For Each objOption in OptionChooser1.Options
If objOption.Selected Then
Msgbox objOption.InnerText
End If
Next
End Sub
Sub TestSub2
For Each objOption in OptionChooser2.Options
If objOption.Selected Then
Msgbox objOption.InnerText
End If
Next
End Sub
Sub whichFolder
prevPath = objPath
Set objFolder = objShell.BrowseForFolder _
(0, "Select The Folder To Enumerate :", (0))
If objFolder Is Nothing Then
msgBox "Bye!"
self.Close()
Else
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
End If
If prevPath <> "" then WindowsLoad
End Sub
Sub WindowsLoad
If objPath = "" Then
whichFolder
End If
Set objFolder = objFso.GetFolder(objPath)
Window.Document.Title = "Information For " & objPath & " " & Chooser0
strHtml = "<textarea cols=122 rows=25>"
ShowSubFolders objFolder, Chooser0
DataArea.InnerHtml = strHtml
End Sub
Sub ShowSubFolders(fFolder, strExt)
'strHtml = strHtml & Chr(10) & fFolder.Path & Chr(10)
Set objFolder = objFSO.GetFolder(fFolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
If strExt = "" OR UCase(strExt) = _
"." & UCase(objFSO.GetExtensionName(objFile.name)) Then
strHtml = strHtml & objFile.Path & Chr(10)
End If
Next
For Each Subfolder in fFolder.SubFolders
ShowSubFolders Subfolder, strExt
Next
End Sub
</SCRIPT>
</head>
<body>
<select id=extension size="1" name="OptionChooser" onChange="TestSub">
<option value="0">Selet File Type</option>
<option value="1">.txt</option>
<option value="2">.pdf</option>
<option value="3">.jpg</option>
<option value="4">.mp3</option>
</select>
<select id=year size="1" name="OptionChooser1" onChange="TestSub1">
<option value="0">Select Year</option>
<option value="1">2014</option>
<option value="2">2013</option>
<option value="3">2012</option>
<option value="3">2011</option>
<option value="3">2010</option>
</select>
<select id=month size="1" name="OptionChooser2" onChange="TestSub2">
<option value="0">Select Month</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="1">04</option>
<option value="2">05</option>
<option value="3">06</option>
<option value="1">07</option>
<option value="2">08</option>
<option value="3">09</option>
<option value="1">10</option>
<option value="2">11</option>
<option value="3">12</option>
</select>
<input Type = "button" Value = "Browse For Folder"
Name = "Run_Button" onClick = "whichFolder"><p>
<input type="button" value="Search" name="RunSearch"><p>
<div id="DataArea" name="DataArea"></div>
</body>
</html>
Set IE = CreateObject("internetexplorer.Application")
IE.Visible = 1
IE.navigate "https://dashboard.opendns.com/settings/"
Do While (IE.Busy)
WScript.Sleep 10
Loop
Set Helem = IE.document.getElementByID("username")
Helem.Value = " "
Set Helem = IE.document.getElementByID("password")
Helem.Value = " "
IE.Application.document.getElementById("sign-in").Click
WScript.Sleep 10
<a id="dip22332965" title="Update this text" href="#"
onclick="update_ip(22332965);return false" img width="11" height="13"
style="border: 0pt none; margin-bottom: 1px;"
src="https://d2v7u03x06aro3.cloudfront.net/img/icon_update_small.gif">
I successfully sign in after clicking the button, but how can I click on image automatically as mentioned above script?
How can I perform a simple validation on this HTA form to make sure that data is inputted and an option is selected? This should be simple, I'm not sure what I'm missing.
Any answers or suggestions would be appreciated.
Thanks.
<html><head><title>Write data to text file</title>
<HTA:APPLICATION
border="thin"
borderStyle="normal"
caption="yes"
maximizeButton="no"
minimizeButton="yes"
showInTaskbar="yes"
innerBorder="yes"
navigable="yes"
scroll="auto"
scrollFlat="yes" />
<script language="javascript">
window.resizeTo(480,150)
function Writedata()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var write_id;
write_id = document.getElementById('write_id').value ;
alert('The data has been written to \n' + write_id);
var s = fso.OpenTextFile(write_id, 8, true);
s.WriteLine(document.getElementById('name_id').value);
s.Close();
}
</script>
</head>
<body>
<table>
<tr>
<h3>Input some information</h3>
<form>
<td>Input: </td><td><input type="text" name="name" value="" id="name_id"></td>
<td><select id="write_id">
<option name="write" value="">Select an Option</option>
<option name="write" value="C:\temp\option1.txt">Option1</option>
<option name="write" value="C:\temp\option2.txt">Option2</option>
</select></td>
<td><input type="button" onclick="Writedata()" value="submit"></td>
</form>
</tr>
</table>
</body>
</html>
I was stumped, so I rewrote this in vbscript.
I have included bits of what I did to give you an idea of how to write to a text file, and validate your form with an HTA.
The vbscript:
Set wshShell = CreateObject( "WScript.Shell" )
strSender = wshShell.ExpandEnvironmentStrings( "%USERNAME%" ) ' Get the current Username
Dim Checkmark
Sub Validate
If form.Flag.checked = True Then ' Find out if your Checkbox is checked
Checkmark = "*"
Else
Checkmark = ""
End IF
If form.field1.value = "" Then ' Validate the form
alert "Please enter an number!", "0", "Title"
ElseIf IsNumeric(form.field1.value) = False Then
alert "Please enter a valid number!", "0", "Title"
ElseIf form.drop_down1.Value = "" Then
alert "Please select a save location!", "0", "Title"
ElseIf form.field1.value < 100000 Then
alert "Please enter a six digit number!", "0", "Title"
ElseIf form.field1.value > 999999 Then
alert "Please enter a six digit number!", "0", "Title"
Else
SaveData
End If
End Sub
Sub SaveData ' Write data to a text file
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(form.drop_down1.Value) Then
Set objFile = objFSO.OpenTextFile(form.drop_down1.Value, 8)
strLine = form.field1.value & vbtab & Checkmark & vbtab & strSender & vbtab & Now ' fields that will be written
objFile.WriteLine strLine
MsgBox "The Information was successfully written to the file.", "0", "Title"
objFile.Close
Else
Set objFile = objFSO.CreateTextFile(form.drop_down1.Value) ' If file does not exist, create file
strLine = form.field1.value & vbtab & Checkmark & vbtab & strSender & vbtab & Now
objFile.WriteLine strLine
MsgBox "The Information was successfully written to the file.", "0", "Title"
objFile.Close
End If
End Sub
The HTML:
<form name="form">
<h2>Imput</h2>
<tr><td><lable>Data: </lable></td><td><input type="text" name="field1" size="25"></td> </tr>
<tr><td><lable>Save Location: </lable></td><td><select name="drop_down1">
<option type="text" name="select" value="">Select an option</option>
<option type="text" value="SavePath1...">SavePath1</option>
<option type="text" value="SavePath2...">SavePath2</option>
<option type="text" value="SavePath3...">SavePath3</option>
</select></td><td><input type="checkbox" name="Flag" value="">Flag *</td></tr>
</table>
<input type="button" value="Submit" onClick="Validate">
<input type='reset' id='ResetFields' value='Clear Fields' />
</form>