VBScript supports an InputBox function within the language. Thus it is simple to query an user input in this language:
InputBox (prompt, title, default, xpos, ypos)
The following source code demonstrate how to use this function within a script.
'************************************************ ' File: Input.vbs (WSH sample in VBScript) ' Author: (c) G. Born ' ' This script demonstrates how to get an user input in VBscript. ' The sample may be localized by setting language either to 0 or 1. ' ' In no way shall the author be liable for any ' losses or damages resulting from the use of this ' program. Use AS-IS at your own risk. ' ' The code is the property of the author. You may ' use the code and modify it, as far as this header ' remains intact. Further updates and other samples ' may be found on my site: ' http://www.borncity.de '************************************************ Dim WSHShell ' declare the object variable Dim Message Dim Title '*** Here we may localize the strings *** language= 0 ' 0 = English, 1 = German ' Here we initialize the variables for user interaction If language = 0 Then ' *** English *** Message = "Please enter something" Title = "WSH-sample User Input - by G. Born" Text1 = "Sorry, user input was canceled" Text2 = "I got the input:" & vbCRLF Else ' *** German *** Message = "Eingabe" Title = "WSH-Beispiel Benutzereingabe - by G. Born" Text1 = "Benutzereingabe abgebrochen" Text2 = "Ihre Eingabe war:" & vbCRLF End If ' *** now we are ready to jump into the details ;-) ' 1st we must create the WSHShell object to interact ' with the user (show dialog and so on) Set WSHShell = WScript.CreateObject("WScript.Shell") ' We are ready to use the InputBox-function ' InputBox (prompt, title, default, xpos, ypos) ' prompt: the text shown in the input box ' title: the title shown in the input box ' default: the value shown as default in the input field ' xpos/xpos: upper left corner of the input box ' if some values are omitted, WSH uses default values result = InputBox(Message,Title,"Born", 100, 100) If result = "" Then WScript.Echo Text1 Else WScript.Echo Text2 & result End If '*** |
Well, that's all. Additional information about this sample and the way how to create a GUI for WSH scripts (including real forms - yes, it is possible) may be found in my WSH books, published by Microsoft Press.