Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting data input from user within a script

Status
Not open for further replies.

umaandsusan

Technical User
Nov 17, 2003
3
CA
We want to receive input from the user during the execution of a script.

How do we do this ?

 
The simplest way is with view()

Code:
var
	monthyear	 	String
endVar

monthyear = "MM/YY"

;get month/year and add a desciptive window title
monthyear.view( "Enter Month/Year (MM/YY)" )

;now see that the variable is whatever they changed it to
view(monthyear)

But, it's not very elegant and would need some error trapping and possibly data formatting.

I personally use a small dialog form and formReturn().


Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
umaandsusan,

While Mac is technically correct in that the view() method is the easiest, it's not terribly flexible. For example, there's no way to know if the user clicked the OK button or the Cancel button from the resulting dialog.

The way it's supposed to work is:

1. Create a blank form that looks like a dialog box.

2. Place a field object on the form that let's the user enther the value(s) you need. Be sure to give this object a name that makes sense, e.g. fldInput.

3. Place an OK button on your dialog form that has the following in its pushButton() event:

Code:
   formReturn( TRUE )

4. Place a Cancel button on the dialog form that adds the following to its pushButton() event:

Code:
   formReturn( FALSE )

5. Save your dialog form and give it a name you'll remember. In this example, we'll assume it's called MYDIALOG.FSL.

6. Add code to your script that loads the form, waits for the user to deal with it, and then responds appropriately. For example:


Code:
var
   fmDialog  Form
   strValue  String
endVar


   if not fmDialog.open( "MyDialog" ) then
      errorStop( "Can't Open Dialog",
                 "Use [>>] for more details..." )
   else
   
      fmDialog.fldInput = &quot;<A Default Value&quot;>

      if fmDialog.wait() = TRUE then
         strValue = fmDialog.fldInput.Value
         doSomething()
      else
         Message( &quot;Cancelled, as requested...&quot; )
      endIf
      
      try
         fmDialog.close()
      onFail
         ; do nothing it's already closed
      endTry
      
   endIf

Nowq, I know this feels like a lot of work, but there are a number of things that can go wrong and this provides a good starting place for handling those--and other--issues.

Hope this helps...

-- Lance

P.S. While this is a good starting place, it's not what Paul Harvey might call &quot;the rest of the story.&quot; For best results, you'll want to make certain your dialog form only uses one of two exits. See for details.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top