VBScript front-end to a console app. 
Author Message
 VBScript front-end to a console app.

I'm writing a VBScript front-end to a console app. How do I pass input into
a program called from  vbscript?

Set WSHShell= WScript.CreateObject ("WScript.Shell")
WSHShell.Run "%comspec%/ c program.exe", 0, True

The program (program.exe) prompts for input through standard io:

Program.exe>> Enter the name of the file to encode/decode

    I need to turn this into an input box

Programs.exe>> Press esc to encode, return to decode

    I need to turn this into a message box with two buttons encode and
decode
    How do I pass an esc char to the program through vbscript?



Sat, 29 Mar 2003 03:00:00 GMT  
 VBScript front-end to a console app.

Quote:

> I'm writing a VBScript front-end to a console app. How do I pass input into
> a program called from  vbscript?

> Set WSHShell= WScript.CreateObject ("WScript.Shell")
> WSHShell.Run "%comspec%/ c program.exe", 0, True

> The program (program.exe) prompts for input through standard io:

> Program.exe>> Enter the name of the file to encode/decode

>     I need to turn this into an input box

> Programs.exe>> Press esc to encode, return to decode

>     I need to turn this into a message box with two buttons encode and
> decode
>     How do I pass an esc char to the program through vbscript?

I am assuming we are talking about a stand alone WSH hosed script.  If
so, request the info from the user BEFORE you issue the Run.  You can
use the InputBox to request the name of the file to be processed:

  sFilename = InputBox("File to be encoded/decoded")

For the second piece of input you have several choices:

1.  Use the InputBox function again, or

2.  Use a MsgBox with one of the Three button option constants to
provide two buttons and a cancel, again before issuing the Run.  This is
an imperfect, but easy approach, since it will require explanation text
to have the buttons stand in for Encode/Decode.  They cannot be
renamed.  So, it would look something like this, say using the
vbYesNoCancel constant ...

  title = "Make a selection"
  prompt = "Press Yes to Encode or No to Decode"
  buttons = vbYesNoCancel
  Result = MsgBox(prompt, buttons, title)
  Select Case Result
  Case vbYes
    Result = Chr(27) ' The escape character
  Case vbNo
    Result = Chr(13) ' The Carrage return character
  Case vbCancel
    Wscript.Quit
  End Select

3.  Or, the whole input process can be done in a 'console' with the
correctly labeled buttons and a file lookup feature using Michael
Harris' fine scripting component, Msg.wsc.  This is the 'best looking'
solution, if you have IE 4 or 5 loaded on the machine(s). But, it does
require a good deal of programming.  More than I want to attempt in
answer to this question.  If you want to pursue it, the component is
available for free download at Clarence Washington's site:

    http://cwashington.netreach.net/main_site/default.asp

Then, with the user input, you need to create a temporary input file for
use with your program.  For example, ...

  Set oFS = CreateObject("Scripting.FileSystemObject")
  Set oInF = oFS.OpenTextFile("C:\~tmp.txt", 2, True)
  oInF.WriteLine sFilename
  oInF.Write Result
  oInf.Close

Finally, Run the program with its input, supplied via redirection ...

  Set WSHShell= WScript.CreateObject ("WScript.Shell")
  WSHShell.Run "%comspec%/ c program.exe < C:\~tmp.txt", 0, True
  oInf.Delete

The last line deletes the temporary input file.

This needs to be cleaned up, and maybe configured to accept Drag and
Drop delivery of the file to the procedure through WSH's Arguments
property, but this gives you an idea of how to start.

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/



Sat, 29 Mar 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. App Security - front-end or back-end?

2. running console app in same console

3. Newbie question: improve VB front-end app response time

4. VB as front end for other apps

5. Launching programs from a front end app.

6. VB3 - Building App Front Ends

7. VB Front-End for 3270 Apps

8. VB FRONT-END FOR 3270 APPS

9. Help! problems with launching a front-end app

10. Exporting Access records to MS Word via VB6 front end app

11. Help! problems with launching a front-end app

12. Creating an app with a WORD front end?

 

 
Powered by phpBB® Forum Software