Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Newbie Script question

166 views
Skip to first unread message

Paul Lehmann

unread,
Nov 6, 2002, 7:29:33 AM11/6/02
to
I would like to write some simple programs that do not need to be compiled
and are portable on all windows machines. They can be purely text based
but the capability of a simple GUI would be nice. Does VB Script fill this
need? If so, can anyone recommend a tutoral or beginning book(s )on the
subject. I have some Visual Basic experience but I do not want to create
programs with a big overhead.

Evertjan.

unread,
Nov 6, 2002, 7:31:20 AM11/6/02
to
Paul Lehmann wrote on 06 Nov 2002 in
microsoft.public.scripting.vbscript:
> portable on all windows machines.
> Does VB Script fill this need?

No, use Javascript. vbscript only runs on MSIE.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Torgeir Bakken (MVP)

unread,
Nov 6, 2002, 7:31:04 AM11/6/02
to
Paul Lehmann wrote:

Hi

What are you going to actually do in your script/program?

How "advanced" GUI do you need?

--
torgeir
Microsoft MVP Scripting and WMI
Porsgrunn Norway


Torgeir Bakken (MVP)

unread,
Nov 6, 2002, 8:34:59 AM11/6/02
to
"Evertjan." wrote:

> Paul Lehmann wrote on 06 Nov 2002 in
> microsoft.public.scripting.vbscript:
> > portable on all windows machines.
> > Does VB Script fill this need?
>
> No, use Javascript. vbscript only runs on MSIE.

I'm not so sure that the OP wants to run his scripts/programs from a browser.

Evertjan.

unread,
Nov 6, 2002, 9:00:15 AM11/6/02
to
Torgeir Bakken (MVP) wrote on 06 Nov 2002 in
microsoft.public.scripting.vbscript:
> I'm not so sure that the OP wants to run his scripts/programs from a
> browser.

Yes, could be.

Paul Lehmann

unread,
Nov 6, 2002, 10:52:07 AM11/6/02
to
Torgeir Bakken (MVP) wrote:

> "Evertjan." wrote:
>
>> Paul Lehmann wrote on 06 Nov 2002 in
>> microsoft.public.scripting.vbscript:
>> > portable on all windows machines.
>> > Does VB Script fill this need?
>>
>> No, use Javascript. vbscript only runs on MSIE.
>
> I'm not so sure that the OP wants to run his scripts/programs from a
> browser.

I would like to be able to run outside a browser

Torgeir Bakken (MVP)

unread,
Nov 6, 2002, 10:04:27 AM11/6/02
to
Paul Lehmann wrote:

Hi

If you answered my two questions and gave some more details, it would be easier
for people to give you an answer I think.

Paul Lehmann

unread,
Nov 6, 2002, 2:47:12 PM11/6/02
to
Torgeir Bakken (MVP) wrote:

What were your two questions?

Need:
To run a text script that does not require a browser, interpretor or
compiler that does not normally come with Windows operating system. This
seems to rule out things like TCL/TK which does not come on every window
machine.

A text based program is sufficient but it would be nice if I could create a
GUI with input boxes, check boxes etc.

Does VB Script fulfill these requirements? In other words, can I create a
text file with the proper extension and mail it to anyone with a windows
operating system and have it work?

What more do you need to answer my question?

Torgeir Bakken (MVP)

unread,
Nov 6, 2002, 5:41:12 PM11/6/02
to
Paul Lehmann wrote:

> Torgeir Bakken (MVP) wrote:
> > If you answered my two questions and gave some more details, it would be
> > easier for people to give you an answer I think.
>

> What were your two questions?
>
> Need:
> To run a text script that does not require a browser, interpretor or
> compiler that does not normally come with Windows operating system. This
> seems to rule out things like TCL/TK which does not come on every window
> machine.

Well, then WSH (VBScript/JScript) is your best bet. You want VBScript/JScript
5.1 (WSH 2.0) or better. This comes default with WinME, Win2k and WinXP. For
Win9x and NT 4.0, it will be available if Internet Explorer 5.01 or better is
installed. WSH is also available as a standalone download from MS.


> A text based program is sufficient but it would be nice if I could create a
> GUI with input boxes, check boxes etc.

WSH has a "primitive" inputbox, but no check boxes etc. If you have IE 5.0+, you
can use the Internet.Explorer object from your VBScript to get a GUI. See the
demo script by Joe Earnest attached further down (Joe, now your script will be
available at the Google newsgroup archive :-).


> Does VB Script fulfill these requirements? In other words, can I create a
> text file with the proper extension and mail it to anyone with a windows
> operating system and have it work?

With VBScript 5.1, the text file creation is easy. The mailing part is much more
difficult to answer, it depends on your OS and what you have installed on the
computer. There is nothing here that will work on all computers with an out of
the box setup.

' DialogDemo.vbs
'
' NOTE: Requires VBS 5.0+ and IE 5.0+
' The dialog demo code is in the "zDemoDlg" function.
' Variable prefixes are personal and irregular; change as needed.
'
' By Joe Earnest
' Based on examples posted on the microsoft.public.scripting
' .vbscript and .wsh newsgroups by Tom Lavedas, Torgeir Bakken,
' Michael Harris and Alex Angelopoulos. The refresh key/context
' menu suppression script is based on code posted by Thor Larholm
' on the .jscript newsgroup.
'

Option Explicit

Dim oIEApp
Dim umBox, urSln, uxSln
Set oIEApp= CreateObject("InternetExplorer.Application")

uxSln= zDemoDlg(500, 500, "Dialog Demo")

Select Case uxSln(0)
Case 0: umBox= "Dialog exit by [x] or [Alt]+[F4]."
Case Else: umBox= "Normal dialog exit by button #" & uxSln(0) & "."
End Select

umBox= umBox & " " & vbCr & vbCr _
& "Checkbox #1 " & Left("un", Abs(NOT uxSln(1)) *2) & "checked. " _
& vbCr _
& "Checkbox #2 " & Left("un", Abs(NOT uxSln(2)) *2) & "checked. " _
& vbCr _
& "Checkbox #3 " & Left("un", Abs(NOT uxSln(3)) *2) & "checked. " _
& vbCr & vbCr _
& "Radiobutton #"

For urSln= 4 To 6
If uxSln(urSln) Then umBox= umBox & (urSln -3): Exit For
Next

umBox= umBox & " selected. " & vbCr & vbCr _
& "Text Input = " & vbTab & uxSln(7) & " " & vbCr _
& "File Input = " & vbTab & uxSln(8) & " " & vbCr _
& "Password Input = " & vbTab & uxSln(9) & " " & vbCr & vbCr _
& "Option Selection = " & vbTab & "Option #" & uxSln(10) & " " & vbCr

MsgBox umBox, vbOkOnly +vbInformation +vbSystemModal, _
" Demo Dialog Return"

WScript.Quit

' <===== Dialog Demo Function

Function zDemoDlg (vnWid, vnHt, vtBar)

Dim vxSln, vyErr

' NOTE: With AutoItX, you can check for window existence
' at the outset and exit to avoid duplication.

oIEApp.Navigate("about:blank")
Do
WScript.Sleep 50
Loop Until oIEApp.ReadyState=4

With oIEApp
.FullScreen= False
.Toolbar = False
.StatusBar = False
.AddressBar = False
.Resizable= False

With .Document
With .ParentWindow
.ResizeTo vnWid, vnHt
.MoveTo (.Screen.AvailWidth - vnWid) /2, _
(.Screen.AvailHeight - vnHt) /2
End With

' NOTE: Multiple WriteLn statements are used for demo purposes.
' The DHTML code can be concatenated for a single Write/WriteLn entry.

.WriteLn ("<html>")
.WriteLn ("<head>")

' If concatenating VBScript, concatenate vbCr's
' or vbCrLf's after each line.
' This script is placed in the head by convention;
' it can be placed in the body.

.WriteLn ("<script language=""vbscript"">")

' NOTE: The following code uses a hidden value to avoid
' external pushbutton subs.
' GetRef references to external subs in the script may
' also be used for pushbuttons.
' A hidden value provides better [x] or [Alt]+[F4] error trapping for
' a dialog with pushbuttons only, where no other controls are being polled.
' While this routine parses an exit button id in a specific manner, the
' entire exit buttion id could be placed the value, a string value could be
' polled, and the button id could be parsed later for specific operation.

.WriteLn ("Sub ExitButton ()")
.WriteLn ("ExitButtonID= LCase(Trim(window.event.srcelement.id))")
.WriteLn ("If Left(ExitButtonID, 4)=""xbtn"" Then")
.WriteLn ("window.exitbtn.value= Mid(ExitButtonID, 5)")
.WriteLn ("End If")
.WriteLn ("End Sub")

' NOTE: The following code traps refresh and context
' menu keys to avoid dialog corruption by refreshing.

.WriteLn ("Sub NoRefreshKey ()")
.WriteLn ("Select Case window.event.keycode")
.WriteLn ("Case 82: SuppressKey= window.event.ctrlkey")
.WriteLn ("Case 116: SuppressKey= True")
.WriteLn ("End Select")
.WriteLn ("If SuppressKey Then")
.WriteLn ("window.event.keycode= 0")
.WriteLn ("window.event.cancelbubble= True")
.WriteLn ("window.event.returnvalue= False")
.WriteLn ("End If")
.WriteLn ("End Sub")
.WriteLn ("Sub NoContextMenu ()")
.WriteLn ("window.event.cancelbubble= True")
.WriteLn ("window.event.returnvalue= False")
.WriteLn ("End Sub")

' NOTE: The following code implements the above subroutines.

.WriteLn ("Set document.onclick= GetRef(""ExitButton"")")
.WriteLn ("Set document.onkeydown= GetRef(""NoRefreshKey"")")
.WriteLn ("Set document.oncontextmenu= GetRef(""NoContextMenu"")")

.WriteLn ("</script>")
.WriteLn ("</head>")
.WriteLn ("<body>")
.WriteLn ("<center>")
.WriteLn ("<font size=+4><b>Dialog&nbsp;&nbsp;Demo</b></font>")
.WriteLn ("<hr width=55%>")
.WriteLn ("<i>Demonstration of InternetExplorer.Application" _
& " DHTML Dialog</i>")
.WriteLn ("<hr width=90%>")
.WriteLn ("<table style=""font:10pt Arial"">")
.WriteLn ("<tr>")
.WriteLn ("<td align=left>")
.WriteLn ("&nbsp;&nbsp;<input type=checkbox id=chk1" _
& " accesskey=""C"">")
.WriteLn ("&nbsp;&nbsp;<b><u>C</u>heckbox #1</b>")
.WriteLn ("</td>")
.WriteLn ("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp" _
& ";&nbsp;&nbsp;&nbsp;&nbsp;</td>")
.WriteLn ("<td align=left>")
.WriteLn ("<input type=radio id=rad1 name=radgrp0 checked" _
& " accesskey=""R"">")
.WriteLn ("&nbsp;&nbsp;<b><u>R</u>adiobutton #1</b>")
.WriteLn ("</td>")
.WriteLn ("</tr>")
.WriteLn ("<tr>")
.WriteLn ("<td align=left>")
.WriteLn ("&nbsp;&nbsp;<input type=checkbox id=chk2 checked" _
& " accesskey=""H"">")
.WriteLn ("&nbsp;&nbsp;<b>C<u>h</u>eckbox #2</b>")
.WriteLn ("</td>")
.WriteLn ("<td></td>")
.WriteLn ("<td align=left>")
.WriteLn ("<input type=radio id=rad2 name=radgrp0" _
& " accesskey=""A"">")
.WriteLn ("&nbsp;&nbsp;<b>R<u>a</u>diobutton #2</b>")
.WriteLn ("</td>")
.WriteLn ("</tr>")
.WriteLn ("<tr>")
.WriteLn ("<td align=left>")
.WriteLn ("&nbsp;&nbsp;<input type=checkbox id=chk3" _
& " accesskey=""E"">")
.WriteLn ("&nbsp;&nbsp;<b>Ch<u>e</u>ckbox #3<b>")
.WriteLn ("</td>")
.WriteLn ("<td></td>")
.WriteLn ("<td align=left>")
.WriteLn ("<input type=radio id=rad3 name=radgrp0" _
& " accesskey=""B"">")
.WriteLn ("&nbsp;&nbsp;<b>Radio<u>b</u>utton #3<b>")
.WriteLn ("</td>")
.WriteLn ("</tr>")
.WriteLn ("<tr><td><br></td><td></td><td></td></tr>")
.WriteLn ("<tr>")
.WriteLn ("<td align=center colspan=3>")
.WriteLn ("<b><u>T</u>ext:</b>&nbsp;&nbsp;")
.WriteLn ("<input type=text id=inp1 size=43" _
& " style=background-color:LightYellow" _
& " value=""default text"" accesskey=""T"">")
.WriteLn ("</td>")
.WriteLn ("</tr>")
.WriteLn ("<tr>")
.WriteLn ("<td align=left colspan=3>")
.WriteLn ("<b><u>F</u>ile:</b>&nbsp;&nbsp;&nbsp;")
.WriteLn ("<input type=file id=inp2 size=29" _
& " style=background-color:WhiteSmoke" _
& " accesskey=""F"">")
.WriteLn ("</td>")
.WriteLn ("</tr>")
.WriteLn ("<tr><td><br></td><td></td><td></td></tr>")
.WriteLn ("<tr>")
.WriteLn ("<td align=center colspan=3>")
.WriteLn ("<font color=DarkRed><b><u>P</u>" _
& "assword:</b></font>&nbsp;&nbsp;")
.WriteLn ("<input type=password id=inp3 size=9" _
& " maxlength=8 style=background-color:Pink;" _
& " value=""mycode"" accesskey=""P"">")
.WriteLn ("</td>")
.WriteLn ("</tr>")
.WriteLn ("<tr>")
.WriteLn ("<td align=center colspan=3>")
.WriteLn ("<b><u>D</u>rop Box:</b>&nbsp;&nbsp;")
.WriteLn ("<select id=opt1 size=1 accesskey=""D"">")
.WriteLn ("<option selected value=""1"">Option #1")
.WriteLn ("<option value=""2"">Option #2")
.WriteLn ("<option value=""3"">Option #3")
.WriteLn ("<option value=""4"">Option #4")
.WriteLn ("</select>")
.WriteLn ("</td>")
.WriteLn ("</tr>")
.WriteLn ("</table>")
.WriteLn ("<br><hr width=90%>")
.WriteLn ("<button id=xbtn1 style=background-color:White" _
& " accesskey=""1""><font color=Red><b>Exit" _
& " <u>1</u></b></font></button>&nbsp;&nbsp;&nbsp;&nbsp;")
.WriteLn ("<button id=xbtn2 style=background-color:Red" _
& " accesskey=""2""><font color=White><i><b>Exit" _
& " <u>2</u></b></i></font></button>" _
& "&nbsp;&nbsp;&nbsp;&nbsp;")
.WriteLn ("<button id=xbtn3 style=background-color:#6FEFD4" _
& " accesskey=""3""><b>Exit" _
& " <u>3</u></b></button>&nbsp;&nbsp;&nbsp;&nbsp;")
.WriteLn ("<button id=xbtn4 style=background-color:DarkBlue" _
& " accesskey=""4""><font color=LightYellow>" _
& "<i><b>Exit <u>4</u></b></i></font></button>" _
& "&nbsp;&nbsp;&nbsp;&nbsp;")
.WriteLn ("<button id=xbtn5 accesskey=""5""><b>Exit" _
& " <u>5</u></b></button>")

' NOTE: The following code implements hidden value pushbutton polling.
' It is not needed if using external subs.

.WriteLn ("<input type=hidden id=exitbtn value=""0"">")

.WriteLn ("</center>")
.WriteLn ("</body>")
.WriteLn ("</html>")

' NOTE: Background colors, font text colors and styles can be
' set in the DHTML body text, instead of set globally here.

With .ParentWindow.Document.Body
.Style.BackgroundColor= "#6FEFD4"
.Scroll="no"
.Style.Font= "10 pt 'Arial'"
.Style.BorderStyle= "outset"
End With

.Title= vtBar

' NOTE: If using external subs for pushbuttons,
' use code here similar to the following:
' .All.xbtn1.OnClick= GetRef("subBtn1")
' .All.xbtn2.OnClick= GetRef("subBtn2")
' .All.xbtn3.OnClick= GetRef("subBtn3")
' .All.xbtn4.OnClick= GetRef("subBtn4")

.All.xbtn5.Focus
End With

.Visible= True
End With

WScript.Sleep 100

' NOTE: I strongly prefer AutoItX to the following code line for activation.
' With AutoItX, you can also retitle the dialog here, to get rid
' of the " - Microsoft Internet Explorer" appendage to the bar title.
' With AutoItX, you can also time window existence and provide
' a timeout error exit.

CreateObject("WScript.Shell").AppActivate vtBar

Do
WScript.Sleep 50

' NOTE: An error occurs while polling the controls, if
' the window has been dismissed with [x] or [Alt]+[F4].

On Error Resume Next
With oIEApp.Document
vxSln= Array(CInt(.All.exitbtn.Value), _
CBool(.All.chk1.Checked), CBool(.All.chk2.Checked), _
CBool(.All.chk3.Checked), CBool(.All.rad1.Checked), _
CBool(.All.rad2.Checked), CBool(.All.rad3.Checked), _
CStr(.All.inp1.Value), CStr(.All.inp2.Value), _
CStr(.All.inp3.Value), CInt(.All.opt1.Value))
End With
vyErr= CBool(Err)
On Error GoTo 0
If vyErr Then zDemoDlg= vxSln: Exit Function
Loop Until vxSln(0)

oIEApp.Visible= False

zDemoDlg= vxSln

End Function

0 new messages