Previous Topic

Next Topic

Book Contents

Book Index

Script Capturing User Input

This example shows you how to edit a script using Script Editor, and create a prompt for user input. As well as automatically inserting text in Narrative lines, we want to prompt the user to key in additional text to include in the narrative line. We will re-use the script we created previously. Load the script named InvoicePropertyStatement.pfs created in Script to Add Narrative Lines to an Invoice.

  1. Change the first instance of Form1.Line.Description = .... to

    frmINInvoice1.Line.Description =  "Consignment Note No.: " &

  2. With the cursor at the end of the line, from the drop down menus, select Functions > Input > InputBox.
    Result: The following code displays: 

    InputBox(, , ,)

    This shows that the InputBox function has 4 possible arguments, separated by the 3 commas in brackets. See Online Help > MaxBasic functions > InputBox for more information about the arguments you need to enter for the InputBox function. You can access this from the drop down menus, select Functions > Input > InputBox > Help Inputbox

  3. Enter the Prompt "Enter Consignment Note Number" before the first comma.
  4. Enter the Title "Consignment No." before the second comma.
  5. Delete the next commas and any additional spaces. The line will read:

    frmINInvoice1.Line.Description = "Consignment Note No.: " & InputBox("Enter Consignment Note Number", "Consignment No.")

  6. Delete any remaining original code after this line.
    Result: Your code should now look like this,

    Dim frmINInvoice1 as Object
    frmINInvoice1 = GetActiveObject
    If IsNull(frmINInvoice1) or frmINInvoice1.ClassName <> "INInvoiceEntryForm" then Error "Wrong form class for script"
    frmINInvoice1.Edit
    frmINInvoice1.Line.Append
    frmINInvoice1.Line.LineType = "Narrative"
    frmINInvoice1.Line.Description = "Consignment Note No: " & InputBox("Enter Consignment Note Number","Consignment No.")

  7. Save the script with the name ConsignmentNumber.pfs.
  8. Run the script. Key in a number when prompted. Have a look at the result. We'll look at validating user input in a later example.