Include Sample. Dialog Field Length Limiting

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Include Sample. Dialog Field Length Limiting

Post by JRL » Thu Apr 03, 2008 3:41 am

With Macro Scheduler version 9.0 and above, it's possible to write scripts in a manner such that they can be included in a separate script. Following is a sample "include" script that will easily allow you to limit the number of characters in a non-modal dialog edit or memo field.

It works like this. Call the included script at the beginning of the main script using the include function.

Include>ScriptName.scp

This line imports the included script into the main script. The main script will have a non-modal dialog with edit and/or memo objects. In a loop in the non-modal dialog main script, place a line that calls the subroutine from the included script.

In this case the subroutine call needs three parameters.
-- First the number of characters to which text in the object will be limited.
-- Second is the name of the main script's dialog.
-- Third is the name of the edit or memo object.
Call the subroutine and add the three parameters for each object that needs field length control.

Here is the script that will be the included script. to work with the sample main script, the main script and the included script need to be located in the same folder and the name of the included script needs to be "FieldLengthLimit.scp"

Code: Select all

SRT>FieldLimit
  Let>value=%FieldLimit_var_2%.%FieldLimit_var_3%
  StringReplace>value,%CR%,,value
  Length>%value%,elen
  Separate>value,%LF%,var
  If>var_count>1
    If>var_%var_count%=
	  Sub>var_count,2
	Else
	  Sub>var_count,1
	EndIf
	Let>FieldLimit_var_1={%FieldLimit_var_1%+(%var_count%*1)}
  EndIf
  If>elen>%FieldLimit_var_1%
    MidStr>%value%,1,%FieldLimit_var_1%,value
    Let>%FieldLimit_var_2%.%FieldLimit_var_3%=%value%
    LibFunc>user32,SetFocus,SetRes,0
    ResetDialogAction>%FieldLimit_var_2%
  EndIf
END>FieldLimit
Here is a script sample that uses the FieldLengthLimit script.

Code: Select all

//Place this Include> line at the top of any script
//that you want to have any dialog field length limited.
//The unremarked line will work if the script is run outside
//the advanced editor.  If the script is to be run inside the
//editor, remark the second line and unremark the first.
//Include>FieldLengthLimit.scp
Include>%script_dir%\FieldLengthLimit.scp

Dialog>Dialog1
   Caption=Field Length Limiting
   Width=193
   Height=239
   Top=CENTER
   Left=CENTER
   Max=0
   Min=0
   Resize=0
   Edit=msEdit1,32,40,121,
   Memo=msMemo1,32,72,121,65,
   Button=Ok,56,168,75,25,3
   Default=Ok
EndDialog>Dialog1

Show>dialog1

Label>Loop
  GetDialogAction>dialog1,res1
  If>res1=2,EOF
  If>res1=3,Process
  //Dialog field length limit usage:
  //Gosub>FieldLimit,Character Limit,Dialog Name,Object Name
  //Place one GoSub>FieldLimit line for each object that needs a length limit
  GoSub>FieldLimit,4,dialog1,msedit1
  GoSub>FieldLimit,8,dialog1,msMemo1
Goto>Loop

SRT>Process
  MDL>%dialog1.msedit1%%CRLF%%dialog1.msMemo1%
  ResetDialogAction>dialog1
  Press End
END>Process

Label>EOF

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts