You should really use HTML DOM (Document Object Model) to dynamically create tables. There are alot of ways to do things in scripting, but this is how typically dynamically generate a table. If you search the forum for keywords like .InsertCell(), I've posted alot of different examples. Here is something to get you start though:
<!DOCTYPE HTML PUBLIC "-//W3C//Dth HTML 4.0 Transitional//EN">
<html>
<head>
<META http-equiv=Content-Type content="text/html; CHARSET=iso-8859-1">
<title>Dynamic Table</title>
<style type="text/css">
body {
font-family:Verdana;
font-size: 8px;
color: #49403B;
background: #FFFFFF;
text-align: center;
}
table.Results, th.Results, td.Results {
border-width: thin;
border-color: black;
border-style: groove;
border-collapse: collapse;
font-size: 9px;
}
th.Results {
font-size:10px;
font-weight:bold;
background-color:goldenrod;
color:#FFFFFF;
text-align:center;
padding: 5px;
margin-top:0px;
}
</style>
<script language="vbscript" type="text/vbscript">
Call Center_HTA(600, 600)
Sub Window_Onload()
Generate_Table()
End Sub
Sub Center_HTA( widthX, heightY )
self.ResizeTo widthX, heightY
self.MoveTo (screen.Width - widthX)/2, (screen.Height - heightY)/2
End Sub
Sub Generate_Table
Set objWMI = GetObject("WinMGMTS://./Root/CIMv2")
arrAttributes = Array("Name", "DisplayName", "ProcessID", "Status")
Set colItems = objWMI.ExecQuery("Select " & Join(arrAttributes, ",") & " From Win32_Service")
'Create a table in the document
Set objTable = document.createElement("TABLE")
'Create a table header
Set objTHead = objTable.createTHead()
'Insert a row into the table header
Set objRow = objTHead.InsertRow()
'Loop through the attributes in the array
For Each strAttrib In arrAttributes
'Add a TH cell
Set objTH = document.createElement("TH")
'Add text to the cell
objTH.InnerText = strAttrib
'Apply the .Results style class to the cell
objTH.className = "Results"
'Append the new TH to the TR
objRow.appendChild(objTH)
Next
'Create a table body
Set objTBody = document.createElement("TBODY")
'Apply the .Results style class to the cell
objTable.className = "Results"
'Append the body to the table created
objTable.appendChild(objTBody)
'Append the shell table into the DIV
div_Main.appendChild(objTable)
'Loop through WMI and set each cell with the appropriate property
For Each objItem In colItems
'Insert a row into the table body
Set objRow = objTBody.InsertRow(-1)
'Add a cell for Name
Set objCell = objRow.InsertCell(-1)
'Add text to the cell with the WMI Property
objCell.InnerText = objItem.Name
'Apply the .Results style class to the cell
objCell.className = "Results"
'Add a cell for DisplayName
Set objCell = objRow.InsertCell(-1)
'Add text to the cell with the WMI Property
objCell.InnerText = objItem.DisplayName
'Apply the .Results style class to the cell
objCell.className = "Results"
'Add a cell for ProcessID
Set objCell = objRow.InsertCell(-1)
'Add text to the cell with the WMI Property
objCell.InnerText = objItem.ProcessId
'Apply the .Results style class to the cell
objCell.className = "Results"
'Add a cell for Status
Set objCell = objRow.InsertCell()
'Add text to the cell with the WMI Property
objCell.InnerText = objItem.Status
'Apply the .Results style class to the cell
objCell.className = "Results"
Next
End Sub
</script>
<hta:application
applicationname="Dynamic Table"
border="dialog"
borderstyle="normal"
caption="yes"
contextmenu="no"
icon="no.ico"
maximizebutton="yes"
minimizebutton="yes"
navigable="no"
scroll="yes"
selection="no"
showintaskbar="yes"
singleinstance="yes"
sysmenu="no"
version="1.0"
windowstate="normal"
>
</head>
<body>
<div id="div_Main"></div>
</body>
</html>