All Forums >> [Scripting] >> WSH & Client Side VBScript >> Help. Output data to a multi-column textbox Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Does anyone have a script that outputs data to a textarea (multi-column textbox)? I am trying to create a .hta script that outputs a constant ping to a textbox. Thank you in advanced.
Hi ehvbs, thank you for the reply. Is it possible to use your example inconjunction with a document.write command? Here is part of the script I would like to display in a textbox.
For Each machine in aMachines Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._ ExecQuery("select * from Win32_PingStatus where address = '"_ & machine & "'") For Each objStatus in objPing If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then document.write("<font color=black>" & Machine & " </font><font color=#FF0000> .......is unreachable </font><BR>") Else document.write("<font color=black>" & Machine & " </font><font color=#00FF00>.......is up </font><BR>") End If Next Next
while it is possible to document.write the <textarea> and its value, in my opinion it's a fatal design error to have document.write in a .HTA (ok, all you .HTA fans - I'm waiting for your counter arguments).
Dim taDisplay : Set taDisplay = document.GetElementById( "taDisplay" ) ... If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then taDisplay.Value = machine & " is unreachable." & vbCrLf & taDisplay.Value ...
ehvbs, It worked the first time! Thanks. Now I am curious, what does "document.GetElementById" actually do? Tried to google it but could not find the definition.
Ok, I ran into another snag - still new at vbscript. How can I make this script do continous loop. I am trying to create a script that will do a continous ping and output the results every 5 seconds.
Here are my questions:
1. What is the .hta equivalent to vbscript wscript.sleep() 2. Can you use the "DO" and "LOOP" command inside a "IF,THEN,ELSE"? 3. Do I need to make a LOOP outside of the " For Each objStatus in objPing" line?
Here is part of the code I am working on; how can I make this output the ping results every 5 seconds:
Sub Server1 Dim taDisplay Machine = "Server1" Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._ ExecQuery("select * from Win32_PingStatus where address = '"_ & machine & "'") For Each objStatus in objPing Set taDisplay = document.GetElementById( "taDisplay" ) Do If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then taDisplay.Value = machine & " is unreachable." & vbCrLf & taDisplay.Value Else taDisplay.Value = machine & " is up." & vbCrLf & taDisplay.Value
End If Loop Next End Sub
< Message edited by boomer -- 6/19/2008 12:53:37 AM >
your ping-action in Sub Server1 is a selfcontained task (including the output to the textarea. So the best way to do it many times (every 5 secs) is to use this Sub with SetInterval (and ClearInterval). But you should consult a good book or tutorial about DHTML before you write your first line of code.
If you are seriously interested in .HTA programming, you should organize your learning/programming in a systematic way. I don't claim that this way is the only one or the best, but it works for me:
(1) Start with a simple template:
This gives you a very simple .hta with the most important sections in the simplest version:
- an Application object
- a meta section specifying encoding and script language
- a style section (here you can start to trash your font tags)
- a code section (with all the ugly formalisms done)
- a html body you can fill out later
The reload button/sub allows you to keep the code in your editor, save it after changes, and reload/refresh the currently running .hta.
Add the HTML element you need to do the ping job:
If you do fc on the template and the first step on ping.hta, you'll see the changes/additions:
Title & Name (trivial); application globals to store HTML elements for further/frequent use and variables to keep track of important/relevant states of the program/application; two subs to start and stop the ping task (no real action yet, but they show how to avoid starting/stopping twice/in the wrong order); initializing (of the globals) in OnLoadBody (after the elements are ready); the minimal set of elements for the ping task: two buttons and a textarea to talk to the user.
Test it to see if I messed it up: Can you start ping twice or stop it when it is not running? Play with the CSS (make the meta button yellow), ...
Next Step: Using SetInterval with a Fake Ping sub:
Not so much new code:
It's just a new sub and the using of Set/ClearInterval. Testing should show that after starting the (fake) ping, the sub is called every 2 secs, and that you can start and stop the action correctly.
Last step: Replace FakePink with RealPing:
Give this approach a chance, try it with two or three (simple) projects - and blame me here, if it doesn't work for you. [Seriously: if it doesn't work for you, I hope you'll give some feedback here, so that I (we?) can improve the procedure].
Thanks for the tips on the books -- With that said, I have only been working vbscript and HTA for only 2 months now. I am beginner only trying to get my feet wet, so to speak - to see if I want to continue in learning more advanced techniques. So far I like it and plan on investing more time and money learning the tricks and trades as you have -- but for now it is nice to know I have people on the web who can help me and ease my beginner's pain. We all have to start somewhere. I don't want to waste a lot of money on books or school only to find out I don't want to continue. But then again, I don't want to waste your time on beginner's trivial questions. I am very grateful for all you help and time. Thanks again for posting the script templates!!
I just tried the last one. Really like how the scripts gives the time stamp. Still trying to understand how it all works, especially how you got the ping to stop. Thanks again for the scripts. I'll check back once I do more research on your awesome scripts.
(1) you don't need to be apologetic about just starting with VBScript
(2) my posting wasn't about tricks, but about the basics
(3) there are public libraries & the Internet (money isn't an argument for not reading)
(4) 'just tried the last one' was the worst possible approach - if you'd started with the first and worked thru up to the last and had looked up SetInterval and ClearInterval, you wouldn't have to to ask about stopping the ping.
The scolding done, I must add that
(1) 'getting the work done' is important too
(2) not being dounted by problems and unrelentingly working on their solution is a laudable trait of character too
(3) sometimes it's difficult to force Google or a book to spit out the relevant info; so asking for help is peerfectly legitimate
So keep up your good work (but try to lay some sustainable foundation)