Personal C Sharp                                                         By  famsoft.org
HomeHow To StartExamples-DesktopExamples-WebPC# MethodsReference-DesktopReference-Web


DEMONSTRATIVE EXAMPLES ====================== WEB PAGE DEVELOPMENT II ====================== THE NEW MASTER PAGE FILE: ========================= In Web Page Development I section, we have been trying not to get into "Error handling" discussions. The reason was to make things simple. Before getting further, you must read the "Error handling" sections of both "Personal C# reference for desktop applications" and "Personal C Sharp reference for web applications". The default error level code is (eri=2) and this has been the error level code for all the examples of "Web page development I". Now, we like to switch to error level zero (eri=0) so we can handle the expected errors by ourselves. The bottom section of each page which is made of the two tables "tb4" and "tb5" will be used more actively to display error messages or important instructions to the user. We are going to include a new method into the master file in order to simplify this job. Other than that the new master file is going to be the same as the original one. Here is the new method: public void DisplayMessage(int l, int t, string ms) { // Input var's: l=which label, l=0 means lb00, l=1 means lb01. // t=Message type (color selected accordingly) // t=0 means instructions, t=1 means Success, t=2 means Error. // ms=Message text. cls="S9 G3 r0 ".Substring(3*t,2)+"p7"; // Msg type determines foreground color, if (l==0) cs="lb00"; else cs="lb01"; // Left or right label? wm("sC"); // Set message color cis=ms;wm("sl"); // Make msg the label's text } } The first parameter tells the method which label you like the message to appear into. The second parameter tells the method about the urgency of the message. The method selects the color to display message into accordingly. It can be: 0 Used for "instructions" which will be displayed in black color. 1 Used for reasons like informing user that his task has been done successfully. Green color will be used. 2 Used for urgent messages like errors. Red color will be used. ========================================================================================= THE MASTER PAGE CLASS: ---------------------- public partial class master1:pasp { public override void setup() { //---------------------------------- Page Contents ----------------------------------- cns=""; // tb0 Container="" since it's // mounted directly on the page. cs="tb0";cls="S9g8";fns="trb12";wm("i"); // tb0 installation parameters //----------------------------------- tb0 Contents ----------------------------------- cns="tb0"; // Container=tb0 for next tables cs="tb1";j=0;k=0;i=2;lf=760;of=100;cls="S9p7";fns="trb12";jd=5;ds="n";wm("i"); cs="tb2";j=0;k=1;lf=380;of=250;;cls="S9p7";fns="trb12";jd=5;wm("i"); cs="tb3";j=1;k=1;lf=380;of=250;cls="S9p7";fns="trb12";jd=5;wm("i"); cs="tb4";j=0;k=2;lf=380;of=50;cls="S9p7";fns="trb12";jd=5;wm("i"); cs="tb5";j=1;k=2;lf=380;of=50;cls="S9p7";fns="trb12";jd=5;wm("i"); //----------------------------------- tb1 Contents ---------------------------------- cns="tb1"; // tb1 is divided into 11 col,3 rows cls="r0";fns="trb24";ds="c";os="Web Page Development II";wm("dp"); cs="lt01";j=0;k=0;i=10;ds="c";wm("i"); // Insert Ap title into (cis) Create // Literal control, make cs its text cs="hl11";j=0;k=1;i=3;cis=" Home ";fns="trb12"; cls="s9b0";ds="e";urs="..\\default.aspx";wm("i"); cs="lt02";j=3;k=1;i=4;cis="Insert This Page's Number Here";ds="c";fns="trb12";wm("i"); cs="hl12";j=7;k=1;i=3;cis="WPD I";fns="trb12"; cls="s9b0";ds="w";urs="..\\WPDI\\pg1.aspx";wm("i"); cs="hl01";j=0;k=2;cis="Page 1";fns="trb12";cls="s9b0";ds="c";urs="pg1.aspx";wm("i"); cs="hl02";j=1;k=2;cis="Page 2";fns="trb12";cls="s9b0";ds="c";urs="pg2.aspx";wm("i"); cs="hl03";j=2;k=2;cis="Page 3";fns="trb12";cls="s9b0";ds="c";urs="pg3.aspx";wm("i"); cs="hl04";j=3;k=2;cis="Page 4";fns="trb12";cls="s9b0";ds="c";urs="pg4.aspx";wm("i"); cs="hl05";j=4;k=2;cis="Page 5";fns="trb12";cls="s9b0";ds="c";urs="pg5.aspx";wm("i"); cs="hl06";j=5;k=2;cis="Page 6";fns="trb12";cls="s9b0";ds="c";urs="pg6.aspx";wm("i"); cs="hl07";j=6;k=2;cis="Page 7";fns="trb12";cls="s9b0";ds="c";urs="pg7.aspx";wm("i"); cs="hl08";j=7;k=2;cis="Page 8";fns="trb12";cls="s9b0";ds="c";urs="pg8.aspx";wm("i"); cs="hl09";j=8;k=2;cis="Page 9";fns="trb12";cls="s9b0";ds="c";urs="pg9.aspx";wm("i"); cs="hl10";j=9;k=2;cis="Page 10";fns="trb12";cls="s9b0";ds="c";urs="pg10.aspx";wm("i"); cs="im00";j=10;k=0;o=3;ds="e";lf=190;of=90;ims="..\\images\\icon.jpg";jd=5;wm("i"); // Image, scaled to (190,90) pixels //----------------------------------- tb4 Contents ---------------------------------- cns="tb4"; // tb4 is made of 1 col, 1 row cs="lb00";cis="Server Response: ";wm("i"); // Create (lb00), cis=its txt //----------------------------------- tb5 Contents ---------------------------------- cns="tb5"; // tb5 is made of 1 col, 1 row cs="lb01";cis="Server Response: ";wm("i"); // Create (lb01), cis=its txt } public void PageNumber(int pgno) { cs="lt02";cis="Page Number "+pgno;wm("sl"); } public void DisplayMessage(int l, int t, string ms) { // Input var's: l=which label, j=0 means lb00, j=1 means lb01. // t=Message type (color selected accordingly) // t=0 means instructions, t=1 means Success, t=2 means Error. // ms=Message text. cls="S9 G3 r0 ".Substring(3*t,2)+"p7"; if (l==0) cs="lb00"; else cs="lb01"; wm("sC"); cis=ms;wm("sl"); } } ========================================================================================= FILING ======== Generally, filing is not a web application. This is because normally, you don't like your website viewers to modify file data directly. You must have control on which data gets into your files. However, in some cases, you may allow them to read the file data directly and in a few cases, you may like to give a specific user the right to modify one record or more in a file. Making filing code suitable for web applications: ================================================= When you do filing in a web application, you meet some few new problems. Here is what they are and how to overcome them. OBTAINING THE FILE PATH: ------------------------ In a desktop application if the file name which you have supplied method fm() with was "test.txt" and you have executed your program at the same folder in which that file resides, the file will be assumed to be local to that folder and everything will go the way you wanted it to go. In a web application, you don't execute the application page by yourself. The browser requests the page from the server then the server executes the page. So, your application folder where "test.txt" resides is not the execution folder. The execution folder will most likely be "Windows\System32" or a subfolder of it. So, if you supply the name "test.txt" without supplying the full path, You'll be understood as you mean "Windows\System32\test.txt". What a mess! Method wm() at mode "fp" fixes that for you by getting for you the actual file path of the file. Here is how to use it: js="test.txt";wm("fp"); You assign the name of the file relative to your application folder to (js) then call wm("fp") After the execution of this method, (fls) will contain the full path of your file. The full path of the file can be "c:\inetpub\wwwroot\WPDII\test.txt" COMPARING LOCAL PATH WITH WEB PATH: ----------------------------------- If your application folder name was "WPDII" and it contains the file "test.txt", The local pass of the file will most likely be: "c:\inetpub\wwwroot\WPDII\test.txt" assuming that the root drive is "c". The web path should be "/WPDII/test.txt". and the the application folder "/WPDII" is looked at by the browser as the current folder, so using the name "test.txt" to identify the file to the web within the page's class is legal. Windows uses backslashes to seperate files and folders while the web uses forward slashes. When you supply a string to "C#" which contains backslash characters, you need to double each of them since one backslash char is illegal. It means a special char and must be followed with a character to define what that special char is. So, before you supply the local path of file "test.txt" to method fm(), you should modify it to: "c:\\inetpub\\wwwroot\\WPDII\\test.txt" The web path needs no modification since the forward slash is a legal character. IMPORTANT REMARK: ----------------- The full path string which you get by calling wm("fp") assigned to (fls) can be used as is since the method doubles all backslashes of the path before it returns it to your program. GOING BACKWARD WITH THE PATH: ----------------------------- Since the application folder is considered to be the "current folder" for a web page, folder ".." is the parent folder of the application folder and folder "../.." is the grand parent. So: fls="../images/flower.jpg" is the web path of the file "flower.jpg" which is located into subfolder "images" of the parent folder of the application folder. ONE MORE REMARK: ---------------- Whenever a forward slash is expected to be the "file - folder" seperator, the ASP.NET allows us to use either a forward slash or backslash. So you could have also used: fls="..\\images\\flower.jpg" without a problem. LOCKING THE APPLICATION BEFORE WRITING: --------------------------------------- As you must know, a web application is a multi-thread application in which more than one thread can be accessing the same file at the same time. This should be of concern only when writing into a file. To overcome this problem, you need to lock the application before each writing statement then unlock it back when the writing is done. Here is how to do it: Application.Lock(); // Lock application fs="sf0";os="Data to be written";fm("wl");// Write data Application.UnLock(); // Unlock application ========================================================================================= SEQUENCIAL ACCESS FILES Here is the code of example 2 of the desktop filing application modified so it qualifies as a web application. All read data is going to be displayed into the text area "ta0" which we are assuming that it has been installed into the page in advance. // ----------------------- CREATING THE FILE AND WRITING DATA --------------------- js="test.txt";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained Application.Lock(); // Lock application ks="f";fm("D"); // delete file. fs="sf0";fm("ow"); // open for write os="Text Line Number 1";fm("wl"); // write line fm("c"); // close fs="sf0";fm("oa"); // open for append os="Text Line Number 2";fm("wl"); // write line fm("c"); // close file Application.UnLock(); // Unlock application // --------------------------------- READING DATA BACK ---------------------------- js="test.txt";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained fs="sf0";fm("or"); // Open for read fm("ra"); // Read all file cs="ta0";cus=os.Substring(0,os.Length-1);wm("su"); // Remove eof char. Display data into "ta0". fm("c"); // close file } We have kept the application locked during the entire file deletion, creation and writing operations and displayed the data into "ta0". Writing a demonstration program: -------------------------------- The code above is all you need to do filing for a web application. However, we like to create a web page here which demonstrates the sequencial files use. It is going to take more code than necessary for your filing and also will not work very good since we are going to use only one short file for all viewers. The data written by one viewer may be ovewritten by another before he/she reads it back. I hope people will forgive us for that! Example 1: We are going to create a web page which allows users to write text into the SAF "test.txt" then read it back. ========================================================================================= public partial class pg1:master1 { // Page class extends master class public override void init() { eri=0; // Set error level to 0. base.init(); } public override void setup() { base.setup(); // Run setup() of master page first //----------------------------------- tb2 Contents ---------------------------------- cns="tb2"; // tb2 is made of 1 col, 3 rows cs="lb0";cis="Sequencial Access Files - Writing";j=k=0;ds="c"; fns="trb16";cls="r0p7";wm("i"); // Title cs="ta0";cis="Enter text to be written into file 'test.txt'"; j=0;k=1;ds="c"; // text area for text to be written jf=40;kf=6;cls="b0y0";fns="trbi12";wm("i"); cs="bt0";cis="Write Into File";j=0;k=2;ds="c"; // Submit button. cls="r0g8";fns="trb12";wm("i"); //----------------------------------- tb3 Contents ---------------------------------- cns="tb3"; // tb3 is made of 1 col, 3 rows cs="lb1";cis="Sequencial Access Files - Reading";j=k=0;ds="c"; fns="trb16";cls="r0p7";wm("i"); // Title cs="ta1";cis="Text read from file 'test.txt'"; // Text area for text to be read j=0;k=1;ds="c";jf=40;kf=6;cls="b0y0";fns="trbi12";wm("i"); // tf0 size is 20 chars. cs="bt1";cis="Read File";j=0;k=2;ds="c"; // Submit button cls="r0g8";fns="trb12";wm("i"); } //------------------------------------------------------------------------------------ public override void update() { if(cs.Equals("pl")) { // If event is "Page_Load" setup(); // Execute setup() MakePage(table); // and Make the page PageNumber(1); // Calling master class's method } // to display this page's number // --------------------------------- WRITING INTO FILE ----------------------------- if(cs.Equals("bt0")) { // If event is: "bt0 clicked" try { // Start op while catching exceptions cs="ta0";wm("gu"); // Get update text of ta0 in (cus) js="test.txt";wm("fp"); // Get full path of file "test.txt" if (fls.Length<1) return; // If not successful return Application.Lock(); // Lock application fm("A"); // check file attributes if(os != " ") { // If file exists ks="f";fm("D"); // Delete it. } fs="sf0";fm("ow"); // open file for write os=cus;fm("wl"); // write text into file fm("c"); // close file Application.UnLock(); // Unlock application DisplayMessage(0,1,"Data has been written successfully."); } // Send success message. catch { // If exception has occured DisplayMessage(0,2,"ERROR: "+exp.Message); } } // --------------------------------- READING DATA BACK ----------------------------- if(cs.Equals("bt1")) { // If event is: "bt1 clicked" try { // Start op while catching exceptions js="test.txt";wm("fp"); // Get full path of file "test.txt" if (fls.Length<1) return; // If not successful return fs="sf0";fm("or"); // Open file for read fm("ra"); // Read entire file cus=os.Substring(0,os.Length-1); // Eliminate eof mark, assign to (cus) fm("c"); // close file cs="ta1";wm("su"); // Display text on "ta1" DisplayMessage(1,1,"Data has been read back successfully."); } // Send success message. catch { // If exception has occured DisplayMessage(1,2,"ERROR: "+exp.Message); } } // Display Error msg to user } } =========================================================================================


GENERAL RANDOM ACCESS FILES =========================== A General Random Access File (RAF) is made of equal size records. It allows you to read or save a record instantly without having to read all preceeding records in the file. Each record is a string which you can use as is to store string data or use it to build your own database. Reading and writing data for this file type has been demonstrated in example 4 of desktop filing. Here is how to modify that example to make it suitable for web filing: // ----------------------- CREATING THE FILE AND WRITING DATA --------------------- js="test.txt";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained Application.Lock(); // Lock application fm("A"); // check file attributes if(os != " ") {ks="f";fm("D");} // If exists, delete it fs="rf0";rcl=24;ib=true;fm("o"); // Open file as headerless RAF, rec length=24 rcs="Line number one.";rci=0;fm("w");// Write first record rcs="Line #2.";rci=1;fm("w"); // Write second record fm("c"); // Close the file. Application.UnLock(); // Unlock application // ------------------------------- READING DATA BACK ------------------------------ js="test.txt";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained fs="rf0";rcl=24;ib=true;fm("o"); // Open file as headerless RAF, rec length=24 n=0;dnb=false; // Initialize record number counter, eof flag. while (!dnb) { // Start record reading loop. rci=n;fm("r"); // Read one record. os=rcs;om("c"); // Clean record (remove trailing null chars) tm(); // Then display record. n++; // increment record number. } fm("c"); // Close the file. } Writing a demonstration program: -------------------------------- As we mentioned before, the code above is all you need to do this type of filing in a web application. Allowing the user to create new file or write data direcly into the file is not of practical use to your own. However, it could be a nice example on how to interact with the user. Example 2: The code of this example will allow the user to create, write to and read from a headerless RAF. REMARK: Within the body of some of the messages which are displayed to the user, you may see the modified html tag "[br]". The actual brackets in this word are angled brackets. They have been changed to square brackets here only in order to make your browser display the tag instead of executing it. The tag causes a linefeed ========================================================================================= public partial class pg2:master1 { // Page class extends master class public override void init() { eri=0; // Set error handling level to 0. base.init(); } public override void setup() { base.setup(); // Run setup() of master page first //----------------------------------- tb2 Contents ---------------------------------- cns="tb2"; // tb2 is made of 3 cols, 6 rows cs="lb0";cis="Random Access Files";j=k=0;i=3;ds="c";fns="trb16";cls="r0p7";wm("i"); cs="lb1";cis="Creating File:";j=0;k=1;ds="w";fns="trb16";cls="M2p7";wm("i"); cs="tf0";cis="Rec Length";j=1;k=1;os="n";ds="s"; jf=2;od=2;cls="S9m7";fns="trb12";wm("i"); cs="bt0";cis="Create";j=2;k=1;i=3;ds="s";cls="r0m8";fns="trb12";wm("i"); cs="lt0";cis="========================================";j=0;k=2;i=3;wm("i"); cs="lb2";cis="Writing:";j=0;k=3;ds="w";fns="trb16";cls="b0p7";wm("i"); cs="tf1";cis="Rec Length";j=1;k=3;os="n";ds="c"; jf=2;od=2;cls="S9b7";fns="trb12";wm("i"); cs="tf2";cis="Rec Number";j=2;k=3;os="n";ds="c"; jf=1;od=1;cls="S9b7";fns="trb12";wm("i"); cs="tf3";cis="Enter text to be written into Rec. (upto record length)"; j=0;k=4;i=3;ds="e";jf=46;od=99;cls="S9b7";fns="trb12";wm("i"); cs="bt1";cis="Write Record";j=0;k=5;i=3;ds="c";cls="r0g8";fns="trb12";wm("i"); //----------------------------------- tb3 Contents ---------------------------------- cns="tb3"; // tb3 is made of 2 cols, 4 rows cs="lb3";cis="Reading:";j=0;k=0;ds="w";fns="trb16";cls="r0p7";wm("i"); cs="tf4";cis="Record Length";j=1;k=0;os="w";ds="e"; jf=2;od=2;cls="S9y5";fns="trb12";wm("i"); cs="tf5";cis="Record Number";j=0;k=1;os="w";ds="w"; jf=1;od=1;cls="b0y5";fns="trb12";wm("i"); cs="cb1";cis="Read all records";j=1;k=1;ds="e";cls="S9p7";fns="trb12";wm("i"); cs="ta1";cis="Text read from Random Access File";j=0;k=2;i=2;ds="c"; jf=46;kf=6;cls="b0y5";fns="trbi12";wm("i"); cs="bt2";cis="Read File";j=0;k=3;i=2;ds="c";cls="r0g8";fns="trb12";wm("i"); } //------------------------------------------------------------------------------------ public override void update() { if(cs.Equals("pl")) { // If event is "Page_Load" setup(); // Execute setup() MakePage(table); // and Make the page PageNumber(2); // Call master class's method ms="Select a record length when creating file and supply[br]the same record length"; ms+=" when reading or writing."; // Instructions to display to user DisplayMessage(0,0,ms); // Display instructions on lb00 DisplayMessage(1,0,""); // Display nothing on lb01 } // ------------------------------- CREATING NEW FILE ------------------------------- if(cs.Equals("bt0")) { // If Create button clicked" // Var 's Used: ms=Temporarely stores Server response message try { // Start op while catching exceptions js="test.raf";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained fm("A"); // check file attributes if(os != " ") { // If exists Application.Lock(); ks="f";fm("D"); // Delete it while application locked Application.UnLock(); } cs="tf0";wm("gu");ss=cus; // Get update of tf0 (for rec length) try {os=cus;om("ti");rcl=o;} // Try Converting to int catch { // If error occured DisplayMessage(0,2,"ERROR: Unreadable record length."); return; // Display error msg to user, return } cus=ss;cs="tf1";wm("su"); // Else, Write same Rec Length into cus=ss;cs="tf4";wm("su"); // all other rec length text fields fs="rf0";ib=true;fm("o"); // open file fm("c"); // Close File DisplayMessage(0,1,"New File has been created."); return; // Display msg and return. } catch { // If any other exception occured DisplayMessage(0,2,"ERROR: "+exp.Message);// during process, display its msg } } // ------------------------------- WRITING INTO FILE ------------------------------- else if(cs.Equals("bt1")) { // Else if Write button clicked: try { // Start op while catching exceptions js="test.raf";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained cs="tf1";wm("gu"); // Read rec length text field try {os=cus;om("ti");rcl=o;} // Try converting to int,assign to rcl catch { // If error occured: fm("c"); // Close file DisplayMessage(0,2,"ERROR: Unreadable record length."); return; // Display error message, return. } fs="rf0";ib=true;fm("o"); // open file cs="tf2";wm("gu"); // Read rec number text field try {os=cus;om("ti");rci=o;} // Try converting to int,assign to rci catch { // If error occured: fm("c"); // Close file DisplayMessage(0,2,"ERROR: Unreadable record number."); return; // Display error msg, return. } cs="tf3";wm("gu"); // Else Read rec string text field Application.Lock(); // Lock application fs="rf0";rcs=cus;fm("w"); // write record Application.UnLock(); // Unlock application fm("c"); // close file ms="Record Data Written into RAF.";DisplayMessage(0,1,ms); } // Display successful operation msg catch { // If any other exception occured DisplayMessage(0,2,"ERROR: "+exp.Message);// during entire process, display its } // message to user. } // --------------------------------- READING DATA BACK ---------------------------- else if(cs.Equals("bt2")) { // If "bt2" clicked try { // Start op while catching exceptions js="test.raf";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained cs="tf4";wm("gu"); // Get "tf4" update (rec length) try {os=cus;om("ti");rcl=o;} // Try converting to int catch { // If error occured: fm("c"); // close file DisplayMessage(1,2,"ERROR: Unreadable record length."); return; // Display error msg, return. } fs="rf0";ib=true;fm("o"); // open file cs="cb1";wm("gu"); // See if "Read all records" checked if (cus.Equals("1")) { // If checked dnb=false;cus="";rci=0; // Initialize EOF flag, rec number while (!dnb) { fs="rf0";fm("r");cus+=rcs+"\n"; // Keep reading lines until EOF rci++; // adding them all to (cus) } } else { // Else if "Rd all records" unchecked cs="tf5";wm("gu"); // Get "tf5" update (Record number) try {os=cus;om("ti");rci=o;} // Try to convert to int catch { // If error occured: fm("c"); // Close file DisplayMessage(1,2,"ERROR: Unreadable record number."); return; // Display error msg, return. } fs="rf0";fm("r");cus=rcs; // Read record, assign text to (cus) } cs="ta1";wm("su"); // Display text on text area "ta1" fm("c"); // Close file DisplayMessage(1,1,"Record Data Read successfully."); } // Inform user of successful operation catch { // If any other exception occured DisplayMessage(1,2,"ERROR: "+exp.Message); // during entire process, display its } // message to user. } } } =========================================================================================


RAF2 RANDOM ACCESS FILES WITH HEADERS =========================== Our Random Access File has been made capable of storing multi fields of both numeric and string types by using a header which resides into its first record (record number zero) and contains the record length in addition to the locations and types of all the fields. Reading and writing data for this type of file has been demonstrated in example 5 of desktop filing. Here is how to modify that example to make it fit for web filing: ========================================================================================= // ------------------- CREATING THE FILE AND WRITING THE HEADER ------------------ js="test1.txt";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained Application.Lock(); // Lock application fm("A"); // check file attributes if(os != " ") {ks="f";fm("D");} // If exists, delete it fs="rf0";rcl=100;ib=true;fm("o"); // open the file as no header file OS[0]="name";OD[0]=35; // 35 character string field OS[1]="age";OD[1]=0.0; // Integer field OS[2]="position";OD[2]=25; // 25 character string field OS[3]="salary";OD[3]=0.2; // numeric field with 2-decimal digits fm("wh"); // Write header. fm("c"); // Close the file. Application.UnLock(); // Unlock application // -------------------------- ENTERING DATA INTO THE FILE ------------------------- js="test1.txt";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained fls="test.raf";fs="rf0";fm("o"); // open file and read header information // Notice that we did not supply rec# OS[0]="John Smith"; // First field data, a string in OS[] OD[1]=25; // Second field data, a number in OD[] OS[2]="Machine operator"; // Third field data, a string in OS[] OD[3]=35000.50; // Fourth field data, a number in OD[] Application.Lock(); // Lock application rci=1;fm("w"); // Write record #1 Application.UnLock(); // Unlock application OS[0]="Mary Jones"; // OD[1]=20; // OS[2]="Clerk"; // Field data for second record OD[3]=25000.66; // Application.Lock(); // Lock application rci=2;fm("w"); // Write record #2 Application.UnLock(); // Unlock application fm("c"); // Close the file. // ------------------------------ READING DATA BACK ------------------------------ js="test1.txt";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained fls="test.raf";fs="rf0";fm("o"); // open file and read header information // Notice that we did not supply rec# or any // field information. The file reads itself. n=1; // Start by record # 1 while (!dnb) { // Do until eof encountered. rci=n;fm("r"); // Read one record. (See REMARK) os=OS[0];tm(); // Read and display 1st field os=OS[1];tm(); // Read & display 2nd field os=OS[2];tm(); // Read and display 3rd field os=OS[3];tm(); // Read & display 4th field os="";tm(); // Add blank line to seperate records n++; // increment record number. } fm("c"); // Close the file. } ========================================================================================= Writing a demonstration program: -------------------------------- As we mentioned before, the code above is all you need to do this type of filing in a web application. Allowing the user to create new file or write data direcly into the file is not of practical use to your own. However, it could be a nice example on how to interact with the user. Example 3: The code of this example will introduce this type of filing to the user. ========================================================================================= public partial class pg3:master1 { // Page class extends master class public override void init() { eri=0; // Set error level to 0. base.init(); } public override void setup() { base.setup(); // Run setup() of master page first //----------------------------------- tb2 Contents ---------------------------------- cns="tb2"; // tb2 is made of 1 col, 2 rows cs="lb0";cis="Random Access File With A Header"; j=k=0;ds="n";fns="trb14";cls="r0p7";wm("i"); cs="lt0";cis="";j=0;k=1;ds="nw";fns="trb8";cls="S9p7";wm("i"); //----------------------------------- tb3 Contents ---------------------------------- cns="tb3"; // tb3 is made of 1 col, 2 rows cs="lb1";cis="Demonstration";j=0;k=0;ds="c";fns="trb14";cls="r0p7";wm("i"); cs="lt1";cis="";j=0;k=1;ds="nw";fns="trb8";cls="S9p7";wm("i"); } //------------------------------------------------------------------------------------ public override void update() { if(cs.Equals("pl")) { // If event is "Page_Load" setup(); // Execute setup() MakePage(table); // and Make the page PageNumber(3); // Calling master class's method wm("o");fns="tr12"; os="You may call it a Personal Database. You set its record length and field data"; os+=" with a very simple code. The data is written into the file's header and from"; os+=" this point up, you need not to supply any data to read from or write"; os+=" into the file other than the file's name.";wm();os="";wm(); os="Field types can either be string or numeric. One unified type code defines"; os+=" a field of either type. String fields can be of any length "; os+="while numeric fields are always 5 bytes long."; wm(); wm("c");cs="lt0";wm("sl"); wm("o"); os="In the next page, you will be able to to create, read from and write into"; os+=" a file which contains the following four fields:";wm();wm(); os="NAME      : Upto 35 char's string field.";wm(); os="AGE          : An integer.";wm(); os="POSITION: Upto 25 char's string field.";wm(); os="SALARY   : A two decimal digits numeric field.";wm();wm(); cls="b0p7"; os="REMARK: Data starts at record number 1.";wm(); wm("c");cs="lt1";wm("sl"); ms="See next page to create and write data into a file of this type."; DisplayMessage(0,1,ms); ms="Also, see next page to read back the data stored into the file."; DisplayMessage(1,1,ms); } } } =========================================================================================


Example 4: This example will demonstrate how to create, read from and write into a file of this type. ========================================================================================= public partial class pg4:master1 { // Page class extends master class public override void init() { eri=0; // Set error level to 0. base.init(); } public override void setup() { base.setup(); // Run setup() of master page first //----------------------------------- tb2 Contents ---------------------------------- cns="tb2"; // tb2 is made of 2 cols, 6 rows cs="lb1";cis="Creating New File:";j=0;k=0;ds="w";fns="trb16";cls="m0p7";wm("i"); cs="bt0";cis="Create";j=1;k=0;ds="c";cls="m0g8";fns="trb12";wm("i"); cs="lb2";cis="Writing:";j=0;k=1;ds="w";fns="trb16";cls="b0p7";wm("i"); cs="tf0";cis="Rec Number";j=1;k=1;os="n";ds="c"; jf=1;od=1;cls="S9b7";fns="trb12";wm("i"); cs="tf1";cis="Name";j=0;k=2;ds="c";jf=25;od=35;cls="S9b7";fns="trb12";wm("i"); cs="tf2";cis="Age";j=1;k=2;ds="c";jf=10;od=3;cls="S9b7";fns="trb12";wm("i"); cs="tf3";cis="Position";j=0;k=3;ds="c";jf=25;od=25;cls="S9b7";fns="trb12";wm("i"); cs="tf4";cis="Salary";j=1;k=3;ds="c";jf=10;od=10;cls="S9b7";fns="trb12";wm("i"); cs="bt1";cis="Write Record";j=2;k=4;i=2;ds="c";cls="r0g8";fns="trb12";wm("i"); //----------------------------------- tb3 Contents ---------------------------------- cns="tb3"; // tb3 is made of 2 cols, 4 rows cs="lb3";cis="Reading:";j=0;k=0;i=2;ds="w";fns="trb16";cls="r0p7";wm("i"); cs="tf6";cis="Record Number";j=0;k=1;os="w";ds="w"; jf=1;od=1;cls="b0y5";fns="trb12";wm("i"); cs="cb1";cis="Read all records";j=1;k=1;ds="e";cls="S9p7";fns="trb12";wm("i"); cs="ta1";cis="Text read from File";j=1;k=2;i=2;ds="c"; jf=46;kf=6;cls="b0y5";fns="trbi12";wm("i"); cs="bt2";cis="Read Record(s)";j=0;k=3;i=2;ds="c";cls="r0g8";fns="trb12";wm("i"); } //------------------------------------------------------------------------------------ public override void update() { if(cs.Equals("pl")) { // If event is "Page_Load" setup(); // Execute setup() MakePage(table); // and Make the page PageNumber(4); // Calling master class's method DisplayMessage(0,0,""); // Clear both bottom labels DisplayMessage(1,0,""); } // --------------------------------- WRITING INTO FILE ---------------------------- if(cs.Equals("bt0")) { // If "bt0" clicked js="test1.raf";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained Application.Lock(); // Lock application fm("A"); // check file attributes if(os != " ") {ks="f";fm("D");} // If exists, delete it fs="rf0";rcl=100;ib=true;fm("o"); // open the file as no header file OS[0]="name";OD[0]=35; // 35 character string field OS[1]="age";OD[1]=0.0; // Integer field OS[2]="position";OD[2]=25; // 25 character string field OS[3]="salary";OD[3]=0.2; // numeric field with 2-decimal digits fm("wh"); // Write header. fm("c"); // Close the file. Application.UnLock(); // Unlock application } if(cs.Equals("bt1")) { // If "bt1" clicked" // Var 's Used: ms=Temporarely stores Server response message try { js="test1.raf";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained fs="rf0";fm("o"); // open file and read header information cs="tf0";wm("gu"); // Get "tf0" update (Record Number) try {os=cus;om("ti");rci=o;} // Try to convert to int catch { // If error occured: fm("c"); // Close file DisplayMessage(0,2,"ERROR: Unreadable record number."); fm("c");return; // Display error msg, return. } if (rci<1) { // If user attempts to overrite header DisplayMessage(0,2,"ERROR: Data starts at record 1 for this file type."); fm("c"); // Warn him and return } cs="tf1";wm("gu");OS[0]=cus; // Get Name (string), Assign to OS[0] cs="tf2";wm("gu");os=cus;om("ti");OD[1]=(double)o; // Get Age (numeric), Assign to OD[1] cs="tf3";wm("gu");OS[2]=cus; // Get Position (string), Assign to OS[2] cs="tf4";wm("gu");os=cus;om("td");OD[3]=od; // Gey Salary (numeric), Assign to OD[3] Application.Lock(); fm("w"); // Write record while application locked Application.UnLock(); fm("c"); // Close file. ms+="Record Data Written into RAF.";DisplayMessage(0,1,ms); // Inform user of successful operation } catch { // If any other exception occured DisplayMessage(0,2,"ERROR: "+exp.Message); // during entire process, display its fm("c"); // message to user. } } // --------------------------------- READING DATA BACK ----------------------------- if(cs.Equals("bt2")) { // If "bt2" clicked try { js="test1.raf";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained fs="rf0";fm("o"); // open file and read header information cs="cb1";wm("gu"); // See if "Read all records" checked if (cus.Equals("1")) { // If checked: dnb=false;cus="";rci=0; // Initialize EOF flag, rec number n=1;cus=""; // Start by record # 1,initialize (cus) while (!dnb) { // Do until eof encountered. cus+="RECORD "+n+"\n"; // Add Rec number to (cus) rci=n;fm("r"); // Read one record. cus+=" Name: "+OS[0]+"\n"; // Add each field string value to (cus) cus+=" Age : "+OS[1]+"\n"; cus+=" Position: "+OS[2]+"\n"; cus+=" Salary :"+OS[3]+"\n"; cus+="===================================\n"; n++; // Add seperation line, increment rec number } } else { // Else if "Read all records" unchecked cs="tf6";wm("gu"); // Get tf6 update (Rec number) try {os=cus;om("ti");rci=o;} // Try to convert to int catch { // If error occured: fm("c"); // Close file DisplayMessage(1,2,"ERROR: Unreadable record number."); fm("c");return; // Display error msg, return. } if (rci<1) { // If user attempts to overrite header DisplayMessage(1,2,"ERROR: Data starts at record 1 for this file type."); fm("c");return; // Warn him and return } cus+="RECORD "+rci+"\n"; // Add Rec number to (cus) fm("r"); // Read one record. cus+=" Name: "+OS[0]+"\n"; // Add each field string value to (cus) cus+=" Age : "+OS[1]+"\n"; cus+=" Position: "+OS[2]+"\n"; cus+=" Salary :"+OS[3]+"\n"; cus+="===================================\n"; } cs="ta1";wm("su"); // Display text fm("c"); // Close file DisplayMessage(1,1,"File has been read successfully."); } // Inform user of successful operation catch { // If any other exception occured DisplayMessage(1,2,"ERROR: "+exp.Message); // during entire process, display its fm("c"); // message to user. } } } } =========================================================================================


COMPARING RAF2 FILES WITH DATABASES: ------------------------------------ Databases are suitable for large applications where large amounts of data are necessary to be stored and retrieved using the industry standard SQL query. RAF2 files are much simpler to use and portable which makes them more suitable for small applications. However, no database can beat the RAF2 file in one item, your ability to use your programming skill to do anything you want to your data. The internal structure of the file is fully exposed to you, so at any time, you can access the file, modify your data in any way you like, restructure the file if necessary or repair it no matter how extensive the damage is. Troubleshooting RAF2 files: --------------------------- To access the file for troubleshooting purpose, you need to open it as "no header" file so you can read and modify the header record (record number 0) if necessary. The header record is very simple. This is the header of file "test1.raf" which you have created in the last example: 100|name:35,age:0,position:25,salary:0.2, It starts with the record length followed with "|" then with field setup data. Field setup data is made of the name of each field, a ":", the type code of the field and a "," to seperate it from the next one. Since the header record must be equal in length to the rec length, the header data has been followed with enough null characters to make the record 100 bytes long. Data records are also very simple. Here is the first data record of the file: John Smith.........................xxxxxMachine Operator.........xxxxx................... |<---------- 35 chars ------------>5chrs<------ 25 chars ------->5chrs<----- 30 chars ... The first field of type "string" occupied only 10 bytes of the 35 bytes assigned to it, so a 25 null characters [(char)0] have been added at the end of that field. Same thing happened to the third field. The second and fourth fields are numeric, so each of them occupies 5 bytes. The entire record data occupied 70 bytes, so 30 null characters have been added to make the total equal to the record length. To build your own record, start by creating an empty record made of 100 null chars as follows: rcs=""; // Start by empty record for(int i=0;i<100;i++) rcs+=(char)0; // Add 100 null chars to it Then use method fm("fp") to put each field into record. Here is how to duplicate rec 1: os="John Smith";kd=35;i=0;fm("fp"); // String field, len=35, start char=0 od=25;kd=0;i=36;fm("fp"); // Integer numeric field, start char=36 os="Machine operator";kd=25;i=41;fm("fp");// String field, len=25, start char=41 od=35000.50;kd=0.2;i=66;fm("fp"); // 2 dec numeric field, start char=66 You can then write the record as you do with any RAF without header. To write it as record number 3: fs="rf0";rci=3;fm("w"); To read one field data which a record contains, use method fm("fg") As an example, here is how to read record 2, then read all its fields one by one and display them: js="test.txt";wm("fp"); // Get full path of the file if (fls.Length<1) return; // Return if could not be obtained fs="rf0";rcl=100;ib=true;fm("o"); // Open file as headerless RAF, rec len=100 fs="rf0";rci=2;fm("r"); // Read record kd=35;i=0;fm("fg"); // Read string field (comes assigned to os) kd=0;i=36;fm("fg"); // Read integer field (comes assigned to o) kd=25;i=41;fm("fg"); // Read string field (comes assigned to os) kd=0.2;i=66;fm("fg"); // Read numeric field (comes assigned to od) fm("c"); ========================================================================================= MORE INTERESTING CONTROLS ========================= Before we go further, we need to take a look at some exciting ASP.NET controls. THE LIST BOX: ------------- This control has two modes, "single selection" and "multiple selection". In the "single selection" mode, the user is allowed to select a single item from a list of items while in the "multiple selection" the user can select more than one item from the list. The user can select multiple items by pressing the control button while making his / her selection. The difference in the setup of the two types is in the boolean value (ib). The default is a "single item" ListBox. If you like to set the ListBox as "multiple item" add (ib=true;) to its setup parameters. To get the user selection (or update) of the ListBox call wm("gu") as normal. For a "single selection" ListBox, you'll receive the selected index assigned to the "control update integer" (cui). The index starts by zero. For a "multiple selection" ListBox you'll get the "control update string array" CUS[] containing either "1" or "0" at each of its rows indicating that the item whose index matchs the row order is "selected" or "uneselected" respectively. THE FILE UPLOAD CONTROL: ------------------------ This control is made of a text field and a button labled "Browse". The user either type the path of his local file which he likes to upload to your server into the text field or press the "browse" button so the windows "file dialog" appears, then select the file and click on the "open" button of the file dialog. In the update of the "FileUpload" control, you supply two values: fls = The path of the folder at your server which will receive the file. js = The destination file name. If you like to name it the same as it was at the user's side, supply (js="") which is the default. If the upload operation was successful, (ob=true) will be returned as an indication. ========================================================================================= Example 5: This example will show how to setup and receive events fron "single selection" ListBox, "multiple selection" ListBox and a "FileUpload" control. We are not going to supply (fls) or (js) for the FileUpload control, instead we are going to apologize to the user since we cannot accept uploading files to our server. ========================================================================================= public partial class pg5:master1 { // Page class extends master class public override void init() { eri=0; // Set error level to 0. base.init(); } public override void setup() { base.setup(); // Run setup() of master page first //----------------------------------- tb2 Contents ---------------------------------- cns="tb2"; // tb2 is made of 2 cols, 3 rows cs="lb0";cis="Single Item";j=0;k=0;ds="s";fns="trb12";cls="r0p7";wm("i"); cs="lb1";cis="Multiple Item";j=1;k=0;ds="s";fns="trb12";cls="r0p7";wm("i"); cs="ls0";ib=false;j=0;k=1;cls="S9p7";fns="trb12";ds="c"; CIS=new string[] {"Item 0","Item 1","Item 2","Item 3"};wm("i"); cs="ls1";ib=true;j=1;k=1;cls="S9y7";fns="trb12";ds="c"; CIS=new string[] {"Item 0","Item 1","Item 2","Item 3"};wm("i"); cs="bt0";cis="Submit";j=0;k=2;ds="c";cls="r0g8";fns="trb12";wm("i"); cs="bt1";cis="Submit";j=1;k=2;ds="c";cls="r0g8";fns="trb12";wm("i"); //----------------------------------- tb3 Contents ---------------------------------- cns="tb3"; // tb3 is made of 1 col, 1 row cs="fu0";cis="Full Path of the file to be uploaded";j=k=0;ds="c"; lf=300;of=30;jd=3;fns="trb12";cls="b0y0";wm("i"); cs="bt2";cis="Upload File";j=0;k=1;ds="c";cls="r0g8";fns="trb12";wm("i"); } //------------------------------------------------------------------------------------ public override void update() { if(cs.Equals("pl")) { // If event is "Page_Load" setup(); // Execute setup() MakePage(table); // and Make the page DisplayMessage(0,0,""); // Erase old messages DisplayMessage(1,0,""); PageNumber(5); // Calling master class's method } // to display this page's number // ---------------------------- Single Item List Box ------------------------------ if(cs.Equals("bt0")) { // If event is: "bt0 clicked" cs="ls0";wm("gu"); // Get ls0 update (cui) & display it DisplayMessage(0,1,"Selected Index (cui) = "+cui); } // --------------------------- Multiple Item List Box ----------------------------- if(cs.Equals("bt1")) { // If event is: "bt1 clicked" cs="ls1";wm("gu"); // Get ls1 update (CUS[]) cis="Item states (CUS[ ]) :"; // Display all rows of CUS[] for (int n=0;n<4;n++) cis+=" ^nbsp ^nbsp ^nbsp "+CUS[n]; DisplayMessage(0,1,cis); } // ----------------------------- File Upload Control ------------------------------ if(cs.Equals("bt2")) { // If event is: "bt2 clicked" // If you accept the upload, keep the following 3 lines: // supply destination folder, file cs="fu0";js="";fls="c:\\inetpub\\wwwroot\\WPDII";wm("gu"); if (ob) DisplayMessage(1,1,"Thank You. Your file has been uploaded."); else DisplayMessage(1,2,"ERROR: You must enter a valid path for your file."); // Check (ob), send msg accordingly // If you do not accept the upload replace the 3 lines with: DisplayMessage(1,2,"Sorry this option has been disabled for security reason."); // Apologize to user } } } =========================================================================================


THE IMAGE BUTTON CONTROL This control displays an image. When the user clicks anywhere within the image borders, the control sends the coordinates of the point clicked at with respect to the image's top left corner assigned to (j,k). If you remeber what we did when we drew the "Ace of hearts", you know that this control could have made our job easier and more accurate. We used the "GeneralPath" to draw the heart's symbol; and to do so, we sketched the symbol on paper and obtained the coordinates of some points on its outline. We could have done better if we have scanned a real card and used the resulting image with a control of this type to get the coordinates. The only problem which we could have met is that we use different coordinates in our drawings. We use cartesian and polar coordinates relative to the center of the object instead of its top left corner. Let us have an example which makes the necessary adjustments so we can use it for such task. ========================================================================================= Example 6: On the left side, we are going to create an ImageButton control and display the coordinates received as is. On the right side, we are going to move the center point to any postion the user wants and to adjust the coordinates received from the control accordingly. Furthermore, we are going to display the coordinates translated to any coordinate system the user wants. The image used on the left side will be "flower.jpg". On the right side we are going to create a dynamic image which shows the (Y,X) axis lines and the 4 quadrants. ========================================================================================= Let us start by creating the image of the right side. Coordinates Image Class: ------------------------ public partial class coordinates:pasp { public override void init() { base.init(); } public override void update() { if(!cs.Equals("pl")) return; // Return if not PageLoad event lf=370;of=200;wm("bo"); // Open new bitmap operation using // bitmap of size 370 X 200 pixels cls="g7";gm("ec"); // Paint background mint green jf=-172;kf=0;lf=172;of=0;gm("cld"); // Draw line bet. points (-172,0) & (172,0) jf=0;kf=86;lf=0;of=-86;gm("cld"); // Draw line bet. points (0,86) & (0,-86) fns="trb14"; // Select font os="X";jf=179;kf=0;gm("ctf"); // Draw letter "X" beside X-axis os="Y";jf=0;kf=94;gm("ctf"); // Draw letter "Y" above Y-axis cls="b0";gm("sps"); // Change to blue color ks="X_s";wm("vg");if(os.Length<1) os="0";// Get X-Coord value stored as session var om("ti"); // If unavailable, consider it (0), cnvert to j=o-370/2;x=j; // int., adjust to make it relative to center ks="Y_s";wm("vg");if(os.Length<1) os="0";// Get Y-Coord value stored as session var om("ti"); // If unavailable, consider it (0), cnvert to k=200/2-o; // int., adjust to make it relative to center jf=(float)x;kf=(float)k; // Convert both values to float lf=of=6;gm("ced"); // Draw a small circle where the point is wm("bc"); // Close bitmap operation. } } CLASS pg6: ---------- public partial class pg6:master1 { public override void init() { eri=0; base.init(); } public override void setup() { base.setup(); // Run setup() of master page first //----------------------------------- tb2 Contents ---------------------------------- cns="tb2"; // tb2 is made of 1 col, 1 row cs="ib0";cis="Click anywhere inside image";j=k=0;ds="c"; ims="../images/flower.jpg";fns="trb12";cls="r0p7";wm("i"); //----------------------------------- tb3 Contents ---------------------------------- cns="tb3"; // tb3 is made of 1 col, 2 rows cs="ib1";cis="";j=0;k=0;i=1;ds="c";lf=370;of=200;ims="coordinates.aspx";wm("i"); cs="ch0";j=0;k=1;ds="c";cls="S9g7";fns="trb12";CIS=new string[] {"Set Center point", "Cartesian coord, relative to Top left corner", "Cartesian coord, relative to center","Polar coord, relative to center"};wm("i"); } //------------------------------------------------------------------------------------ public override void update() { if(cs.Equals("pl")) { // If event is "Page_Load" setup(); // Execute setup() MakePage(table); // and Make the page DisplayMessage(0,0,""); // No msg at left ms="TO START: Select 'Set Center Point' then Click on Drawing's Center point."; DisplayMessage(1,0,ms); // Instruction msg at right PageNumber(6); // Calling master class's method // to display this page's number ks="cpx_s";wm("vg"); // Check to see if center point coor's // have been set. Use x-coor as sample if(!IsPostBack || os.Length<1) { // If first trip to retrieve page or ks="cpx_s";os="0";wm("vs"); // center point not set, save default ks="cpy_s";os="0";wm("vs"); // values for both center point and ks="X_s";os="0";wm("vs"); // selected point coord's as session ks="Y_s";os="0";wm("vs"); // var's. } } if(cs.Equals("ib0")) { // If event is: "bt0 clicked" cis="You clicked at coordinates ("+j+","+k+")"; cs="lb00";wm("sl"); // Display coord's received. } if(cs.Equals("ib1")) { // If event is: "bt1 clicked" // Local Var's used: x,y = Coordinates received from user // cpx,cpy = Center point's coordinates // r = Radius // ad = Angle between radius and X-axis // Session Var's used: X_s, Y_s = Coordinates of point selected by user. // cpx_s, cpy_s = Center point coordinates. x=j;y=k; // Copy coord's received to (x,y) cs="ch0";wm("gu"); // Get user's selection if (cui==0) { // If "Set center point" selected: ks="cpx_s";os=""+x;wm("vs"); // Save received coord's into both ks="cpy_s";os=""+y;wm("vs"); // center point and selected point ks="X_s";os=""+x;wm("vs"); // (x,y) session variables ks="Y_s";os=""+y;wm("vs"); ms="Center Point Set. Now, Select Coordinates type then click at any location."; DisplayMessage(1,0,ms); // Display message and return return; } ks="X_s";os=""+x;wm("vs"); // If any other selection made, assign ks="Y_s";os=""+y;wm("vs"); // the selected point coord's received // to the var's x,y. if (cui==1) { // If "Cartesian,top-left" selected: DisplayMessage(1,1,"You clicked at coordinates ("+x+","+y+")"); return; // Display coord's without adjustment } int cpx,cpy; // Define int var's (cpx,cpy) ks="cpx_s";wm("vg");if(os.Length<1) cpx=0; // Get center point coord's session else {om("ti");cpx=o;x=x-cpx;} // var's, convert to int and copy to ks="cpy_s";wm("vg");if(os.Length<1) cpy=0; // (cpx,cpy). Assign 0's if not found else {om("ti");cpy=o;y=cpy-y;} // Adjust selected point coord's (x,y) // by cpx,cpy to be relative to center if (cpx==0 && cpy==0) { // If both cpx, cpy found to be zeros ms="Please select 'Set Center Point' first, then Click on Drawing's Center point."; DisplayMessage(1,2,ms); // Display this message and return. return; } if (cui==2) { // If "Cartesian, center" selected: DisplayMessage(1,1,"You clicked at coordinates ("+x+","+y+")"); return; // Display (x,y) which have already } // been made relative to center. else if (cui==3) { // If "Polar, center" selected: jd=2;od=(double)x;um("mp");xd=od; // Calculate x^2 jd=2;od=(double)y;um("mp");yd=od; // Calculate y^2 od=xd+yd;um("ms");r=(int)od; // Radius r=Square Root of (x^2 + y^2) od=(double)y/(double)x;js="atan";um("mt"); // Get theta = atan(y/x) ad=od; // assign result to (ad) js="pi";um("mt");ad=ad*180/od;a=(int)ad; // Get "PI". Convert (ad) to degrees if (x<0) a=a+180;else if(y<0) a=a+360; // Adjust (ad) for point's quadrant. DisplayMessage(1,1,"You clicked at Radius of "+r+" and Angle of "+a); return; // Display Polar coordinates. } } } } =========================================================================================


USING SCROLLBARS: ================= Sometimes we like to display a large size item like an entire file or web page into a smaller size container. The "Table" has been chosen to be the container we use since it can be divided into cells of any sizes which allow us to postion items precisely into the page. Unfortunately, we cannot install scrollbars into table cells. So the solution is to install "Panel" controls into the table cells and install scroll bars into the panels. The panels can then be used as containers of larger size items. You cannot place controls into a panel at the positions you choose. You add the controls to the panel and the panel sets them wherever it sees necessary. This can cause some layout problems especially when you try to install several controls which contain labels. The label to control alignment sometimes gets disorganized. All the panels PC# creates for you contain scrollbars by default which appear only when the panel contents exceed its size. We are going to see examples on scrollbars, but before that, we need to discuss how to display text into a web page in more details. ========================================================================================= MORE ABOUT TEXT DISPLAY ======================= Method wm() has been designed to display text on a web page in about the same manner method tm() displays text on the text output device of a desktop application. The most common text display modes are the same, however method wm() provides more options. Here are all the modes available: Pre-formatted text: ------------------- IMPORTANT REMARK: We have intentially replaced the angled brackets of html tags with square brackets and the ampersend sign with '^' character in order to force your browser to display the tags instead of executing them. HTML does not understand spaces or line feeds. It only understands its tags. The space character to html is representrd by "^nbsp" and the new line character is represented by [br]. However if you call mode "l", it adds the tag [pre] which allows all the text which you add next to be kept as is with all the spaces and line feeds it contains. Mode "lc" adds the tag [/pre] which terminates this feature. l = Leave coming text as is. It adds [pre] tag. lc = Close this mode. It adds [/pre] tag. String Display: --------------- There are 3 modes for string display. dl (default) Display the string assigned to (os) then move cursor to next line. d or dw Display the string assigned to (os) and keep cursor at same line. dp Create a new paragraph, then display the string in (os) and there are other parameters which can be supplied before calling the method at any of the 3 modes: cls The foreground color code to switch to before displaying the string. fns The font code to switch to before displaying the string. ds The direction (or justification) of the text it could be equal to: "w" Meaning "west" or "left". "e" Meaning "east" or "right". "c" Meaning "center". j Number of characters to indent the line with. REMARKS: (1) After the method executes the call, it will reset (j), (os) and keep (cls),(fns) and (ds) the same. So those three parameters will be used for all the display you do next until you supply new values for them. (2) Mode "dl" is the default. So wm("dl") and wm() mean the same thing. (3) Notice that in mode "dl", a line feed is added after the line is displayed, while in mode "dp", moving to a new paragraph happens before the line is displayed. (4) The two direction assignments (ds="w") and (ds="e") are effective if supplied at mode "dp" only. They will do nothing if supplied at the other two modes. The assignment (ds="c") is effective at all three modes. (5) If mode "l" was selected before calling modes "d", "dl" or "dp", all three will do the same since the html will not add line feeds or paragraphs at this mode. Local Text/html File display: ----------------------------- df = Read the local file whose name is assigned to (fls) and display all the text it contains. If it was an html file, display will start immediately after the [body] html tag and stop immediately before the [/body] tag. REMARK: You may like to use the mode "l" before the display of text files in order to keep their text alignment as is. External web page display: -------------------------- du = Read the external web page whose URL is assigned to (urs) and display all its contents. Display will start immediately after the [body] html tag and stop immediately before the [/body] tag. Hyperlink display (anchor): --------------------------- a = Display the string supplied in (os) as a clickable text. When clicked on, load the page whose address is assigned to (urs) (cls,fns,ds and j) can also be supplied as parameters for the display. If instead of assigning a web address to (urs), you assigned your e-mail address, when the user clicks on the text, his "send e-mail message" window will appear with the "send to" box filled in with your e-mail address. Table display: -------------- to Open new table. You may supply the following parameters when opening a table: i = Border width in pixels o = Tables width as a percentage of page width cls= Table's default color code. fns= Table's default font code. th Table header information. Will be described shortly. td Information for one row of data. Parameters used for modes "th" and "td" are identical. They are: OS[] = Header names or data row containing all column data. LS[] = Directions. valuse of (ds) for all columns. JS[] = Font codes for all columns. KS[] = Color codes for all columns. I[] = Number of columns occupied if more than one. O[] = Number of rows occupied if more than one. Example: If first data item should occupy two columns, assign data to OS[0], '2' to I[0] and assign no data to any parameter for column 1. tc Close table. WHAT DOES DISPLAY MEAN? ----------------------- Displaying something on a web page means different things depending on the type of file we are working on. (1) If we are working on a file which will be extended by an "aspx" web page file, it means that all the text and html tags generated are concatenated and loaded into the string (cis). The string (cis) can be the label of one of several controls like text field, text area, label, image, calendar, .. etc or can be the full body of a "literal control". All the text contained into the label will be displayed by the browser when it receives the page. (2) If we are working on an html file (will see an example on that later), it means writing all the data into the file. Contents of the html file will be displayed by the browser which executes the html page. Loading text/html into (cis): ----------------------------- To perform this operation properly, you need to start it by calling wm("o"). This will initialize all flags associated with html tag creation so PC# can maintain a good record of all tags which your selections will create. It also initializes (cis). At the end of the operation, you should call wm("c"), so closing tags will be generated for all the open ones. It is good to note that the specific tag closing jobs performed by modes "lc" and "tc" can also be done by the general tag closing mode "c". So, mode "c" can replace all other tag closing modes. STEPS OF DISPLAYING TEXT INTO A WEB PAGE: ----------------------------------------- (1) If the text to be displayed exceeds in size the table cell which should contain it, install a panel into the table cell of equal size to the cell and use the panel as a container for the label or literal control which will be created in the next step. (2) Install a label control or literal control into the container. The container could be either a table cell or a panel installed into the table cell as discussed in preceeding step. (3) Call wm(o) to open new text/html loading operation. (4) If you are loading a text which contains spacing and/or line feeds which you like to keep or if you are loading a text file, call wm("l") to keep text formatting as is. (5) You may call wm("d"), wm("dl") or wm("dp") to display text, call wm("df") to display a local file or call wm("du") to display an external web page. (6) You may also display any number of tables and hyper links. (7) At the end, call wm("c") to close all open tags. (8) Call wm("sl") supplying the keyname of the control which you like (cis) to be its label. What other html components can be installed? ============================================ Loading html into the text string (cis) is not limited to ordinary text display, tables, hypertext and files. There are two more components which you can install which are: (1) An image control. (2) A label control. Probably, you are wondering what can we get by installing a label control if we can display all kinds of text directly. The value will become clear when we get into "Animation". Both controls can be moved using JavaScript accross the page. Furthermore, the label control can be made with a transparent background, a feature which is also important in Animation. We'll explain the installation and use of these two controls when we get into JavaScript and Animation. ========================================================================================= Example 7: On the left side, we are going to demonstrate the use of scrollbars. We are going to install a panel, then install 4 images which require more space than the panel can provide. On the right side, we'll display a text file which contains a table. This requires the use of mode "l" in order to keep the table alignment. It also requires scrollbars. ========================================================================================= public partial class pg7:master1 { public override void init() { eri=0; base.init(); } public override void setup() { base.setup(); // Run setup() of master page first //----------------------------------- tb2 Contents ---------------------------------- cns="tb2"; // tb2 is made of 1 col, 1 row cs="pn0";j=0;k=0;ds="c";lf=160;of=200;fns="trb12";cls="r0g7";wm("i"); // Install a panel into the table //----------------------------------- pn0 Contents ---------------------------------- cns="pn0"; // Install 4 images into the panel cs="im0";ims="..\\images\\flower.jpg";wm("i"); cs="im1";ims="..\\images\\flower.jpg";wm("i"); cs="im2";ims="..\\images\\flower.jpg";wm("i"); cs="im3";ims="..\\images\\flower.jpg";wm("i"); //----------------------------------- tb3 Contents ---------------------------------- cns="tb3"; // tb3 is made of 1 col, 1 row cs="pn1";j=0;k=0;ds="c";lf=365;of=235;fns="trb12";cls="S9g7";wm("i"); // Install a panel into the table //----------------------------------- pn1 Contents ---------------------------------- cns="pn1"; // Install a literal control into pn1 cs="lt2";j=0;k=0;i=1;ds="w";cls="S9g7";fns="trb12";wm("i"); } //------------------------------------------------------------------------------------ public override void update() { if(cs.Equals("pl")) { // If event is "Page_Load" setup(); // Execute setup() MakePage(table); // and Make the page PageNumber(7); // Calling master class's method // to display this page's number DisplayMessage(0,0,"Using Scroll Bars"); // Display messages to user DisplayMessage(1,0,"Displaying a text file"); wm("o"); // Open new html loading operation wm("l"); // Leave text unchanged fls="div.txt";wm("df"); // Load the text file "div.txt" wm("c"); // Cloase loading operation. cs="lt2";wm("sl"); // Set (lt2)'s label } } } ========================================================================================= Can you run a Java Applet within an ASP.NET page? ================================================= Yes definitely. All you need is the Java Class file and a small HTML file which makes the applet run. Let us assume that you want to run your Java applet into (lt2) of last example and the width and height of the applet are (365,235) to match the containing panel's size Your HTML file could be: IMPORTANT: The space at the beginning of each HTML tag has been added in order to make your browser disply the code instead of attempting to execute it. You must delete the spaces in your actual HTML file. < HTML>< TITLE>My Applet< /TITLE> < BODY> < APPLET CODE="MyApplet.class" WIDTH=365 HEIGHT=235>< /APPLET> < /BODY> < HTML> Save that file then use method wm("df") to load it in place of file "div.txt". Can you insert a Google map into your ASP.NET page? =================================================== Yes. We are going to assume the following: (1) You want to place your map into (lt2) of last example. (2) The wanted width and height for the map are 365,235 pixels to match the containing panel's size. (3) Coordinates at map's center are 34.040359,-118.269400 which are for Los Angeles Convention Center. (4) The Zoom amount wanted is 18 which is for a large scale map. Using smaller numbers reduces scale. Copy the html code below to notepad. Modify it as you like then save it into file named "mymap.html". Use method wm("df") to load it in place of file "div.txt". IMPORTANT: The space at the beginning of each HTML tag has been added in order to make your browser disply the code instead of attempting to execute it. You must delete the spaces in your actual HTML file. < HTML>< TITLE>My Map< /TITLE> < BODY> < div id="map">< /div> < style> #map { width: 365px; height: 235px; } < /style> < script src="https://maps.googleapis.com/maps/api/js">< /script> < script> function setmap() { var element = document.getElementById('map'); var setups = { center: new google.maps.LatLng(34.040359,-118.269400), zoom: 18, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(element, setups) } google.maps.event.addDomListener(window, 'load', setmap); < /script>< /BODY> < /HTML> =========================================================================================


Example 8: In this example, the user will enter a web page address into a text field. The page represented by the address will be retrieved and displayed. ========================================================================================= public partial class pg8:master1 { public override void init() { eri=0; base.init(); } public override void setup() { base.setup(); // Run setup() of master page first //----------------------------------- tb2 Contents ---------------------------------- cns="tb2"; // tb2 is made of 1 col, 3 rows cs="lb0";cis="Please Enter a full address like http://www.microsoft.com"; j=0;k=0;ds="c";cls="r0p7";fns="trb12";wm("i"); cs="tf0";cis="Enter the web address of any page you like"; j=0;k=1;ds="c";jf=20;cls="b0y0";fns="trb12";wm("i"); cs="bt0";cis="Display Page";j=0;k=2;ds="c";cls="r0g8";fns="trb12";wm("i"); //----------------------------------- tb3 Contents ---------------------------------- cns="tb3"; // tb3 is made of 1 col, 1 row cs="pn1";j=0;k=0;ds="c";lf=365;of=235;fns="trb12";cls="S9g7";wm("i"); // Install a panel into the table //----------------------------------- pn1 Contents ---------------------------------- cns="pn1"; // Install a literal control into pn1 cs="lt2";j=0;k=0;i=1;ds="w";cls="S9g7";fns="trb12";wm("i"); } //------------------------------------------------------------------------------------ public override void update() { if(cs.Equals("pl")) { // If event is "Page_Load" setup(); // Execute setup() MakePage(table); // and Make the page PageNumber(8); // Calling master class's method // to display this page's number ms="Please be patient. Web Page retrieval may take a long time."; DisplayMessage(1,0,ms); // Display message to user } if(cs.Equals("bt0")) { // If event is "bt0" clicked cs="tf0";wm("gu"); // Get tf0's update (in cus) wm("o"); // Open new html/txt loading operation urs=cus;wm("du"); // Display the page wm("c"); // Close loading operation cs="lt2";wm("sl"); // install (cis) into literal control } } } =========================================================================================


CREATING HTML FILES =================== You can easily create an html file which contains text, hyperlinks, tables, .. etc without knowing anything about html. You have already known how to do all that in an asp.net page, this time we are going to write all the dynamically generated html directly into an html file which is completely independant from asp.net. When we have been loading the html into the string (cis), the first step was to open an html loading operation by calling wm("o"). This is the only part of your code which needs to be changed, you replace it with calling wm("h") The rest of your code should be kept the same. However, calling wm("h") requires supplying some parameters which are: fls The name of the html file which you like to create and load the html into. os The html page title which can be optional. cls The foreground - Background combined color code for the page. Example: cls="S9s9" ks Another combined color code for hyperlinks. The first color is for the link text before the page has been visited and the second one is for the link text after the page has been visited. ims The file name of an image which you may like to use as a background for the page. All parameters are optional except the html file name (fls). The last step is calling wm("c") as usual. Method wm() at mode "c", in addition to closing all open html tags, will close the html file too. ***************************************************************************************** SORRY. Due to tighter security measures, execution of this file under Windows 10 environment may fail and generates an error message when it tries to save file x.html into your system. ***************************************************************************************** ========================================================================================= Example 9: We are going to create the html file "x.html" and load it with html then close it. The file can then be requested and executed by any browser, however, we are also going to execute it at the right side of the same page. To make this example more useful, we are going to create a more complex table with multi- headers and with some data occupying more than one column into the html file. ========================================================================================= public partial class pg9:master1 { public override void init() { eri=0; base.init(); } public override void setup() { base.setup(); // Run setup() of master page first //----------------------------------- tb2 Contents ---------------------------------- cns="tb2"; // tb2 is made of 1 col, 1 row cs="lt1";j=0;k=0;i=1;ds="w";cls="S9g7";fns="trb12";wm("i"); //----------------------------------- tb3 Contents ---------------------------------- cns="tb3"; // tb3 is made of 1 col, 1 row cs="pn1";j=0;k=0;ds="c";lf=365;of=235;fns="trb12";cls="S9y7";wm("i"); // Install a panel into the table //----------------------------------- pn1 Contents ---------------------------------- cns="pn1"; // Install a literal control into pn1 cs="lt2";j=0;k=0;i=1;ds="w";cls="S9y8";fns="trb12";wm("i"); } //------------------------------------------------------------------------------------ public override void update() { if(cs.Equals("pl")) { // If event is "Page_Load" setup(); // Execute setup() MakePage(table); // and Make the page PageNumber(9); // Calling master class's method // to display this page's number // -------------------- Open the html file and load it with html -------------------- fls="x.html";cls="S9y8";ks="b0m0"; // supply file name, page fg/bg color, os="Dynamic HTML"; // link uvstd/vstd colors, page title wm("h"); // and open new html filing operation ds="c";fns="trb16";cls="r0";wm(); // change color, font, skip one line os="Dynamically generated html";wm(); // Display this line wm(); // Skip one line i=5;o=70;wm("to"); // Open table, border=5 pxls, // width=70% of page width OS[0]="AVAILABLE PUBLICATIONS";I[0]=3; // 1st header occupies all 3 col's JS[0]="trb18";KS[0]="R0"; // font and color for header wm("th"); // Make the header OS[0]="Publication Name";JS[0]="trb16";KS[0]="B0"; // 1st item of 2nd hder, span=1 col OS[1]="Description";I[1]=2;JS[1]="trb16";KS[1]="B0"; wm("th"); // 2nd item of 2nd hdr, span=2 col OS[0]="Financial Planner";LS[0]="w"; // 2 item data which matches header OS[1]="Provides general investment analysis";I[1]=2;LS[1]="w"; wm("td"); OS[0]="Mutual Fund Analyzer";LS[0]="w"; // 2 item data which matches header OS[1]="Compares Open End Mutual Funds";I[1]=2;LS[1]="w"; wm("td"); OS[0]="Publication Name";JS[0]="trb16";KS[0]="B0"; // 1st item, 3rd hdr, col span=1 OS[1]="One Year Subscription";JS[1]="trb16";KS[1]="B0"; // 2nd item, 3rd hdr, col span=1 OS[2]="Two Years Subscription";JS[2]="trb16";KS[2]="B0"; wm("th"); // 3rd item, 3rd hdr, col span=1 OS[0]="Financial Planner";LS[0]="w"; // 3 item data, matches header OS[1]="75.00";LS[1]="e"; OS[2]="125.00";LS[2]="e"; wm("td"); OS[0]="Mutual Fund Analyzer";LS[0]="w"; // 3 item data, matches header OS[1]="150.00";LS[1]="e"; OS[2]="220.00";LS[2]="e"; wm("td"); wm("tc"); // close table wm(); // Skip one line os="Click here";urs="http://www.sears.com";wm("a"); // Create hyperlink wm("c"); // Close html filing operation // -------------------------- Display text on left side -------------------------- wm("o"); // Open html loading operation cls="r0";fns="trb16";ds="c"; // Change color to red, dir=center os="Generating HTML Pages dynamically";wm(); // Display this line cls="bo";ds="w";fns="trb12"; // Change to blue, dir=left os="This asp.net page has just done the following:";wm("dp");wm(); // Display this line, skip one line cls="S9";fns="trb11"; // Change to black color j=8;os="(1) Created the html file 'x.html' and opened it for write.";wm(); j=8;os="(2) Added the html title (Dynamic HTML) to the page.";wm(); j=8;os="(3) Added html code to display a line of text.";wm(); j=8;os="(4) Added html code to display a table.";wm(); j=8;os="(5) Added html code to display a hyperlink.";wm(); j=8;os="(6) Closed the file.";wm(); j=8;os="(7) Executed the file at the right section of this page.";wm(); wm("c"); // Display lines, close loading oper. cs="lt1";wm("sl"); // Install (cis) into (lt1) // ------------------------------ Execute html file ------------------------------- wm("o"); // Open new html/txt loading operation fls="x.html";wm("df"); // Display the page wm("c"); // Close loading operation cs="lt2";wm("sl"); // install (cis) into (lt2) } } } =========================================================================================


Drawing your own Web Controls: ============================== You can create impressive websites by drawing your own Web Controls. You can draw a Button, a Text Field, a Lst Box,.. almost any control can be replaced with drawing. You can use image files or you can use dynamic drawings. In either case, you need to supply the image to the web page as an Image Button. Example 6 showed you how to use an image button. After creating your controls, you need to use the same code we used in example 6 to know the borders of each control, so you can set the conditions for clicking on it. The code was as follows: if(cs.Equals("ib0")) { // If event is: "ib0 clicked" cis="You clicked at coordinates ("+j+","+k+")"; cs="lb00";wm("sl"); // Display coord's received. } As you already know, if your drawing is going to be dynamic, you can either make it a seperate class or you can write it into a method of the main class which can be accessed using query strings. We'll be using this type in the next example. =============================================================================================== Example 10: We are going to repeat two examples of WPDI replacing their web controls with dynamically generated ones. The first example is the one which draws a piece of jewelry with selectable pearl colors. The second example is the one which demonstrates 4 kinds of 3D effects. =============================================================================================== public partial class pg10:master1 { // Class extends master1 as uasual string block=""; public override void init() { base.init(); // Initialize pasp } public override void setup() { wm("ir"); // Reset all installation par's. Good for safety // since wm("rq") could have changed o-based ones. base.setup(); // Execute setup() of master1 class //-------------------------------------- tb2 Contents -------------------------------------- cns="tb2"; // tb2 is made of 2 cols, 2 rows cs="lb0";cis="Drawing your own controls";i=2;ds="c";cls="r0p7";fns="trb16";wm("i"); cs="ib0";j=0;k=1;cis="";ds="c"; // "SelectPearl" ImageButton installation. Included ims="pg10.aspx?block=1";wm("i"); // as a method which executes with par (block=1) cs="im1";cis="";j=1;k=1;ds="c";lf=of=0; // "Jewel" dynamic image control. Included ims="pg10.aspx?block=2";wm("i"); // as a method which executes with par (block=2) //------------------------------------- tb3 Contents --------------------------------------- cns="tb3"; // tb3 is made of 2 cols, 2 rows cs="lb1";cis="and handling their events";i=2;ds="c";cls="r0p7";fns="trb16";wm("i"); cs="ib1";cis="";j=0;k=1;ds="c";lf=0;of=0; // "SelectEffect" ImageButton installation.Included ims="pg10.aspx?block=3";wm("i"); // as a method which executes with par (block=3) cs="im2";j=1;k=1;ds="c";lf=of=0; // "Effects" dynamic image control. Included ims="pg10.aspx?block=4";wm("i"); // as a method which executes with par (block=4) } //------------------------------------------------------------------------------------------- public override void update() { //--------------------------------------- Page Load ----------------------------------------- if(cs.Equals("pl")) { // If event is "Page_Load" ks="block";wm("rq");block=OS[0]; if (block.Equals("1")) {SelectPearl();return;} if (block.Equals("2")) {Jewel();return;} if (block.Equals("3")) {SelectEffect();return;} if (block.Equals("4")) {Effects();return;} setup(); // Execute setup() if(!IsPostBack) { // If first trip to retrieve page ks="PearlColor_s";os="p0";wm("vs"); // Save initial color code ("p0") // as a session variable ks="effect_s";os=" ";wm("vs"); // Also save default "Effects" } // string as a session variable MakePage(table); // Make the page to be sent PageNumber(10); // Call master1 class's method to } // set page number. //--------------------------------------- ib0 Click ---------------------------------------- if(cs.Equals("ib0")) { // If user clicked within (ib0)'s boders: // var's used: x,y = Pearl center coordinates. // PearlColor_s = Selected pearl color as session variable. for(n=0;n<8;n++) { // Scan location data of all pearls x=19; // X-Coordinate of each pearl center if(n%2!=0) x=79; // =19 when (n) is even and 79 when odd. y=60+(int)(n/2)*40; // Y-Coordinate of each pearl center if(j>(x-12) && j<(x+12) && k>(y-12) && k<(y+12)) break; // Exit loop if clicked within one pearl } // borders. os="r0 G2 b0 S5 C2 O2 p0 Y2 p0".Substring(n*3,2); // Get color code of selected pearl. ks="PearlColor_s";wm("vs"); // Save selected color as a session var. } //-------------------------------------- ib1 Click ---------------------------------------- if(cs.Equals("ib1")) { // If user clicked within (ib1)'s boders: // var's used: effect_s = Selected 3D effect as session variable. if(j<1 || j>207 || k<2 || k>199) return; // If clicked beyond selection areas, exit. if (k<58) os="RGP"; // Make os="RGP" if clicked at it. else if (k<105) os="LGP"; // Else, Make os="LGP" if clicked at it. else if (k<154) os="SER"; // Else, Make os="SER" if clicked at it. else os="SED"; // Else, Make os="SED" if clicked at it. ks="effect_s";wm("vs"); // of item selected. Save the string (os) } } //--------------------------------------- SelectPearl ------------------------------------- void SelectPearl() { lf=100;kf=224;wm("bo"); // Open new bitmap operation using // bitmap of size 100 X 224 pixels cls="p7";gm("ec"); // Paint background same as page fns="trb18";cls="S9";gm("sps"); // Set font and color for title. os="Select";kf=90;gm("ctf"); // Display 1st line of title. os="A Pearl";kf=70;gm("ctf"); // Display 2nd line of title. float yf=-80; // Y-Coordinate of first row of pearls. for(n=0;n<8;n++) { // Scan all pearl order numbers cls="r0 G2 b0 S5 C2 O2 p0 Y2 ".Substring(n*3,2); // Get color code for each one. lf=of=25;gm("ce"); // Create a circle at bitmap's center (pearl) jf=-30; // X-Coordinate of of pearls with even order no's. if (n%2!=0) jf=30; // X-Coordinate of of pearls with odd order no's. if (n%2==0) yf+=40; // Y-Coordinate of each pearl. Notice that each kf=yf; // 2 pearls have the same Y-coordinate. ks="r";gm("grs"); // Render pearl using 3D effects-reflection. } wm("bc"); // Close bitmap operation. } //---------------------------- Generate Jewel Image (No Change) ----------------------------- void Jewel() { lf=of=200;wm("bo"); // Open new bitmap operation using bitmap of // size 200 X 200 pixels. cls="p7";gm("ec"); // Paint background with same color as page lf=of=170;gm("ce"); // Create the circular gold plate cls="o5y5";gm("spl"); // Prepare linear gradient brush for it gm("grf"); // then render-fill the gold plate. lf=6;of=50;gm("c="); // Create hexagon shape object at center. cls="r0";ks="r";gm("grs"); // Draw the object using sp effects-refl at jf=45;cls="b0";ks="r";gm("grs"); // center in red, then repeat 6 times using jf=-45;cls="b0";ks="r";gm("grs"); // different colors and different locations jf=22;kf=40;cls="g0";ks="r";gm("grs"); jf=-22;kf=40;cls="m0";ks="r";gm("grs"); jf=22;kf=-40;cls="m0";ks="r";gm("grs"); jf=-22;kf=-40;cls="g0";ks="r";gm("grs"); lf=of=25;gm("ce"); // Create a circle at center (pearl) ks="PearlColor_s";wm("vg"); // ** get color code stored as session var if(os.Length<2) os="p0"; // ** If not valid use pink color as default cls=os; // ** Assign code to (cls) for (int x=0;x<20;x++) { // Draw it 20 times using sp effects-refl. jf=80;kf=18*x;kb=true; // at locations around the plate. Polar ks="r";gm("grs"); // coord's are used for specifying locations } wm("bc"); // Close bitmap operation } //--------------------------------------- SelectEffect ------------------------------------- void SelectEffect() { lf=208;kf=224;wm("bo"); // Open new bitmap operation using // bitmap of size 208 X 224 pixels cls="p7";gm("ec"); // Paint background same as page // Create each selection rectangle at bitmap's center, then move it to correct position while // applying 3D Effects-Depth. lf=180;of=30;gm("cr"); // Special Effects - depth jf=0;kf=-72;ks="d";id=40;ad=45;cls="s5S5";gm("grs"); lf=180;of=30;gm("cr"); // Special Effects - reflection kf=-24;ks="d";id=40;ad=45;cls="p7p0";gm("grs"); lf=180;of=30;gm("cr"); // Linear Gradient Paint kf=24;ks="d";id=40;ad=45;cls="b7b0";gm("grs"); lf=180;of=30;gm("cr"); // Radial Gradient Paint kf=72;ks="d";id=40;ad=45;cls="r7r0";gm("grs"); // Display text of each selectable rectangle at its center. cls="s9";gm("sps");fns="trb15"; os="Radial Gradient Paint";jf=8;kf=60;gm("ctf"); os="Linear Gradient Paint";jf=8;kf=12;gm("ctf"); os=" Special Effects - Reflection";jf=8;kf=-37;gm("ctf"); os="Special Effects - Depth";jf=8;kf=-84;gm("ctf"); wm("bc"); // Close bitmap operation. } //-------------------------- Generate 3D-Effects Image (No Change) -------------------------- void Effects() { lf=of=150;wm("bo"); // Open new bitmap operation using // bitmap of size 185 X 185 pixels cls="p7";gm("ec"); // Paint background same as page lf=of=128;gm("ce"); // Create a circle ks="effect_s";wm("vg"); // Retrieve the effects string if (os.Length<1) os=" "; // If var lost or corrupted use default //----------------------------- Radial Gradient Paint ------------------------------ if (os.Equals("RGP")) { // If "Radial Gradient Paint selected: cls="s9r0";gm("spr"); // Make radial gradient brush for the circle gm("grf"); // Render-fill the circle object. } //----------------------------- Linear Gradient Paint ------------------------------ else if (os.Equals("LGP")) { // If "Linear Gradient Paint selected: cls="s9b0";ad=0;gm("spl"); // Make linear gradient brush for the circle gm("grf"); // Render-fill the circle object. } //-------------------------- Special Effects - Reflection --------------------------- else if (os.Equals("SER")) { // If "Sp Effects-Reflection selected: of=5;cls="p0";ks="r";gm("grs"); // Render with sp effects-reflection // brightness factor=5, blue color } //----------------------------- Special Effects - Depth ----------------------------- else if (os.Equals("SED")) { // If "Sp Effects-Depth selected: cls="s9s0";id=20;ad=30;ks="d";gm("grs"); // Render with sp effects-depth // Shear angle=30, Depth=20 pixels } //---------------------------- No 3D Effects Requested ------------------------------ else { // If No Selection made (title selected): cls="p0";gm("sps"); // Create Pink solid paint brush gm("grf"); // Render-fill the circle object. } wm("bc"); // Close bitmap operation. } } ==============================================================================================