name box; -- make a rectangle box of stars Property CurrentFile = 0; -- shared global variable Property CurrentSel = 0; sub CheckFileOpen flag = false; file = qedit.activefile; -- we need an object to insert into if typeof(file)=qedit.typeundefined result=dialog("You must have a file open"); else CurrentFile = file; -- update shared Global variable flag = true; endif return flag; endsub sub CheckSelection flag = false; if CheckFileOpen() s = CurrentFile.selection; if length(s) = 1 then -- Oops, only a caret is active r = dialog("You must have an active selection to fill."); else CurrentSel = s; flag = true; endif endif return flag; endsub sub make if CheckSelection() then startsel = CurrentSel.start; startl = startsel.line; startc = startsel.column; endsel = CurrentSel.end; -- unknown property if no selection endl = endsel.line; endc = endsel.column; if length(CurrentSel) = 2 then --- oops, not rectangular r = dialog("Box only works on rectangles. Use Control-Drag."); stop; endif width = endc - startc + 1; stars = ""; repeat for x from 1 to width by 1 stars = stars + "*"; endrepeat -- delete the top of the box CurrentFile.delete(startline: startl, endline: startl, startcolumn: startc, endcolumn: endc, rectangular: true); -- insert the new top of the box CurrentFile.insertcolumn(startline: startl, endline: startl, atcolumn: startc, text: stars); -- delete the bottom of the box CurrentFile.delete(startline: endl, endline: endl, startcolumn: startc, endcolumn: endc, rectangular: true); -- insert the new bottom of the box CurrentFile.insertcolumn(startline: endl, endline: endl, atcolumn: startc, text: stars); height= endl - startl + 1; stars = "*"; -- delete the left side of box CurrentFile.delete(startline: startl, endline: endl, startcolumn: startc, endcolumn: startc, rectangular: true); -- insert left side of box CurrentFile.insertcolumn(startline: startl, endline: endl, atcolumn: startc, text: stars); -- delete the right side of box CurrentFile.delete(startline: startl, endline: endl, startcolumn: endc, endcolumn: endc, rectangular: true); -- insert right side of box CurrentFile.insertcolumn(startline: startl, endline: endl, atcolumn: endc, text: stars); -- Cancel selection, Position caret at upper left corner: CurrentFile.select(startline: startl, startcolumn: startc); endif endsub make(); -- dummy mainline. make is exported as a callable method << Author: bgreen@robelle.com Date: Sept 26, 1999 Web: box.qsl Comments: 1. You will run this script from the Script Menu. 2. Save script as a local file, box.qsl anywhere on c:\ drive. 3. Go to Script-ManageScripts dialog. 4. If 'box' is already there, click and Remove it. 5. Click Add and browse to box.qsl file and select it. 6. Click Done to finish ManageScripts dialog. 7. Open any file with some text in it. 8. Create a rectangular selection using Control and mouse-drag. 9. Select Script-Box to replace the selection with a box. 10. This script is based on replace01.qsl -- see it for coding notes. 11. The mainline is in the make() sub to give it an explicit name so that it can be invoked from another script. 12. Exercise: change the logic to insert the box around the rectangle selection (i.e., insert rows and columns so that this box will not delete any existing characters). >>