Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Looping problem overwriting my last data output

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,61490
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Looping problem overwriting my last data output
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Looping problem overwriting my last data output - 6/17/2008 4:00:04 AM   
  boomer

 

Posts: 28
Score: 0
Joined: 6/17/2008
Status: offline
I am having a looping problem with my hta script. When I try to output each computer's Operating System data, it overwrites the last computer's data.  I can not figure out how to create a new "DataArea" <span> table for each computer (computer1, computer2, computer3).  Any help would be appreciated.


<head>
<title>HTA Test</title>
<HTA:APPLICATION
    APPLICATIONNAME="HTA Test"
    SCROLL="yes"
    SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
Sub GetOSVersion
strMachines = "computer1, computer2, computer3"
aMachines = split(strMachines, ";")

For Each machine in aMachines
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & machine & "\root\cimv2")
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOSes
strHTML = "<table border='1' style='border-collapse: collapse' bordercolor='SaddleBrown' id='Table1' >"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='10%'>" & "<b>Computer Name: </b>" & objOS.CSName & "</td>"
strHTML = strHTML & "<td width='10%'>" & "<b>Operating System: </b>" & objOS.Caption 'Name & "</td>"
strHTML = strHTML & "<td width='10%'>" & "<b>Version: </b>" & objOS.Version 'Version & build & "</td>"
strHTML = strHTML & "<td width='10%'>" & "<b>Service Pack: </b>" & objOS.ServicePackMajorVersion & "." & objOS.ServicePackMinorVersion & "</td>"
strHTML = strHTML & "</tr>"
strHTML = strHTML & "</table>"
DataArea.InnerHTML = strHTML
Next
Next
End Sub
</script>
<body>
<input type="button" value="Operating System" onClick="GetOSVersion">
<p>
<span id = "DataArea"></span> <br>
</body>
 
 
Post #: 1
 
 RE: Looping problem overwriting my last data output - 6/17/2008 4:11:59 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
try moving this:

DataArea.InnerHTML = strHTML

out of the loop.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to boomer)
 
 
Post #: 2
 
 RE: Looping problem overwriting my last data output - 6/17/2008 4:19:19 AM   
  boomer

 

Posts: 28
Score: 0
Joined: 6/17/2008
Status: offline
Thanks ebgreen for the reply.  I placed DataArea.InnerHTML = strHTML outside the second 'Next' and I get the same results.  The LAST computer's data overwrites the previous computer's data.  It only outputs the last computer's data in the (strMachines = "computer1, computer2, computer3")  I.E. computer 3 is all that is displayed.


(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Looping problem overwriting my last data output - 6/17/2008 4:34:31 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
strMachines = "computer1, computer2, computer3"
aMachines = split(strMachines, ";")


Do you see the problem?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to boomer)
 
 
Post #: 4
 
 RE: Looping problem overwriting my last data output - 6/17/2008 4:39:39 AM   
  boomer

 

Posts: 28
Score: 0
Joined: 6/17/2008
Status: offline
My bad, my original script had ";" vs. ","  .  I changed it to different computer names for confidentiality and thus added a "," instead of ";" when I posted it on this forum.  My original script I am working with has ";" and fails to work properly  --  it overwrites the previous computer's data.  Please ignore the "," and instead treat it as ":".  Thank you for pointing this out, though!

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Looping problem overwriting my last data output - 6/17/2008 4:41:32 AM   
  boomer

 

Posts: 28
Score: 0
Joined: 6/17/2008
Status: offline
Here is the correction from my typo.  Still having problems overwriting the prior's computer's data.

<head>
<title>HTA Test</title>
<HTA:APPLICATION
   APPLICATIONNAME="HTA Test"
   SCROLL="yes"
   SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
Sub GetOSVersion
strMachines = "computer1; computer2; computer3"
aMachines = split(strMachines, ";")

For Each machine in aMachines
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & machine & "\root\cimv2")
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOSes
strHTML = "<table border='1' style='border-collapse: collapse' bordercolor='SaddleBrown' id='Table1' >"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='10%'>" & "<b>Computer Name: </b>" & objOS.CSName & "</td>"
strHTML = strHTML & "<td width='10%'>" & "<b>Operating System: </b>" & objOS.Caption 'Name & "</td>"
strHTML = strHTML & "<td width='10%'>" & "<b>Version: </b>" & objOS.Version 'Version & build & "</td>"
strHTML = strHTML & "<td width='10%'>" & "<b>Service Pack: </b>" & objOS.ServicePackMajorVersion & "." & objOS.ServicePackMinorVersion & "</td>"
strHTML = strHTML & "</tr>"
strHTML = strHTML & "</table>"
DataArea.InnerHTML = strHTML
Next
Next
End Sub
</script>
<body>
<input type="button" value="Operating System" onClick="GetOSVersion">
<p>
<span id = "DataArea"></span> <br>
</body>

(in reply to boomer)
 
 
Post #: 6
 
 RE: Looping problem overwriting my last data output - 6/17/2008 4:44:21 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Ok, so in the code that you just posted, you still have  DataArea.InnerHTML = strHTML inside the loop.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to boomer)
 
 
Post #: 7
 
 RE: Looping problem overwriting my last data output - 6/17/2008 4:48:58 AM   
  boomer

 

Posts: 28
Score: 0
Joined: 6/17/2008
Status: offline
I get the same results if the "DataArea.InnerHTML = strHTML" is inside or outside the loop.  I just ran it again as you suggested with the below script.

<head>
<title>HTA Test</title>
<HTA:APPLICATION
  APPLICATIONNAME="HTA Test"
  SCROLL="yes"
  SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
Sub GetOSVersion
strMachines = "computer1; computer2; computer3"
aMachines = split(strMachines, ";")

For Each machine in aMachines
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & machine & "\root\cimv2")
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOSes
strHTML = "<table border='1' style='border-collapse: collapse' bordercolor='SaddleBrown' id='Table1' >"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='10%'>" & "<b>Computer Name: </b>" & objOS.CSName & "</td>"
strHTML = strHTML & "<td width='10%'>" & "<b>Operating System: </b>" & objOS.Caption 'Name & "</td>"
strHTML = strHTML & "<td width='10%'>" & "<b>Version: </b>" & objOS.Version 'Version & build & "</td>"
strHTML = strHTML & "<td width='10%'>" & "<b>Service Pack: </b>" & objOS.ServicePackMajorVersion & "." & objOS.ServicePackMinorVersion & "</td>"
strHTML = strHTML & "</tr>"
strHTML = strHTML & "</table>"
Next
Next
DataArea.InnerHTML = strHTML

End Sub
</script>
<body>
<input type="button" value="Operating System" onClick="GetOSVersion">
<p>
<span id = "DataArea"></span> <br>
</body>

(in reply to ebgreen)
 
 
Post #: 8
 
 RE: Looping problem overwriting my last data output - 6/17/2008 4:51:25 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Well you still have a problem with your delimiter. Your string is delimited with "; " but you are splitting on ";".

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to boomer)
 
 
Post #: 9
 
 RE: Looping problem overwriting my last data output - 6/17/2008 5:01:58 AM   
  boomer

 

Posts: 28
Score: 0
Joined: 6/17/2008
Status: offline
Not sure what you mean.  The script seems to work fine but overwrites in the <span id = "DataArea"></span>.  I am trying to create a separate table row for each computer (computer1;computer2;computer3) rather then overwriting the table row with the NEXT computer. 

To give you an example of my problem, when the script runs it writes a table row for computer3.  If I change or reverse the order to (computer3;computer2;computer1) it will write a table row for ONLY computer1.  In other words, the only data that is shown in the dataArea output is the last computer in the split (strMachine, ";") command.

(in reply to ebgreen)
 
 
Post #: 10
 
 RE: Looping problem overwriting my last data output - 6/17/2008 5:13:29 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
<head>
<title>HTA Test</title>
<HTA:APPLICATION
  APPLICATIONNAME="HTA Test"
  SCROLL="yes"
  SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
Sub GetOSVersion
strMachines = "computer1; computer2; computer3"
aMachines = split(strMachines, ";")

For Each machine in aMachines
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & machine & "\root\cimv2")
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOSes
strHTML = strHTML & "<table border='1' style='border-collapse: collapse' bordercolor='SaddleBrown' id='Table1' >"
strHTML = strHTML & "<tr>"
strHTML = strHTML & "<td width='10%'>" & "<b>Computer Name: </b>" & objOS.CSName & "</td>"
strHTML = strHTML & "<td width='10%'>" & "<b>Operating System: </b>" & objOS.Caption 'Name & "</td>"
strHTML = strHTML & "<td width='10%'>" & "<b>Version: </b>" & objOS.Version 'Version & build & "</td>"
strHTML = strHTML & "<td width='10%'>" & "<b>Service Pack: </b>" & objOS.ServicePackMajorVersion & "." & objOS.ServicePackMinorVersion & "</td>"
strHTML = strHTML & "</tr>"
strHTML = strHTML & "</table>"
Next
Next
DataArea.InnerHTML = strHTML

End Sub
</script>
<body>
<input type="button" value="Operating System" onClick="GetOSVersion">
<p>
<span id = "DataArea"></span> <br>
</body>

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to boomer)
 
 
Post #: 11
 
 RE: Looping problem overwriting my last data output - 6/17/2008 5:18:55 AM   
  boomer

 

Posts: 28
Score: 0
Joined: 6/17/2008
Status: offline
ebgreen - That fixed it. Your awesome! Thank you again for all your help!  Great website and forum by the way.

(in reply to ebgreen)
 
 
Post #: 12
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Looping problem overwriting my last data output Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts