name HtmlTable; -- generate HTML code for a table
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 genColumn
return "
| ";
endsub
sub genRow(columns)
str = "";
repeat for x from 1 to columns by 1
str = str + genColumn();
endrepeat;
str = str + "
";
return str;
endsub
sub genTable(rows,columns)
html = {""};
if rows<1 or rows>500
r=dialog("Table can have from 1 to 500 rows.");
else
if columns < 1 or columns > 20
r=dialog("A table can have from 1 to 20 columns.");
else
html = html + "";
repeat for x from 1 to rows by 1
html = html + genRow(columns);
endrepeat;
html = html + "
";
html = html + "";
endif
endif
return html;
endsub
sub getRows;
-- dialog() returns a record.
result = dialog("How many rows in your table?",1,"");
r = dialog(string(result));
-- {button: 1, enteredText: "10"}
return integer(result.enteredText);
endsub
sub getColumns;
result = dialog("How many columns in your table?",1,"");
return integer(result.enteredText);
endsub
if CheckFileOpen() then
CurrentFile.insert(genTable(getRows(),getColumns()));
endif
<< Author: bgreen@robelle.com
Date: Sept 14, 1999
Web: htmltable.qsl
Comments:
1. You will run this script from the Script Menu.
2. Save script as a local file, htmltable.qsl anywhere on c:\ drive.
3. Go to Script-ManageScripts dialog.
4. If 'htmltable' is already there, click and Remove it.
5. Click Add and browse to htmltable.qsl file and select it.
6. Click Done to finish ManageScripts dialog.
7. Open any file with some text in it.
8. Place the cursor where you want the HTML code for the table.
9. Select Script-HtmlTable to replace the selection with a box.
10. The dialog() call requests an OK button (1) and no default answer.
It returns a record that tells which button was pressed and
the enteredText value.
11. Wherever possible, this script shows calling subroutine from within
other subroutine and method calls and using the results as parameters.
12. Exercise: Change the script to ask you for the overall
width of the table (accept 50% or 500 pixels and insert
into the tag as 'width=50%'). Change the script
to ask if you prompt for headings and generate |
tags for them.
>>
|