Avatar of Rebel_no_1
Rebel_no_1
Flag for China

asked on 

How can I display a specific value from an array inside a <div element. Clear and safe sample demonstration script below.

Currently I have a text file (HWStatus.txt) that contains 14 sets (lines) of 4 values separated with a comma on each line. There will always be 14 lines/sets-of-values. These 4 values provide the status and details of hardware components that needs to be monitored by a continuuously looping .HTA (HTML Application). (A sepearate dos .bat script maintains and updates this .txt file in real-time).

The 4 values per line can be described as follows:
1) Device number for the HW component. Example: "HW01"
2) Corresponding background color of the status box associated with this HW component. Example: "#00e600"
3) Description/Friendly Name of hardware item. Example: "BACKUP DEVICE"
4) Text string (HWID) used by a small application to retrieve the status of the HW component. Example:"VID_1A40"

Rules for the values:
Value 1 will always be populated from HW01 - HW14 as in the attached example.
Value 2 will always be populated if there is a corresponding device to be monitored. It will be blank if there is no device.
Value 3 will be populated with a friendly device name if a Name needs to be displayed for the corresponding device.
Value 4 will be populated with the device ID of the corresponding device to be monitored. It will be blank if there is no device.

Explanation of the attached example:
Device 01 does not have a friendly name and is therefore not displayed.
Device 02 - 12 contains all values and is displayed accordingly
Device 13, 14 does not contain any values and is therefore not displayed at all.

Currently the HTA monitors the color value in each line. It loops every 1second and this works perfectly.
My question is this:
Can the HTA also retrieve the corresponding Device Name (Value 3) from the HWStatus.txt file?
Can the HTA handle blank values in the Friendly name

What I am trying to achieve:
I would effectively like to only configure the HWStatus.txt file to determine the functionality of the .HTA. I regularly add or remove devices and this is a tedious process if I have to edit the .HTA. The .HTA must therefore be able to handle a minimum of 1 device and a max of 14 devices without any change or modification.

This is the HWSTatus.txt:
HW01,#00e600,,VID_1A40
HW02,#00e600,BACKUP DEVICE,WPDBUSENUMROOT
HW03,#00e600,SIGNATURE PAD,VID_2133
HW04,#00e600,CHARGE CONTROLLER,VID_0403
HW05,#ff0000,3G MODEM & GPS,VID_12D1
HW06,#00e600,USB EXTENSION CABLE,VID_1A40
HW07,#ff0000,BARCODE READER,VID_27DD
HW08,#00e600,DOCUMENT SCANNER,VID_1B17
HW09,#ff0000,EXTERNAL KEYBOARD,VID_1997
HW10,#ff0000,FACE CAPTURE CAMERA,VID_1E4E
HW11,#00e600,EVOLIS PRINTER,USBPRINT\EVOLIS_ZENIUS
HW12,#00e600,FINGERPRINT READER,VID_17B9
HW13,,,
HW14,,,

Open in new window


This is the sample.HTA file:
<!DOCTYPE html>
<html>
<head>

<title>Platform</title>
	<meta http-equiv="x-ua-compatible" content="IE=8">
	<meta http-equiv="Content-Script-Type" content="text/vbscript">
	<meta name=VI60_defaultClientScript content=javascript/>

<HTA:APPLICATION
     ID="objScreen" 
     APPLICATIONNAME="EE-Dev" 
     BORDERSTYLE="dialog" 
/> 

<Script Language="VBScript"> 
   Sub Window_OnLoad
	' Refresh data from HWstatus file
	CheckHWStatusFile
	' Set up a timer event so we can update the screen periodically
	iTimerID = window.setInterval("myVBSClock", 1000)
   End Sub

   Sub myVBSClock
	' Update current time
	myClock.innerText = Now()

	' Refresh colors from HWstatus file
	CheckHWStatusFile

   End Sub


   Sub CheckHWStatusFile
	' Constants for file I/O
	Const ForReading = 1
	Const ForWriting = 2
	Const TriStateUseDefault = -2

	' Name of HWstatus file
	strHWStatusFile = "HWStatus.txt"

	' Create file system object
	Set objFSO = CreateObject("Scripting.FileSystemObject")

	' Make sure HWstatus file exists
	If objFSO.FileExists(strHWStatusFile) Then
	   ' Open it for reading
	   Set objHWStatusFile = objFSO.OpenTextFile(strHWStatusFile, ForReading, False, TriStateUseDefault)
	   ' Read HWstatus file, split lines into array elements
	   arrHWStatus = Split(objHWStatusFile.ReadAll, vbCrLf)
	   ' Close file, release objects
	   objHWStatusFile.Close
	   Set objHWStatusFile = Nothing
	   Set objFSO = Nothing

	   ' Process each line of the HWstatus file (skip blank lines)
	   For Each strHWStatus in arrHWStatus
		If strHWStatus <> "" Then
		   ' Split HWstatus line into array at comma
		   arrField = Split(strHWStatus, ",")
		   ' Process lines based on first field on line (item name to update), and set item color to HWstatus file value
		   Select Case arrField(0)
			Case "HW01"
			   HW01.style.background = arrField(1)
			Case "HW02"
			   HW02.style.background = arrField(1)
			Case "HW03"
			   HW03.style.background = arrField(1)
			Case "HW04"
			   HW04.style.background = arrField(1)
			Case "HW05"
			   HW05.style.background = arrField(1)
			Case "HW06"
			   HW06.style.background = arrField(1)
			Case "HW07"
			   HW07.style.background = arrField(1)
			Case "HW08"
			   HW08.style.background = arrField(1)
			Case "HW09"
			   HW09.style.background = arrField(1)
			Case "HW10"
			   HW10.style.background = arrField(1)
			Case "HW11"
			   HW11.style.background = arrField(1)
			Case "HW12"
			   HW12.style.background = arrField(1)
		   End Select
		End If
	   Next 
	End If
   End Sub
</SCRIPT>

</head>




<BODY TOPMARGIN="0px" RIGHTMARGIN="0px" LEFTMARGIN="0px">


<SPAN
   id="HW01"
   style="
	cursor: default;
	top: 42%;
	left: 2%;
	width: 1.8%;
	height: 35.5%;
	position: fixed;
	z-index: 4;
	visibility: show;
	border-style: solid;
	border-width: 1px;
	border-color: #6d6d6d;
	background: #5d5d5d;">
<div style="padding-left: 30px; color: #515151;font-family: Arial;font-size: 20px;">	
</div>
</SPAN>

<SPAN
   id="HW02"
   style="
	cursor: default;
	top: 42%;
	left: 5%;
	width: 1.8%;
	height: 3.2%;
	position: fixed;
	z-index: 4;
	visibility: show;
	border-style: solid;
	border-width: 1px;
	border-color: #6d6d6d;
	background: #5d5d5d;">
<div style="padding-left: 30px; color: #515151;font-family: Arial;font-size: 20px;">	
BACKUP&nbspDEVICE
</div>
</SPAN>

<SPAN
   id="HW03"
   style="
	cursor: default;
	top: 46%;
	left: 5%;
	width: 1.8%;
	height: 3.2%;
	position: fixed;
	z-index: 4;
	visibility: show;
	border-style: solid;
	border-width: 1px;
	border-color: #6d6d6d;
	background: #5d5d5d;">
<div style="padding-left: 30px; color: #515151;font-family: Arial;font-size: 20px;">	
SIGNATURE&nbspPAD
</div>
</SPAN>

<SPAN
   id="HW04"
   style="
	cursor: default;
	top: 50%;
	left: 5%;
	width: 1.8%;
	height: 3.2%;
	position: fixed;
	z-index: 4;
	visibility: show;
	border-style: solid;
	border-width: 1px;
	border-color: #6d6d6d;
	background: #5d5d5d;">
<div style="padding-left: 30px; color: #515151;font-family: Arial;font-size: 20px;">	
CHARGE&nbspCONTROLLER
</div>
</SPAN>

<SPAN
   id="HW05"
   style="
	cursor: default;
	top: 54%;
	left: 5%;
	width: 1.8%;
	height: 3.2%;
	position: fixed;
	z-index: 4;
	visibility: show;
	border-style: solid;
	border-width: 1px;
	border-color: #6d6d6d;
	background: #5d5d5d;">
<div style="padding-left: 30px; color: #515151;font-family: Arial;font-size: 20px;">	
3G&nbspMODEM&nbsp&&nbspGPS
</div>
</SPAN>

<SPAN
   id="HW06"
   style="
	cursor: default;
	top: 58%;
	left: 5%;
	width: 1.8%;
	height: 3.2%;
	position: fixed;
	z-index: 4;
	visibility: show;
	border-style: solid;
	border-width: 1px;
	border-color: #6d6d6d;
	background: #5d5d5d;">
<div style="padding-left: 30px; color: #515151;font-family: Arial;font-size: 20px;">	
USB&nbspEXTENSION&nbspCABLE
</div>
</SPAN>

<SPAN
   id="HW07"
   style="
	cursor: default;
	top: 62%;
	left: 5%;
	width: 1.8%;
	height: 3.2%;
	position: fixed;
	z-index: 4;
	visibility: show;
	border-style: solid;
	border-width: 1px;
	border-color: #6d6d6d;
	background: #5d5d5d;">
<div style="padding-left: 30px; color: #515151;font-family: Arial;font-size: 20px;">	
BARCODE&nbspREADER
</div>
</SPAN>

<SPAN
   id="HW08"
   style="
	cursor: default;
	top: 66%;
	left: 5%;
	width: 1.8%;
	height: 3.2%;
	position: fixed;
	z-index: 4;
	visibility: show;
	border-style: solid;
	border-width: 1px;
	border-color: #6d6d6d;
	background: #5d5d5d;">
<div style="padding-left: 30px; color: #515151;font-family: Arial;font-size: 20px;">	
DOCUMENT&nbspSCANNER
</div>
</SPAN>

<SPAN
   id="HW09"
   style="
	cursor: default;
	top: 70%;
	left: 5%;
	width: 1.8%;
	height: 3.2%;
	position: fixed;
	z-index: 4;
	visibility: show;
	border-style: solid;
	border-width: 1px;
	border-color: #6d6d6d;
	background: #5d5d5d;">
<div style="padding-left: 30px; color: #515151;font-family: Arial;font-size: 20px;">	
EXTERNAL&nbspKEYBOARD
</div>
</SPAN>

<SPAN
   id="HW10"
   style="
	cursor: default;
	top: 74%;
	left: 5%;
	width: 1.8%;
	height: 3.2%;
	position: fixed;
	z-index: 4;
	visibility: show;
	border-style: solid;
	border-width: 1px;
	border-color: #6d6d6d;
	background: #5d5d5d;">
<div style="padding-left: 30px; color: #515151;font-family: Arial;font-size: 20px;">	
FACE&nbspCAPTURE&nbspCAMERA
</div>
</SPAN>

<SPAN
   id="HW11"
   style="
	cursor: default;
	top: 78%;
	left: 5%;
	width: 1.8%;
	height: 3.2%;
	position: fixed;
	z-index: 4;
	visibility: show;
	border-style: solid;
	border-width: 1px;
	border-color: #6d6d6d;
	background: #5d5d5d;">
<div style="padding-left: 30px; color: #515151;font-family: Arial;font-size: 20px;">	
EVOLIS&nbspPRINTER
</div>
</SPAN>

<SPAN
   id="HW12"
   style="
	cursor: default;
	top: 82%;
	left: 5%;
	width: 1.8%;
	height: 3.2%;
	position: fixed;
	z-index: 4;
	visibility: show;
	border-style: solid;
	border-width: 1px;
	border-color: #6d6d6d;
	background: #5d5d5d;">
<div style="padding-left: 30px; color: #515151;font-family: Arial;font-size: 20px;">	
FINGERPRINT&nbspREADER
</div>
</SPAN>

<SPAN
	STYLE="
	cursor:default; 
	bottom: -1%;
	right: 1.5%;
	position: fixed;
	z-index: 4;
	text-align: right;
	color: #515151;
	font-family: Arial;
	font-size: 15px;
	font-weight: bold;
	visibility: show;">
	<PRE ID=myClock>
	</PRE>

</SPAN>


</BODY>
</HTML>

							

					  

Open in new window



To run the code just create the HWStatus.txt and EESample.hta files in the same directory with the provided content and run the .HTA.
VB ScriptHTMLScripting LanguagesProgramming Languages-OtherJavaScript

Avatar of undefined
Last Comment
RobSampson

8/22/2022 - Mon