home *** CD-ROM | disk | FTP | other *** search
Wrap
SCRIPT "Add scrollbars automatically" BEHAVIOR "Placed in a field or recordfield, lets the field automatically adjust its scrollbars" CATEGORY Text { --You must send the custom message from somewhere, e.g. at the enterPage event to handle showOrHideScrollbar if my textOverflow > 0 or my scroll > 0 set my borderStyle to scrolling else set my borderStyle to rectangle end if end showOrHideScrollbar } ACTION "Show Command window" BEHAVIOR "This one line script brings up the Command window without using the Command menu item or the Shift + F3 key." CATEGORY Debug { show commandWindow } ACTION "Beep" BEHAVIOR "Beeps the computer once." CATEGORY Utilities { beep 1 } SCRIPT "Check for characters" BEHAVIOR "This function checks each character to ensure that it is within the bounds of (A-Z) and (a-z)." CATEGORIES Data { to get isStringAlpha testString alphabet = "abcdefghijklmnopqrstuvwxyz" step i from 1 to charcount(testString) if char i of testString is not in alphabet return FALSE end if end step return TRUE end isStringAlpha } SCRIPT "Find the offset of an item" BEHAVIOR "A fast way to find the offset of an item in a list." CATEGORIES Utilities { to get itemOffset itm,lst step i from 1 to itemcount(lst) pop lst if itm = it return i end if end step return 0 end itemOffset } SCRIPT "Check a list for an item" BEHAVIOR "This function checks to see if an item is in a list." CATEGORIES Utilities { to get itemInList xitem,xlist while itemcount(xlist) > 0 and item 1 of xlist <> xitem pop xlist end while if item 1 of xlist = xitem return true else return false end if end itemInList } ACTION "Select a line of text" BEHAVIOR "In a single or multi-select list box, select a line of text." CATEGORIES Text ARG fieldName is "textField" help "Set this to the name of the field." ARG fieldLine is "3" help "Set this to the line you want selected." { set focus to field "$$fieldName" set selectedTextLines of field "$$fieldName" to $$fieldLine } ACTION "Deselect a line of text" BEHAVIOR "Deselects text in a single or multi-select list box." CATEGORIES Text ARG fieldName is "textField" help "Set this to the name of the field." { if selectedTextLines of field "$$fieldName" <> null set selectedTextLines of field "$$fieldName" to null end if } ACTION "Put selected text into Command window" BEHAVIOR "Puts the currently selected text into the command window" CATEGORIES Text { -- a good place for this script is in a -- buttonDoubleClick in the field itself get selectedText put it } ACTION "Request the selected text" BEHAVIOR "Puts the text of the selected textlines in a list box into a request box" CATEGORIES Text ARG fieldName is "textField" help "Set this to the name of the field." { local temp1,temp2 set temp2 to null get selectedTextLines of field $$fieldName put it into temp1 step i from 1 to itemCount (temp1) put textLine (item i of temp1) of text of field $$fieldName & CRLF\ after temp2 end step request temp2 } ACTION "Clear the selected text" BEHAVIOR "In a list box, clears the selected text. Place this script in a list box" CATEGORIES Text { if selectedTextState <> NULL set startChar to item 1 of selectedTextState set endChar to item 2 of selectedTextSTate clear chars startChar to endChar + 2 of text of self end if } SCRIPT "Allow normal tabs in a field" BEHAVIOR "Allows the user to use the tab normally in a field, rather than having the tab move the user to another object." CATEGORIES Text { --put this handler in a page or background to handle keyDown key,isShift,isCtrl if key is keytab and isShift is FALSE and isCtrl is FALSE send keydown keytab, FALSE, TRUE else forward end if end keyDown } SCRIPT "Remove a character from a string" BEHAVIOR "This function removes all instances of the specified character from the specified string." CATEGORIES Data { -- removes all instances of chr from strng to get stripChar chr,strng set chrLoc to offset(chr,strng) while chrLoc > 0 clear char chrLoc of strng set chrLoc to offset(chr,strng) end while return strng end stripChar } SCRIPT "Remove trailing spaces from a string" BEHAVIOR "This function removes all trailing spaces, as well as other undesirable characters." CATEGORIES Data { -- removes trailing spaces, tabs, and crlf's to get trim strng local charsToDrop set charsToDrop to space & crlf & tab while charcount(strng) > 0 and last char of strng is in charsToDrop clear last char of strng end while return strng end trim } SCRIPT "Get the day from the date" BEHAVIOR "Returns the weekday of any day beyond 1/1/1700. Requires the function isLeapYear() ('Determine if a Leap Year')." CATEGORIES Dates { -- returns the weekday of any day beyond 1/1/1700: -- note: requires full year. Example: get weekDay("1/1/1993") -- also requires isLeapYear() function below to get dayOfWeek pdate -- make a list out of the date format date pdate as "m,d,y" from "m/d/y" set m to item 1 of pdate set d to item 2 of pdate set y to item 3 of pdate -- the following list (1 item for each month) contains the -- number of days that have passed before first day of -- each month. set days to "0,31,59,90,120,151,181,212,243,273,304,334" -- set numdays to number of days elapsed since 1/1/1700 set numdays to (y-1700) div 4-(y-1700) div 100 +(y-1600) \ div 400 + 365 * (y - 1700) + item m of days + d -1 if isLeapYear(y) and m <= 2 decrement numdays by 1 end if set n to (numdays-2) mod 7 +1 return item n of \ "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday" end dayOfWeek } SCRIPT "Get the days in a month" BEHAVIOR "Returns the number of days in a month. Requires the function isLeapYear() ('Determine if a Leap Year')." CATEGORIES Dates { -- function: daysInMonth(<month>,<four-digit year>) -- Returns the number of days in a month. -- -- NOTE: this function requires 4 digits for the year. -- This function calls and requires the function isLeapYear() defined below. -- -- example: to find out how many days are in February, 1992 -- set x to daysInMonth(2,1992) -- to get daysInMonth m,y if m <> 2 return item m of "31,28,31,30,31,30,31,31,30,31,30,31" else if isLeapYear(y) return 29 else return 28 end if end if end daysInMonth } SCRIPT "Determine if a leap year" BEHAVIOR "Returns TRUE if 'y' is a leap year, FALSE if not." CATEGORIES Dates { -- NOTE: this fuction requires a four digit year. -- -- Example: Find out if 1992 is a leap year. -- if leapYear(1992) to get isLeapYear y if ((y mod 4 = 0 and y mod 100 <> 0) or (y mod 400 = 0)) return TRUE else return FALSE end end isLeapYear } SCRIPT "Find a new date" BEHAVIOR "Returns a date n days from a given date." CATEGORIES Dates { -- function: newDate(<original date>,<number of days to add>) -- -- Returns a date n days from a given date. Pass it a date -- for the first parameter, followed by an integer (positive -- or negative) representing the number of days from that date -- -- Example: to find out the date 10 days ago -- set x to newDate(sysdate,-10) -- to get newDate origdate, days format date origdate as "seconds" increment origdate by (days*24*60*60) format date origdate as sysdateformat from "seconds" return origdate end newDate } ACTION "Set Tool palette to non-sticky" BEHAVIOR "This script gives you the option of reverting to the selection tool after drawing an object instead of staying with the 'draw' tool." HANDLER Make CATEGORIES Utilities { -- This should go at the book level or in a system book forward set sysTool to "Select" } ACTION "Show properties dialog on make" BEHAVIOR "This causes ToolBook to display the properties dialog box of each object as it is made." HANDLER Make CATEGORIES Utilities { -- This should go at the book level or in a system book forward send properties to target } SCRIPT "Get the current path" BEHAVIOR "This script gets the current DOS path setting." CATEGORIES DOS { to get findCurrentPath --Link to the TB30dos dll linkDLL sysToolBookDirectory & "tb30DOS.DLL" STRING getDOSEnvironmentString (STRING) end linkDLL --Get the path list set currentPathSetting to getDOSEnvironmentString ("PATH") return currentPathSetting unlinkDLL sysToolBookDirectory & "tb30DOS.DLL" end findCurrentPath } SCRIPT "Get path from book name" BEHAVIOR "Find the path of the book executing the script" CATEGORY DOS { to get bookPath pth = name of this book while last char of pth <> "\" clear last char of pth end while return pth end bookPath } SCRIPT "Get book name without path" BEHAVIOR "Find the name of the book without any qualifying path" CATEGORY DOS { to get bookName nm = name of this book while "\" is in nm clear first char of nm end while return nm end bookName } SCRIPT "Get the current drive letter" BEHAVIOR "This function returns the directory letter from a full path after checking for its validity." CATEGORIES DOS { to get getDriveLetter pathToCheck if char 2 of pathToCheck is ":" --Link to the TB30dos dll and get the current drive list linkDLL sysToolBookDirectory & "tb30dos.dll" STRING getDriveList(STRING) end linkDLL get getDriveList("") unlinkdll sysToolBookDirectory & "tb30dos.dll" --Make sure that the drive is in the list if char 1 of pathToCheck is in it return upperCase(char 1 of pathToCheck) end if end if return NULL end getDriveLetter } SCRIPT "Get free disk space on a drive" BEHAVIOR "Returns the amount of space available on a particular drive." CATEGORIES DOS { to get findDiskSpace whatDrive local LONG diskSpaceAvailable --Link to the TB30dos dll linkDLL sysToolBookDirectory & "tb30dos.dll" LONG getFreeDiskSpace(STRING) end linkDLL set diskSpaceAvailable to getFreeDiskSpace(whatDrive) unlinkDLL sysToolBookDirectory & "tb30dos.dll" return diskSpaceAvailable end findDiskSpace } SCRIPT "Search the path for a file" BEHAVIOR "This script determines if the file is in the path." CATEGORIES DOS { to get fileInPath fileNameToCheck --Link to the TB30dos dll linkDLL sysToolBookDirectory & "tb30dos.dll" INT fileExists (STRING) STRING getDOSEnvironmentString (STRING) end linkDLL --Get the path list set currentPathList to getDOSEnvironmentString ("PATH") --Clear the 'Path=' at the beginning of the path list get offset("=",currentPathList) if it > 0 then clear chars 1 to it of currentPathList end if --Convert the path list to a list of items get offset(";",currentPathList) while it > 0 set char it of currentPathList to "," get offset(";",currentPathList) end while --Search through the list, one path at a time while currentPathList is not NULL pop currentPathList into checkPath if last char of checkPath is not "\" put "\" after checkPath end if -- we return the first place in the path where the file is found. if fileExists(checkPath & fileNameToCheck) = 1 unlinkDLL sysToolBookDirectory & "tb30dos.dll" return checkPath end if end while --Unable to find file in the path unlinkDLL sysToolBookDirectory & "tb30dos.dll" return null end fileInPath } SCRIPT "Search for files" BEHAVIOR "Returns a list of files matching the supplied file name in the supplied directory" CATEGORY DOS{ -- -- This function returns a list of all files matching the supplied file name -- in the supplied starting directory tree. It requires the handler -- searchDir below. -- -- Parameters: -- -- startingDir: a path in which the function searches for specified file(s). -- All subdirectories below startingDir will also be searched. -- -- fileName: a string containing the file name. Can contain wildcards -- -- Returns a CRLF delimited list of files, or a negative number if -- the startingDirectory supplied was invalid. -- -- Example: -- -- to get a list of all WAV files on your C drive: -- get searchDrive("c:\","*.wav") -- to get searchDrive startingDir,fileName system foundFiles,dirCount clear foundFiles dircount = 0 linkdll "tb30dos.dll" INT fileExists (STRING) STRING getDirectoryOnlyList (STRING,STRING) STRING getFileOnlyList (STRING,STRING,STRING) STRING getFileAttributes (STRING) end -- get rid of trailing slash if path is not root: if last char of startingDir is "\" and \ char (charcount(startingDir)-1) of startingDir is not ":" clear last char of startingDir end -- check to see if startingDir is valid test = getFileAttributes(startingDir) if not (test contains "D") retval = syserror else if last char of startingDir is not "\" put "\" after startingDir end statusBarStatus = visible of statusbar statusBarText = caption of statusBar visible of statusbar = true -- send this directory to be searched send searchDir startingDir,FileName visible of statusbar = statusBarStatus caption of statusBar = statusBarText retval = foundfiles clear foundfiles if retval is not null clear last char of retval clear last char of retval end end clear dircount unlinkdll function \ "fileExists,getDirectoryOnlyList,getFileOnlyList,getFileAttributes" \ from "tb30Dos.dll" return retval end -- called by searchDrive and by itself. Accumulates list of all matching -- files to filename. to handle searchDir dir,fileName system foundFiles,dirCount increment dircount put dir into caption of statusBar files = lowerCase(getFileOnlyList(dir&filename,null,"N")) if files is not null step i from 1 to textlinecount(files) fn = dir&textline i of files put fn & CRLF after foundFiles end end -- send each directory in dir to be searched dirs = lowerCase(getDirectoryOnlyList(dir,"N")) step i from 1 to textlinecount(dirs) curDir = textline i of dirs if curDir is not "." and curDir is not ".." send searchDir dir & curDir &"\",filename end end end } SCRIPT "Get the center of an object" BEHAVIOR "Gets the location of the center of an object." CATEGORIES Utilities { to get objectCenter obj if obj is null set obj to target end get bounds of obj set r to round(average (item 2 of it, item 4 of it)) push round(average (item 1 of it, item 3 of it)) onto r return r end objectCenter } SCRIPT "Center an object at a location" BEHAVIOR "Sets the center of an object to a particular location." CATEGORIES Utilities { to set objectCenter to loc get bounds of target move target to (item 1 of loc - (item 3 of it - item 1 of it) div 2),\ (item 2 of loc - (item 4 of it - item 2 of it) div 2) end objectCenter } SCRIPT "Make full screen" BEHAVIOR "Without maximizing the screen, makes the application fit in the window, and its device independent" CATEGORIES Utilities ARG setOff oneOf "0,4" is "0" help "You can push the borders off the edge of the screen by setting this to 4, or leave them alone by accepting the default." { to handle enterApplication linkDLL "tb30win.dll" INT horizontalDisplayRes() INT verticalDisplayRes() end set position of mainWindow to -$$setOff,-$$setOff set maximumSize of mainWindow to\ horizontalDisplayRes() + (2 * $$setOff),verticalDisplayRes() + (2 * $$setOff) set minimumSize of mainWindow to\ horizontalDisplayRes() + (2 * $$setOff),verticalDisplayRes() + (2 * $$setOff) unlinkDLL "tb30Win.dll" end }