We help IT Professionals succeed at work.

HTA Code thats Awesome. For Quiz or user comments on a project. Need a way to update a log file when user submits.

bsharath
bsharath asked
on
Hi,

HTA Code thats Awesome. For Quiz or user comments on a project. Need a way to update a log file when user submits.
I need the below code to be changes with a Submit button when clicked it has to update a UNC log file.
Automaticall capture the username & machine name.

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
</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> &nbsp; &nbsp;
    <br>
  </td>
</tr>
<tr valign="top">
  <td colspan="2">
  	<span id="span_tabspan"></span>
  </td>
</tr>
</table>
</body>
</html>

Open in new window

Comment
Watch Question

Top Expert 2010

Commented:
Hi, Sharath.

I'd like to see what the code does, but it reads a file named config.ini that's not present.  Can you share a copy of that file?

Author

Commented:
Config.ini file for example will have this data

[Maths]
Install a
Install b
Install c

[Science]
Install a
Install b
Install c
Top Expert 2010
Commented:
This version adds a submit button.  When clicked the code writes a log entry into a file.  The log entry contains the date/time of the entry, the username of the person who clicked the button, and the computer the entry came from.  You'll have to edit the code and change the file name/path of the log file.
<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> &nbsp; &nbsp;
    <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>

Open in new window

Author

Commented:
Thanks David
i will want the tabs that were selected by the user into the log.
Say 10 users open the Hta in one shot and submit will the log file Write. If there will be an issue can we create 1 file for each user in the UNC. Wih Machinename_Username.txt
Top Expert 2010

Commented:
Sharath,

Please be specific with what you want when you write a question.  There's no mention in this question that you want the boxes that were checked.  All the question says is that you want to capture the user and machine names when a user submits.  It wastes time when we have to go back and add something in.  

How do you want the selections written out and how do you want them labeled?

Author

Commented:
Sorry David,
But my intension here to record the log was to find what the user has selected.
If user selected just one tab 2 checkboxes then the log should look as this other than whats being recorded now.
Science > Install A,Install B

I have a few more additions thats needed. but though of putting related posts rather than putting all into one.
Sorr again for the trouble