WNGZWZSC0110-   OO84#0You must have a sheet open to use this function.? 9??>7v9/)#%Cannot delete; no Cell Range selected96#2Cannot delete; the first range is not a Cell Range?@9?@97 O N NO   ???.+??.+???p Delete Block/OK@Cancel@ @@  H!BDELETE.scz:ok_button = TRUE() DELETE.scz:delete_dir = CTVALUE(3,0)/Left Up @g Shift Cells@J9 9%*?"*?    rowcol last_row last_col act_rows act_cols ok_button delete_dirpresent_sheet new_sheet LEFT DeleteBlock{ DeleteBlock() This script was developed by Informix to demonstrate how to design a dialog box and work with the clipboard. This script designs a dialog with a two radio buttons. There is only one function in this file: DeleteBlock. Conventions: HyperScript keywords and functions are in all capital letters, user functions are in proper case, and variables are in lower case. Some variables are used as constants (i.e. they are defined and initialized, but are never changed), these always appear in all capital letters. TO USE THIS SCRIPT: To add this function to a menu, add the following to a Startup script: SELECT MENU "~Sheet"; ADD MENUITEM "Delete Block..." COMMAND "GET SCRIPT ""/usr/lpp/Wingz/Examples/Delete.scz""; CALL Delete.scz:DeleteBlock(); REMOVE SCRIPT ""Delete.scz"";"; You can then access the function just by going to the "Sheet" menu and selecting the command from the menu. NOTE: Before calling this function or choosing it from the menu, you must select a range of cells to delete. } { Variable List } DEFINE row, col { hold the upper-left corner of the } { selected area } DEFINE last_row, last_col { save the lower-right corner of the } { selected area } DEFINE act_rows, act_cols { save the size of the active sheet by } { saving the number of active rows and } { columns } DEFINE ok_button { a flag that holds the status of the } { OK button on the dialog box } DEFINE delete_dir { a flag that holds the direction the } { surrounding area will be shifted to } { fill the deleted block } { 0 will indicate shift up } { 1 will indicate shift to the left } DEFINE present_sheet { save the current sheet name } DEFINE new_sheet { this sheet is used as a temporary } { storage area for the clipboard } { Variables used as Constants } DEFINE LEFT { constant used to indicate the } { diretion the area should be shifted } CALL DeleteBlock() { DeleteBlock() This function will delete a block of the sheet and then shift the cells surrounding the block either up or left to fill in the empty space. All cells in the direction of the shift are moved sufficient cells to fill in the space in the sheet. The user must first select an area and then call this function, this function will then display a dialog box which allows the user to select which direction to shift cells to fill in the marked block } FUNCTION DeleteBlock() IF (ISERR(NAME())) { check if there is a sheet open } MESSAGE "You must have a sheet open to use this function." EXIT SCRIPT END IF LEFT = 1 { Initialize constant to use with } { the delete_dir flag. } { Determine if a range has been } { selected, and if the first range } { selected is a cell range. } { If not print an appropriate message } { and exit the script. } IF ((NRSELECTIONS() = 0) OR (SELECTIONTYPE(1) <> 1)) { Something failed. } { Determine which condition failed. } IF (NRSELECTIONS() = 0) MESSAGE ("Cannot delete; no Cell Range selected") ELSE MESSAGE ("Cannot delete; the first range is not a Cell Range") END IF EXIT FUNCTION END IF { END IF the check for a valid area. } { Check to see if the user has an } { entire row or column selected. } IF ((COLS(SELECTION(1)) = 32768) OR (ROWS(SELECTION(1)) = 32768)) DELETE { Do the system delete and exit. } EXIT FUNCTION END IF present_sheet = NAME() { Save the name of the current sheet } { Create a new sheet to use a place } { to store the current clipboard } NEW WORKSHEET "" LOCATION (20000,20000) (0,0) new_sheet = NAME() { Save the name of the new sheet and } PASTE { put the contents of the clipboard } { into it. } INVALIDATE ON { Because we turned INVALIDATE ON, any } { changes will not be updated on the } { sheet. When we use the INVALIDATE ON } { command, Wingz will save a list of } { any parts of the screen that SHOULD } { HAVE BEEN repainted but not do the } { actual repainting until the } { INVALIDATE OFF command is encountered.} GO TO WINDOW present_sheet { Go back to the original sheet } row = ROWOF(SELECTION(1)) { Save the coordinates of the } col = COLOF(SELECTION(1)) { selected area. } last_row = row+ROWS(SELECTION(1))-1 last_col = col+COLS(SELECTION(1))-1 SELECT ACTIVE CELLS { Select all cells being used and } act_rows = ROWS(SELECTION(1)) { save the size of the active sheet. } act_cols = COLS(SELECTION(1)) { Reselect the original area. } SELECT RANGE MAKERANGE(col,row,last_col,last_row) { Define the dialog box here. } { Define a dialog box of the specified } { height and width that is centered on } { the screen. } { The (-1,-1) means center this box on } { the screen. The second set of coord- } { inates specify the size of the box. } NEW MODAL DIALOG BOX AT (-1,-1) (2.5inch,1.5inch) NAME DIALOG BOX "Delete Block" { Add the two buttons, the OK and } { CANCEL buttons, in the specified } { rectangle. These will be controls } { one and two. } { CONTROLS 1 and 2 } ADD PUSH BUTTON "OK@","Cancel@" AT (0.2inch,1inch) (2.3inch,1.4inch) DIALOG CANCEL PUSH BUTTON { Specify an action for the CANCEL } { button, which is the current control } { because it was the last one added. } SELECT CONTROL 1 { Select the OK button, it was the } { first control added so it has the } { control number of 1. } DIALOG DEFAULT PUSH BUTTON { Make the OK button the default } { control, which means it will have a } { wider border. } { Specify what should happen when the } { OK button is pressed: } { -set the OK flag. } { -save the current value of the } { the radio button control. } SCRIPT "DELETE.scz:ok_button = TRUE() "& "DELETE.scz:delete_dir = CTVALUE(3,0)" { CONTROL 3 } { Add two radio buttons so the user can } { choose which direction the cells will } { be shifted. } ADD RADIO BUTTON "Left ","Up " AT (0.1inch,0.1inch) (2.4inch,0.8inch) SHOW CONTROL NAME "Shift Cells@" OUTLINE 2 BORDER USE DIALOG BOX { Display the box } IF (ok_button = TRUE()) { If the user pressed the OK button } { process the delete, otherwise skip it.} { Regardless of which direction the user} { wants to shift the cells, you need to } { delete the block. Thus, do that } { before looking at the delete_dir flag.} SELECT RANGE MAKERANGE(col,row,last_col,last_row) CLEAR { Now figure out which way to shift the } { cells, but don't do the cutting and } { pasting inside the IF. Do it after } { to reduce duplicate code and make the } { purpose of the IF statement more } { clear. } IF (delete_dir = LEFT) SELECT RANGE MAKERANGE(last_col+1,row,act_cols,last_row) ELSE SELECT RANGE MAKERANGE(col,last_row+1,last_col,act_rows) END IF { Cut all of the cells out and put them } { in the block that was deleted. } CUT SELECT RANGE MAKECELL(col,row) PASTE UNSELECT { Unhighlight the marked area. } END IF { END IF ok_button = TRUE() } GO TO WINDOW NEW_SHEET { Move the temporary sheet. } COPY { Copy it to the clipboard. } CLOSE NOW { Close the temporary sheet. } SELECT RANGE MAKERANGE(col,row,last_col,last_row) INVALIDATE OFF { Set the INVALIDATE flag off. This } { will cause Wingz to repaint the } { objects which have changed since } { INVALIDATE was turned on. } END FUNCTION