bsharath
asked on
Script that works dynamically cheking the ini file. Code for Hta need so changes.
Hi,
Script that works dynamically cheking the ini file. Code for Hta need so changes.
The below script checks the ini file and shows the Hta. I want it to record any selection made by the users to seperate Txt files with
Username_Machinename.txt and save to the UNC path
Can anyone help with this code please.
REgards
Sharath
Script that works dynamically cheking the ini file. Code for Hta need so changes.
The below script checks the ini file and shows the Hta. I want it to record any selection made by the users to seperate Txt files with
Username_Machinename.txt and save to the UNC path
Can anyone help with this code please.
REgards
Sharath
<html>
<head>
<title>Tabs.hta</title>
<HTA:Application
ID = "HTA"
ApplicationName = "Tabs"
Border = "thin"
BorderStyle = "normal"
Caption = "yes"
ContextMenu="yes"
Icon = ""
InnerBorder="no"
MaximizeButton = "yes"
MinimizeButton = "yes"
Navigable="yes"
Scroll="yes"
SrollFlat="no"
Selection="yes"
ShowInTaskBar = "yes"
SingleInstance = "yes"
SysMenu = "yes"
Version = "1.0"
>
<script language="VBscript">
Dim sItem
Dim aPanels
Dim el
Dim iPanelCount
Dim sConfigFile
Dim objINI
Private Sub Window_OnLoad
Set objINI = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
sConfigFile = "Config.ini"
Set objConfig = objFSO.OpenTextFile(sConfigFile, intForReading, False)
strHeading = ""
While Not objConfig.AtEndOfStream
strLine = objConfig.ReadLine
If strLine <> "" Then
If Left(strLine, 1) = "[" Then
strHeading = Mid(strLine, 2, Len(strLine) - 2)
Else
If objINI.Exists(strHeading) = True Then
objINI(strHeading) = objINI(strHeading) & "|" & strLine
Else
objINI.Add strHeading, strLine
End If
End If
End If
Wend
iPanelCount = objINI.Count
objConfig.Close
strHTMLCode = ""
i = 0
For Each strHeading In objINI
i = i + 1
If i = 1 Then
strHTMLCode = "<span class=""tabs tabsSelected"" id=""tab" & i & """ onclick=""panel(" & i & ")"">" & strHeading & "</span>"
Else
strHTMLCode = strHTMLCode & "<span class=""tabs tabsNotSelected"" id=""tab" & i & """ onclick=""panel(" & i & ")"">" & strHeading & "</span>"
End If
Next
i = 0
For Each strHeading In objINI
i = i + 1
If i = 1 Then
strHTMLCode = strHTMLCode & "<div class=""panel"" id=""panel" & i & """ style=""display:block"">"
Else
strHTMLCode = strHTMLCode & "<div class=""panel"" id=""panel" & i & """ style=""display:none"">"
End If
strHTMLCode = strHTMLCode & "<hr color=""black"">"
strHTMLCode = strHTMLCode & "<table border=""0"" width=""100%"">"
strHTMLCode = strHTMLCode & "<tr valign=""top"">"
strHTMLCode = strHTMLCode & "<td>"
strHTMLCode = strHTMLCode & "<span id=""panelContents" & i & """ class=""head"">"
For Each strItem In Split(objINI(strHeading), "|")
strHTMLCode = strHTMLCode & "<br><input type=""checkbox"" id=""chk_" & Replace(strItem, " ", "_") & """ name=""chk_" & Replace(strItem, " ", "_") & """>" & strItem
Next
strHTMLCode = strHTMLCode & "</span>"
strHTMLCode = strHTMLCode & "<br><br>"
strHTMLCode = strHTMLCode & "TAB " & i & ""
strHTMLCode = strHTMLCode & "</td>"
strHTMLCode = strHTMLCode & "</tr>"
strHTMLCode = strHTMLCode & "</table>"
strHTMLCode = strHTMLCode & "</div>"
Next
span_tabspan.InnerHTML = strHTMLCode
End Sub
Private Sub Panel(tab)
For i = 1 To iPanelCount
If i = tab Then
document.getElementById("tab" & i).className = "tabs tabsSelected"
document.getElementById("panel" & i).style.display = "block"
Else
document.getElementById("tab" & i).className = "tabs tabsNotSelected"
document.getElementById("panel" & i).style.display = "none"
End If
Next
End Sub
Sub AddCheck
strHTML = panelContents2.InnerHTML
strHTML = strHTML & "<input id=" & intCheckCount & " type=" & Chr(34) & "CheckBox" & Chr(34) & _
" name=" & Chr(34) & "chkEnabled" & Chr(34) & "value= " & Chr(34) & "CheckBox" & intCheckCount & Chr(34) & " onClick=" & Chr(34) & _
"NewCheckSubroutine" & Chr(34) & ">" & " <BR>"
panelContents2.InnerHTML = strHTML
End Sub
Sub OnClickButtonSubmit()
'This method will be called when button "Submit" is clicked
'Add your code here
Dim objFSO, objFile, objShell
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Change the file name and path on the next line'
Set objFile = objFSO.OpenTextFile("C:\eeTesting\TabsOutput.txt",8,True)
objFile.WriteLine Now & vbTab & objShell.ExpandEnvironmentStrings("%USERNAME%") & vbTab & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
objFile.Close
Set objShell = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub
</script>
<style type="text/css">
body,td,th { font-family:Arial }
.head { font-size:110%; font-weight:bold }
.panel {
background-color: white;
border: solid 1px black;
height: 410px;
padding: 5px;
position: relative;
width: 650px;
z-index: 0;
}
.tabs {
border-collapse: collapse;
color: black;
cursor: pointer;
cursor: hand;
font-family: arial;
font-size: 9pt;
font-weight: bold;
margin-top: 4px;
padding: 2px 4px 0px 4px;
position: relative;
text-align: center;
text-decoration: none;
z-index: 1;
}
.tabsNotSelected {
background-color: wheat;
border: solid 1px black;
}
.tabsSelected {
background-color: white;
border-color: black black white black;
border-style: solid solid solid solid;
border-width: 1px 1px 1px 1px;
}
</style>
</head>
<body>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650">
<tr valign="top">
<td align="right" colspan="2">
<span class="head">Tabs in HTA!</span>
<br>
</td>
</tr>
<tr valign="top">
<td colspan="2">
<span id="span_tabspan"></span>
</td>
</tr>
</table>
<input type="button" name="Submit" id="Submit" value="Submit" onclick="OnClickButtonSubmit">
</body>
</html>
ASKER
In the ini if i have 4 checkboxes and when opened HTA i select 2 Checkboxes. I want those details logged into the log
ASKER
Any views
Hi Sharath, do you want the selection recorded to a text file when the user clicks on Submit? That shouldn't be too hard....I can fix that up tomorrow.
Regards,
Rob.
Regards,
Rob.
ASKER
Thanks Rob
The whole idea is not troubling you on different additions to HTA :-)
if this can be made user friendly in just adding options in ini to add Checkboxes\Radio buttons\Comment box
With Submit button and 2 logos in the top left and right
Then all that is needed for me. So when ever needed only weekly basis when i want to send this for feedback with different options it would be easy for me to add
All this accordingly has to be into a txt file or csv that later can combine.
The whole idea is not troubling you on different additions to HTA :-)
if this can be made user friendly in just adding options in ini to add Checkboxes\Radio buttons\Comment box
With Submit button and 2 logos in the top left and right
Then all that is needed for me. So when ever needed only weekly basis when i want to send this for feedback with different options it would be easy for me to add
All this accordingly has to be into a txt file or csv that later can combine.
OK, try this. I have had to change the way the config file is written, so that the HTA knows what "type" of control you want.
Here is a sample Config.ini I tested with:
[Maths]
checkbox:Install a
checkbox:Install b
checkbox:Install c
radio:Option a
radio:Option b
textarea:Comments
[Science]
checkbox:Install d
checkbox:Install e
checkbox:Install f
radio:Option c
radio:Option d
Note that each option MUST have different text. You cannot use, for example, Install A under more than one heading.
You can change strLogFolder to specify the location to save the results.
Regards,
Rob.
Here is a sample Config.ini I tested with:
[Maths]
checkbox:Install a
checkbox:Install b
checkbox:Install c
radio:Option a
radio:Option b
textarea:Comments
[Science]
checkbox:Install d
checkbox:Install e
checkbox:Install f
radio:Option c
radio:Option d
Note that each option MUST have different text. You cannot use, for example, Install A under more than one heading.
You can change strLogFolder to specify the location to save the results.
Regards,
Rob.
<html>
<head>
<title>Tabs.hta</title>
<HTA:Application
ID = "HTA"
ApplicationName = "Tabs"
Border = "thin"
BorderStyle = "normal"
Caption = "yes"
ContextMenu="yes"
Icon = ""
InnerBorder="no"
MaximizeButton = "yes"
MinimizeButton = "yes"
Navigable="yes"
Scroll="yes"
ScrollFlat="no"
Selection="yes"
ShowInTaskBar = "yes"
SingleInstance = "yes"
SysMenu = "yes"
Version = "1.0"
>
<script language="VBscript">
Dim sItem
Dim aPanels
Dim el
Dim iPanelCount
Dim sConfigFile
Dim objINI
Private Sub Window_OnLoad
Set objINI = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
sConfigFile = "Config.ini"
Set objConfig = objFSO.OpenTextFile(sConfigFile, intForReading, False)
strHeading = ""
While Not objConfig.AtEndOfStream
strLine = objConfig.ReadLine
If strLine <> "" Then
If Left(strLine, 1) = "[" Then
strHeading = Mid(strLine, 2, Len(strLine) - 2)
Else
If objINI.Exists(strHeading) = True Then
objINI(strHeading) = objINI(strHeading) & "|" & strLine
Else
objINI.Add strHeading, strLine
End If
End If
End If
Wend
iPanelCount = objINI.Count
objConfig.Close
strHTMLCode = ""
i = 0
For Each strHeading In objINI
i = i + 1
If i = 1 Then
strHTMLCode = "<span class=""tabs tabsSelected"" id=""tab" & i & """ onclick=""panel(" & i & ")"">" & strHeading & "</span>"
Else
strHTMLCode = strHTMLCode & "<span class=""tabs tabsNotSelected"" id=""tab" & i & """ onclick=""panel(" & i & ")"">" & strHeading & "</span>"
End If
Next
i = 0
For Each strHeading In objINI
i = i + 1
strDefaultChecked = " CHECKED"
If i = 1 Then
strHTMLCode = strHTMLCode & "<div class=""panel"" id=""panel" & i & """ style=""display:block"">"
Else
strHTMLCode = strHTMLCode & "<div class=""panel"" id=""panel" & i & """ style=""display:none"">"
End If
strHTMLCode = strHTMLCode & "<hr color=""black"">"
strHTMLCode = strHTMLCode & "<table border=""0"" width=""100%"">"
strHTMLCode = strHTMLCode & "<tr valign=""top"">"
strHTMLCode = strHTMLCode & "<td>"
strHTMLCode = strHTMLCode & "<span id=""panelContents" & i & """ class=""head"">"
For Each strControl In Split(objINI(strHeading), "|")
strControlType = Left(strControl, InStr(strControl, ":") - 1)
strItem = Mid(strControl, InStr(strControl, ":") + 1)
'MsgBox "Creating chk_" & Replace(strItem, " ", "_") & " on panelContents" & i
If LCase(strControlType) = "checkbox" Then
strHTMLCode = strHTMLCode & "<br><input type=""checkbox"" id=""chk_" & Replace(strItem, " ", "_") & """ name=""chk_" & Replace(strItem, " ", "_") & """>" & strItem
ElseIf LCase(strControlType) = "radio" Then
strHTMLCode = strHTMLCode & "<br><input type=""radio"" id=""opt_" & Replace(strHeading, " ", "_") & """ name=""opt_" & Replace(strHeading, " ", "_") & """ value=""opt_" & Replace(strItem, " ", "_") & """" & strDefaultChecked & ">" & strItem
strDefaultChecked = ""
ElseIf LCase(strControlType) = "textarea" Then
strHTMLCode = strHTMLCode & "<br>" & strItem & "<br><textarea id=""txt_" & Replace(strItem, " ", "_") & """ name=""txt_" & Replace(strItem, " ", "_") & """ rows=""6"" cols=""75""></textarea>"
End If
Next
strHTMLCode = strHTMLCode & "</span>"
strHTMLCode = strHTMLCode & "<br><br>"
strHTMLCode = strHTMLCode & "TAB " & i
strHTMLCode = strHTMLCode & "</td>"
strHTMLCode = strHTMLCode & "</tr>"
strHTMLCode = strHTMLCode & "</table>"
strHTMLCode = strHTMLCode & "</div>"
Next
span_tabspan.InnerHTML = strHTMLCode
End Sub
Private Sub Panel(tab)
For i = 1 To iPanelCount
If i = tab Then
document.getElementById("tab" & i).className = "tabs tabsSelected"
document.getElementById("panel" & i).style.display = "block"
Else
document.getElementById("tab" & i).className = "tabs tabsNotSelected"
document.getElementById("panel" & i).style.display = "none"
End If
Next
End Sub
'Sub AddCheck
' strHTML = panelContents2.InnerHTML
' strHTML = strHTML & "<input id=" & intCheckCount & " type=" & Chr(34) & "CheckBox" & Chr(34) & _
' " name=" & Chr(34) & "chkEnabled" & Chr(34) & "value= " & Chr(34) & "CheckBox" & intCheckCount & Chr(34) & " onClick=" & Chr(34) & _
' "NewCheckSubroutine" & Chr(34) & ">" & " <BR>"
' panelContents2.InnerHTML = strHTML
'End Sub
Sub OnClickButtonSubmit()
'MsgBox document.getElementById("chk_Install_a").Checked
'Exit Sub
'This method will be called when button "Submit" is clicked
'Add your code here
Dim objFSO, objFile, objShell
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Change the file name and path on the next line'
strLogFolder = "\\d09790ring\c$\temp\temp\test script\"
If Right(strLogFolder, 1) <> "\" Then strLogFolder = strLogFolder & "\"
'MsgBox "Creating " & strLogFolder & objShell.ExpandEnvironmentStrings("%USERNAME%") & "_" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & ".txt"
Set objFile = objFSO.OpenTextFile(strLogFolder & objShell.ExpandEnvironmentStrings("%USERNAME%") & "_" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & ".txt", 8, True)
objFile.WriteLine Now & vbTab & objShell.ExpandEnvironmentStrings("%USERNAME%") & vbTab & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
For Each strHeading In objINI
objFile.WriteLine "[" & strHeading & "]"
For Each strControl In Split(objINI(strHeading), "|")
strControlType = Left(strControl, InStr(strControl, ":") - 1)
strItem = Mid(strControl, InStr(strControl, ":") + 1)
If LCase(strControlType) = "checkbox" Then
objFile.WriteLine strItem & ": " & document.getElementById("chk_" & Replace(strItem, " ", "_")).Checked
ElseIf LCase(strControlType) = "radio" Then
MsgBox document.getElementById("opt_" & Replace(strHeading, " ", "_")).Value & VbCrLf & "opt_" & Replace(strItem, " ", "_")
If document.getElementById("opt_" & Replace(strHeading, " ", "_")).Value = "opt_" & Replace(strItem, " ", "_") Then
objFile.WriteLine strItem & ": Selected"
Else
objFile.WriteLine strItem & ": Not selected"
End If
ElseIf LCase(strControlType) = "textarea" Then
objFile.WriteLine strItem & ": " & document.getElementById("txt_" & Replace(strItem, " ", "_")).Value
End If
Next
Next
objFile.WriteLine ""
objFile.Close
Set objShell = Nothing
Set objFile = Nothing
Set objFSO = Nothing
MsgBox "Thank you. Your information has been submitted."
End Sub
</script>
<style type="text/css">
body,td,th { font-family:Arial }
.head { font-size:110%; font-weight:bold }
.panel {
background-color: white;
border: solid 1px black;
height: 410px;
padding: 5px;
position: relative;
width: 650px;
z-index: 0;
}
.tabs {
border-collapse: collapse;
color: black;
cursor: pointer;
cursor: hand;
font-family: arial;
font-size: 9pt;
font-weight: bold;
margin-top: 4px;
padding: 2px 4px 0px 4px;
position: relative;
text-align: center;
text-decoration: none;
z-index: 1;
}
.tabsNotSelected {
background-color: wheat;
border: solid 1px black;
}
.tabsSelected {
background-color: white;
border-color: black black white black;
border-style: solid solid solid solid;
border-width: 1px 1px 1px 1px;
}
</style>
</head>
<body>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650">
<tr valign="top">
<td align="left">
<img src="\\server\share\img1.jpg">
</td>
<td align="center">
<span class="head">Tabs in HTA!</span>
</td>
<td align="right">
<img src="\\server\share\img2.jpg">
</td>
</tr>
<tr valign="top">
<td colspan="3">
<br><br><span id="span_tabspan"></span>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<br><br><input type="button" name="Submit" id="Submit" value="Submit" onclick="OnClickButtonSubmit">
</td>
</tr>
</table>
</body>
</html>
ASKER
Thanks Rob
Even though the log file path is right i get path not found while submit
Can we do a few checks like few checkboxes has to be checked in each sheet
Can we retrieve the machine name and logged in user name on the screen and the log
By default it should be shown on all sheets or outside the tabs
Even though the log file path is right i get path not found while submit
Can we do a few checks like few checkboxes has to be checked in each sheet
Can we retrieve the machine name and logged in user name on the screen and the log
By default it should be shown on all sheets or outside the tabs
To trouble shoot the log file location, uncomment this line:
'MsgBox "Creating " & strLogFolder & objShell.ExpandEnvironment Strings("% USERNAME%" ) & "_" & objShell.ExpandEnvironment Strings("% COMPUTERNA ME%") & ".txt"
and run it again to see where it's trying to write to.
For checking some checkboxes, I'm not sure how we could make it very dynamic if you change those boxes. What sort of check do you need?
I have also added the visible username and computer name outside the tabs, and in the log file.
Regards,
Rob.
'MsgBox "Creating " & strLogFolder & objShell.ExpandEnvironment
and run it again to see where it's trying to write to.
For checking some checkboxes, I'm not sure how we could make it very dynamic if you change those boxes. What sort of check do you need?
I have also added the visible username and computer name outside the tabs, and in the log file.
Regards,
Rob.
<html>
<head>
<title>Tabs.hta</title>
<HTA:Application
ID = "HTA"
ApplicationName = "Tabs"
Border = "thin"
BorderStyle = "normal"
Caption = "yes"
ContextMenu="yes"
Icon = ""
InnerBorder="no"
MaximizeButton = "yes"
MinimizeButton = "yes"
Navigable="yes"
Scroll="yes"
ScrollFlat="no"
Selection="yes"
ShowInTaskBar = "yes"
SingleInstance = "yes"
SysMenu = "yes"
Version = "1.0"
>
<script language="VBscript">
Dim sItem
Dim aPanels
Dim el
Dim iPanelCount
Dim sConfigFile
Dim objINI
Private Sub Window_OnLoad
Set objShell = CreateObject("WScript.Shell")
span_user.InnerHTML = "Username: " & objShell.ExpandEnvironmentStrings("%USERNAME%") & " " & "Computer name: " & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Set objINI = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
sConfigFile = "Config.ini"
Set objConfig = objFSO.OpenTextFile(sConfigFile, intForReading, False)
strHeading = ""
While Not objConfig.AtEndOfStream
strLine = objConfig.ReadLine
If strLine <> "" Then
If Left(strLine, 1) = "[" Then
strHeading = Mid(strLine, 2, Len(strLine) - 2)
Else
If objINI.Exists(strHeading) = True Then
objINI(strHeading) = objINI(strHeading) & "|" & strLine
Else
objINI.Add strHeading, strLine
End If
End If
End If
Wend
iPanelCount = objINI.Count
objConfig.Close
strHTMLCode = ""
i = 0
For Each strHeading In objINI
i = i + 1
If i = 1 Then
strHTMLCode = "<span class=""tabs tabsSelected"" id=""tab" & i & """ onclick=""panel(" & i & ")"">" & strHeading & "</span>"
Else
strHTMLCode = strHTMLCode & "<span class=""tabs tabsNotSelected"" id=""tab" & i & """ onclick=""panel(" & i & ")"">" & strHeading & "</span>"
End If
Next
i = 0
For Each strHeading In objINI
i = i + 1
strDefaultChecked = " CHECKED"
If i = 1 Then
strHTMLCode = strHTMLCode & "<div class=""panel"" id=""panel" & i & """ style=""display:block"">"
Else
strHTMLCode = strHTMLCode & "<div class=""panel"" id=""panel" & i & """ style=""display:none"">"
End If
strHTMLCode = strHTMLCode & "<hr color=""black"">"
strHTMLCode = strHTMLCode & "<table border=""0"" width=""100%"">"
strHTMLCode = strHTMLCode & "<tr valign=""top"">"
strHTMLCode = strHTMLCode & "<td>"
strHTMLCode = strHTMLCode & "<span id=""panelContents" & i & """ class=""head"">"
For Each strControl In Split(objINI(strHeading), "|")
strControlType = Left(strControl, InStr(strControl, ":") - 1)
strItem = Mid(strControl, InStr(strControl, ":") + 1)
'MsgBox "Creating chk_" & Replace(strItem, " ", "_") & " on panelContents" & i
If LCase(strControlType) = "checkbox" Then
strHTMLCode = strHTMLCode & "<br><input type=""checkbox"" id=""chk_" & Replace(strItem, " ", "_") & """ name=""chk_" & Replace(strItem, " ", "_") & """>" & strItem
ElseIf LCase(strControlType) = "radio" Then
strHTMLCode = strHTMLCode & "<br><input type=""radio"" id=""opt_" & Replace(strHeading, " ", "_") & """ name=""opt_" & Replace(strHeading, " ", "_") & """ value=""opt_" & Replace(strItem, " ", "_") & """" & strDefaultChecked & ">" & strItem
strDefaultChecked = ""
ElseIf LCase(strControlType) = "textarea" Then
strHTMLCode = strHTMLCode & "<br>" & strItem & "<br><textarea id=""txt_" & Replace(strItem, " ", "_") & """ name=""txt_" & Replace(strItem, " ", "_") & """ rows=""6"" cols=""75""></textarea>"
End If
Next
strHTMLCode = strHTMLCode & "</span>"
strHTMLCode = strHTMLCode & "<br><br>"
strHTMLCode = strHTMLCode & "TAB " & i
strHTMLCode = strHTMLCode & "</td>"
strHTMLCode = strHTMLCode & "</tr>"
strHTMLCode = strHTMLCode & "</table>"
strHTMLCode = strHTMLCode & "</div>"
Next
span_tabspan.InnerHTML = strHTMLCode
End Sub
Private Sub Panel(tab)
For i = 1 To iPanelCount
If i = tab Then
document.getElementById("tab" & i).className = "tabs tabsSelected"
document.getElementById("panel" & i).style.display = "block"
Else
document.getElementById("tab" & i).className = "tabs tabsNotSelected"
document.getElementById("panel" & i).style.display = "none"
End If
Next
End Sub
'Sub AddCheck
' strHTML = panelContents2.InnerHTML
' strHTML = strHTML & "<input id=" & intCheckCount & " type=" & Chr(34) & "CheckBox" & Chr(34) & _
' " name=" & Chr(34) & "chkEnabled" & Chr(34) & "value= " & Chr(34) & "CheckBox" & intCheckCount & Chr(34) & " onClick=" & Chr(34) & _
' "NewCheckSubroutine" & Chr(34) & ">" & " <BR>"
' panelContents2.InnerHTML = strHTML
'End Sub
Sub OnClickButtonSubmit()
'MsgBox document.getElementById("chk_Install_a").Checked
'Exit Sub
'This method will be called when button "Submit" is clicked
'Add your code here
Dim objFSO, objFile, objShell
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Change the file name and path on the next line'
strLogFolder = "\\server\logs\"
If Right(strLogFolder, 1) <> "\" Then strLogFolder = strLogFolder & "\"
'MsgBox "Creating " & strLogFolder & objShell.ExpandEnvironmentStrings("%USERNAME%") & "_" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & ".txt"
Set objFile = objFSO.OpenTextFile(strLogFolder & objShell.ExpandEnvironmentStrings("%USERNAME%") & "_" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & ".txt", 8, True)
objFile.WriteLine "Time: " & Now & VbCrLf & "Username: " & objShell.ExpandEnvironmentStrings("%USERNAME%") & VbCrLf & "Computer name:" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
For Each strHeading In objINI
objFile.WriteLine "[" & strHeading & "]"
For Each strControl In Split(objINI(strHeading), "|")
strControlType = Left(strControl, InStr(strControl, ":") - 1)
strItem = Mid(strControl, InStr(strControl, ":") + 1)
If LCase(strControlType) = "checkbox" Then
objFile.WriteLine strItem & ": " & document.getElementById("chk_" & Replace(strItem, " ", "_")).Checked
ElseIf LCase(strControlType) = "radio" Then
MsgBox document.getElementById("opt_" & Replace(strHeading, " ", "_")).Value & VbCrLf & "opt_" & Replace(strItem, " ", "_")
If document.getElementById("opt_" & Replace(strHeading, " ", "_")).Value = "opt_" & Replace(strItem, " ", "_") Then
objFile.WriteLine strItem & ": Selected"
Else
objFile.WriteLine strItem & ": Not selected"
End If
ElseIf LCase(strControlType) = "textarea" Then
objFile.WriteLine strItem & ": " & document.getElementById("txt_" & Replace(strItem, " ", "_")).Value
End If
Next
Next
objFile.WriteLine ""
objFile.Close
Set objShell = Nothing
Set objFile = Nothing
Set objFSO = Nothing
MsgBox "Thank you. Your information has been submitted."
End Sub
</script>
<style type="text/css">
body,td,th { font-family:Arial }
.head { font-size:110%; font-weight:bold }
.panel {
background-color: white;
border: solid 1px black;
height: 410px;
padding: 5px;
position: relative;
width: 650px;
z-index: 0;
}
.tabs {
border-collapse: collapse;
color: black;
cursor: pointer;
cursor: hand;
font-family: arial;
font-size: 9pt;
font-weight: bold;
margin-top: 4px;
padding: 2px 4px 0px 4px;
position: relative;
text-align: center;
text-decoration: none;
z-index: 1;
}
.tabsNotSelected {
background-color: wheat;
border: solid 1px black;
}
.tabsSelected {
background-color: white;
border-color: black black white black;
border-style: solid solid solid solid;
border-width: 1px 1px 1px 1px;
}
</style>
</head>
<body>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650">
<tr valign="top">
<td align="left">
<img src="\\server\share\img1.jpg">
</td>
<td align="center">
<span class="head">Tabs in HTA!</span>
</td>
<td align="right">
<img src="\\server\share\img2.jpg">
</td>
</tr>
<tr valign="top">
<td colspan="3">
<br><br><span id="span_tabspan"></span>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<br><span id="span_user"></span>
<br><br><input type="button" name="Submit" id="Submit" value="Submit" onclick="OnClickButtonSubmit">
</td>
</tr>
</table>
</body>
</html>
ASKER
Rob
I get this
-------------------------- -
-------------------------- -
Creating \\\de02\profer\Fa\Sha_DE06 .txt
-------------------------- -
OK
-------------------------- -
In each tab need to have atleast one checkbox selected and when submit a box to just ensure the data is selected right with yes or no. If no then the user can reselect any left out options
I get this
--------------------------
--------------------------
Creating \\\de02\profer\Fa\Sha_DE06
--------------------------
OK
--------------------------
In each tab need to have atleast one checkbox selected and when submit a box to just ensure the data is selected right with yes or no. If no then the user can reselect any left out options
ASKER
Sorry Rob Log writes fine
I had a extra slash
I cannot see the Computer and user name on the HTA can i have it shown on the HTA also
I had a extra slash
I cannot see the Computer and user name on the HTA can i have it shown on the HTA also
There are three slashes at the start of
\\\de02\profer\Fa\Sha_DE06 .txt
That would cause a problem. Check that
strLogFolder = "\\server\logs\"
is correct.
I will work on making sure at least one checkbox is selected in each tab...
Rob.
\\\de02\profer\Fa\Sha_DE06
That would cause a problem. Check that
strLogFolder = "\\server\logs\"
is correct.
I will work on making sure at least one checkbox is selected in each tab...
Rob.
When I open the HTA, I see the username and computername....
hta.jpg
hta.jpg
ASKER
Sorry Rob i was imagining the usual top view
Thanks
Can i get a combining code for the results
Thanks
Can i get a combining code for the results
ASKER
Hi Rob any vews with these..
Should be easy for you.. :-)
https://www.experts-exchange.com/questions/26268959/Script-to-add-1-user-to-all-Distribution-Security-groups-that-are-mailed-enabled-in-thre-Managed-tab.html
https://www.experts-exchange.com/questions/26305267/Script-to-open-2-ADUC's-of-2-different-Domains-with-a-specific-credentials.html
https://www.experts-exchange.com/questions/26295206/Script-To-check-All-The-Users-who-is-set-to-Change-The-Password-On-Next-Logon.html
Should be easy for you.. :-)
https://www.experts-exchange.com/questions/26268959/Script-to-add-1-user-to-all-Distribution-Security-groups-that-are-mailed-enabled-in-thre-Managed-tab.html
https://www.experts-exchange.com/questions/26305267/Script-to-open-2-ADUC's-of-2-different-Domains-with-a-specific-credentials.html
https://www.experts-exchange.com/questions/26295206/Script-To-check-All-The-Users-who-is-set-to-Change-The-Password-On-Next-Logon.html
Sharath, I have included a check to make sure that at least one checkbox is selected on each tab.
I will work on the code for combining the results.
Regards,
Rob.
I will work on the code for combining the results.
Regards,
Rob.
<html>
<head>
<title>Tabs.hta</title>
<HTA:Application
ID = "HTA"
ApplicationName = "Tabs"
Border = "thin"
BorderStyle = "normal"
Caption = "yes"
ContextMenu="yes"
Icon = ""
InnerBorder="no"
MaximizeButton = "yes"
MinimizeButton = "yes"
Navigable="yes"
Scroll="yes"
ScrollFlat="no"
Selection="yes"
ShowInTaskBar = "yes"
SingleInstance = "yes"
SysMenu = "yes"
Version = "1.0"
>
<script language="VBscript">
Dim sItem
Dim aPanels
Dim el
Dim iPanelCount
Dim sConfigFile
Dim objINI
Private Sub Window_OnLoad
Set objShell = CreateObject("WScript.Shell")
span_user.InnerHTML = "Username: " & objShell.ExpandEnvironmentStrings("%USERNAME%") & " " & "Computer name: " & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Set objINI = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
sConfigFile = "Config.ini"
Set objConfig = objFSO.OpenTextFile(sConfigFile, intForReading, False)
strHeading = ""
While Not objConfig.AtEndOfStream
strLine = objConfig.ReadLine
If strLine <> "" Then
If Left(strLine, 1) = "[" Then
strHeading = Mid(strLine, 2, Len(strLine) - 2)
Else
If objINI.Exists(strHeading) = True Then
objINI(strHeading) = objINI(strHeading) & "|" & strLine
Else
objINI.Add strHeading, strLine
End If
End If
End If
Wend
iPanelCount = objINI.Count
objConfig.Close
strHTMLCode = ""
i = 0
For Each strHeading In objINI
i = i + 1
If i = 1 Then
strHTMLCode = "<span class=""tabs tabsSelected"" id=""tab" & i & """ onclick=""panel(" & i & ")"">" & strHeading & "</span>"
Else
strHTMLCode = strHTMLCode & "<span class=""tabs tabsNotSelected"" id=""tab" & i & """ onclick=""panel(" & i & ")"">" & strHeading & "</span>"
End If
Next
i = 0
For Each strHeading In objINI
i = i + 1
strDefaultChecked = " CHECKED"
If i = 1 Then
strHTMLCode = strHTMLCode & "<div class=""panel"" id=""panel" & i & """ style=""display:block"">"
Else
strHTMLCode = strHTMLCode & "<div class=""panel"" id=""panel" & i & """ style=""display:none"">"
End If
strHTMLCode = strHTMLCode & "<hr color=""black"">"
strHTMLCode = strHTMLCode & "<table border=""0"" width=""100%"">"
strHTMLCode = strHTMLCode & "<tr valign=""top"">"
strHTMLCode = strHTMLCode & "<td>"
strHTMLCode = strHTMLCode & "<span id=""panelContents" & i & """ class=""head"">"
For Each strControl In Split(objINI(strHeading), "|")
strControlType = Left(strControl, InStr(strControl, ":") - 1)
strItem = Mid(strControl, InStr(strControl, ":") + 1)
'MsgBox "Creating chk_" & Replace(strItem, " ", "_") & " on panelContents" & i
If LCase(strControlType) = "checkbox" Then
strHTMLCode = strHTMLCode & "<br><input type=""checkbox"" id=""chk_" & Replace(strItem, " ", "_") & """ name=""chk_" & Replace(strItem, " ", "_") & """>" & strItem
ElseIf LCase(strControlType) = "radio" Then
strHTMLCode = strHTMLCode & "<br><input type=""radio"" id=""opt_" & Replace(strHeading, " ", "_") & """ name=""opt_" & Replace(strHeading, " ", "_") & """ value=""opt_" & Replace(strItem, " ", "_") & """" & strDefaultChecked & ">" & strItem
strDefaultChecked = ""
ElseIf LCase(strControlType) = "textarea" Then
strHTMLCode = strHTMLCode & "<br>" & strItem & "<br><textarea id=""txt_" & Replace(strItem, " ", "_") & """ name=""txt_" & Replace(strItem, " ", "_") & """ rows=""6"" cols=""75""></textarea>"
End If
Next
strHTMLCode = strHTMLCode & "</span>"
strHTMLCode = strHTMLCode & "<br><br>"
strHTMLCode = strHTMLCode & "TAB " & i
strHTMLCode = strHTMLCode & "</td>"
strHTMLCode = strHTMLCode & "</tr>"
strHTMLCode = strHTMLCode & "</table>"
strHTMLCode = strHTMLCode & "</div>"
Next
span_tabspan.InnerHTML = strHTMLCode
End Sub
Private Sub Panel(tab)
For i = 1 To iPanelCount
If i = tab Then
document.getElementById("tab" & i).className = "tabs tabsSelected"
document.getElementById("panel" & i).style.display = "block"
Else
document.getElementById("tab" & i).className = "tabs tabsNotSelected"
document.getElementById("panel" & i).style.display = "none"
End If
Next
End Sub
'Sub AddCheck
' strHTML = panelContents2.InnerHTML
' strHTML = strHTML & "<input id=" & intCheckCount & " type=" & Chr(34) & "CheckBox" & Chr(34) & _
' " name=" & Chr(34) & "chkEnabled" & Chr(34) & "value= " & Chr(34) & "CheckBox" & intCheckCount & Chr(34) & " onClick=" & Chr(34) & _
' "NewCheckSubroutine" & Chr(34) & ">" & " <BR>"
' panelContents2.InnerHTML = strHTML
'End Sub
Sub OnClickButtonSubmit()
'MsgBox document.getElementById("chk_Install_a").Checked
'Exit Sub
'This method will be called when button "Submit" is clicked
'Add your code here
Dim objFSO, objFile, objShell
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Change the file name and path on the next line'
strLogFolder = "\\server\logs\"
If Right(strLogFolder, 1) <> "\" Then strLogFolder = strLogFolder & "\"
'MsgBox "Creating " & strLogFolder & objShell.ExpandEnvironmentStrings("%USERNAME%") & "_" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & ".txt"
Set objFile = objFSO.OpenTextFile(strLogFolder & objShell.ExpandEnvironmentStrings("%USERNAME%") & "_" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & ".txt", 8, True)
objFile.WriteLine "Time: " & Now & VbCrLf & "Username: " & objShell.ExpandEnvironmentStrings("%USERNAME%") & VbCrLf & "Computer name:" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
For Each strHeading In objINI
objFile.WriteLine "[" & strHeading & "]"
boolHasCheckBox = False
boolHasOneChecked = False
For Each strControl In Split(objINI(strHeading), "|")
strControlType = Left(strControl, InStr(strControl, ":") - 1)
strItem = Mid(strControl, InStr(strControl, ":") + 1)
If LCase(strControlType) = "checkbox" Then
boolHasCheckBox = True
If document.getElementById("chk_" & Replace(strItem, " ", "_")).Checked = True Then boolHasOneChecked = True
objFile.WriteLine strItem & ": " & document.getElementById("chk_" & Replace(strItem, " ", "_")).Checked
ElseIf LCase(strControlType) = "radio" Then
If document.getElementById("opt_" & Replace(strHeading, " ", "_")).Value = "opt_" & Replace(strItem, " ", "_") Then
objFile.WriteLine strItem & ": Selected"
Else
objFile.WriteLine strItem & ": Not selected"
End If
ElseIf LCase(strControlType) = "textarea" Then
objFile.WriteLine strItem & ": " & document.getElementById("txt_" & Replace(strItem, " ", "_")).Value
End If
Next
If boolHasCheckBox = True And boolHasOneChecked = False Then
MsgBox "Please select at least one checkbox from the " & strHeading & " tab."
Exit Sub
End If
Next
objFile.WriteLine ""
objFile.Close
Set objShell = Nothing
Set objFile = Nothing
Set objFSO = Nothing
MsgBox "Thank you. Your information has been submitted."
window.close
End Sub
</script>
<style type="text/css">
body,td,th { font-family:Arial }
.head { font-size:110%; font-weight:bold }
.panel {
background-color: white;
border: solid 1px black;
height: 410px;
padding: 5px;
position: relative;
width: 650px;
z-index: 0;
}
.tabs {
border-collapse: collapse;
color: black;
cursor: pointer;
cursor: hand;
font-family: arial;
font-size: 9pt;
font-weight: bold;
margin-top: 4px;
padding: 2px 4px 0px 4px;
position: relative;
text-align: center;
text-decoration: none;
z-index: 1;
}
.tabsNotSelected {
background-color: wheat;
border: solid 1px black;
}
.tabsSelected {
background-color: white;
border-color: black black white black;
border-style: solid solid solid solid;
border-width: 1px 1px 1px 1px;
}
</style>
</head>
<body>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650">
<tr valign="top">
<td align="left">
<img src="\\server\share\img1.jpg">
</td>
<td align="center">
<span class="head">Tabs in HTA!</span>
</td>
<td align="right">
<img src="\\server\share\img2.jpg">
</td>
</tr>
<tr valign="top">
<td colspan="3">
<br><br><span id="span_tabspan"></span>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<br><span id="span_user"></span>
<br><br><input type="button" name="Submit" id="Submit" value="Submit" onclick="OnClickButtonSubmit">
</td>
</tr>
</table>
</body>
</html>
Sharath, a question: Do you want this HTA to append to the log file each time it is run, or just overwrite it? If it appends, I think it will make the report quite messy.....
Rob.
Rob.
To have it overwrite, change this:
Set objFile = objFSO.OpenTextFile(strLog Folder & objShell.ExpandEnvironment Strings("% USERNAME%" ) & "_" & objShell.ExpandEnvironment Strings("% COMPUTERNA ME%") & ".txt", 2, True)
to this
Set objFile = objFSO.CreateTextFile(strL ogFolder & objShell.ExpandEnvironment Strings("% USERNAME%" ) & "_" & objShell.ExpandEnvironment Strings("% COMPUTERNA ME%") & ".txt", True)
Regards,
Rob.
Set objFile = objFSO.OpenTextFile(strLog
to this
Set objFile = objFSO.CreateTextFile(strL
Regards,
Rob.
OK, and with the logs only being written to with one lot of results (by overwriting the file each time), this script will combine the results, if you point strFolder to the folder where the results are stored.
Regards,
Rob.
Regards,
Rob.
strFolder = "\\server\share\results"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objExcel = CreateObject("Excel.Application")
Const xlCalculationManual = -4135
Const xlCalculationAutomatic = -4105
Const xlUp = -4162
Const xlToLeft = -4159
objExcel.Visible = True
objExcel.EnableEvents = False
objExcel.ScreenUpdating = False
'objExcel.Calculation = xlCalculationManual
Set objMaster = objExcel.Workbooks.Add
For Each objFile In objFSO.GetFolder(strFolder).Files
intLastRow = objMaster.Sheets(1).Cells(65536, "A").End(xlUp).Row
If intLastRow = 1 And objMaster.Sheets(1).Cells(1, "A").Value = "" Then
boolWriteHeader = True
Else
boolWriteHeader = False
End If
If LCase(Right(objFile.Name, 4)) = ".txt" Then
Set objText = objFSO.OpenTextFile(objFile.Path, intForReading, False)
While Not objText.AtEndOfStream
strLine = objText.ReadLine
If strLine <> "" Then
If InStr(strLine, ":") > 0 Then
strHeading = Left(strLine, InStr(strLine, ":") - 1)
strValue = Mid(strLine, InStr(strLine, ":") + 2)
If boolWriteHeader = True Then
intLastCol = objMaster.Sheets(1).Cells(1, 256).End(xlToLeft).Column
If objMaster.Sheets(1).Cells(1, intLastCol).Value <> "" Then intLastCol = intLastCol + 1
objMaster.Sheets(1).Cells(intLastRow, intLastCol).Value = strHeading
End If
intFoundCol = FindColumnWithHeading(strHeading)
If intFoundCol > 0 Then
objMaster.Sheets(1).Cells(intLastRow + 1, intFoundCol).Value = strValue
If IsDate(strValue) = True Then objMaster.Sheets(1).Cells(intLastRow + 1, intFoundCol).NumberFormat = "d/mm/yyyy h:mm:ss AM/PM"
End If
ElseIf boolWriteHeader = True Then
intLastCol = objMaster.Sheets(1).Cells(1, 256).End(xlToLeft).Column
If objMaster.Sheets(1).Cells(1, intLastCol).Value <> "" Then intLastCol = intLastCol + 1
objMaster.Sheets(1).Cells(intLastRow, intLastCol).Value = strLine
End If
End If
Wend
objText.Close
Set objText = Nothing
If boolWriteHeader = True Then boolWriteHeader = False
End If
Next
objMaster.Sheets(1).Rows("1:1").Font.Bold = True
objExcel.EnableEvents = True
objExcel.ScreenUpdating = True
'objExcel.Calculation = xlCalculationAutomatic
MsgBox "Combining is complete."
Function FindColumnWithHeading(strTitle)
intCol = 0
For intColNum = 1 To objMaster.Sheets(1).Cells(1, 256).End(xlToLeft).Column
If objMaster.Sheets(1).Cells(1, intColNum).Value = strTitle Then
intCol = intColNum
Exit For
End If
Next
FindColumnWithHeading = intCol
End Function
ASKER
Thanks Rob
1. I will need to clear full log file of the user and update again into it if opened by user again,
2. if i have 3 tabs the check box is checked only for 2
3. how can i increase the size of the hta
4. above each check box i want to describe about the tab can i get the place to update in the ini file.
1. I will need to clear full log file of the user and update again into it if opened by user again,
2. if i have 3 tabs the check box is checked only for 2
3. how can i increase the size of the hta
4. above each check box i want to describe about the tab can i get the place to update in the ini file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot Rob...This is a useful one... :-)
Any help on this
https://www.experts-exchange.com/questions/26306163/Script-that-records-softwares-need-a-change.html
Any help on this
https://www.experts-exchange.com/questions/26306163/Script-that-records-softwares-need-a-change.html
ASKER
Hi Rob any help with this please...
https://www.experts-exchange.com/questions/26306163/Script-that-records-softwares-need-a-change.html
https://www.experts-exchange.com/questions/26306163/Script-that-records-softwares-need-a-change.html
what user selection?