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


DEMONSTRATIVE EXAMPLES DESKTOP APPLICATIONS ====================== How long does it take me to learn Personal C. Sharp? ==================================================== The .NET has never stopped expanding in size since its creation. However, in our opinion, all the valuable tools and methods which you may like PC# to implement are available in Version 3.5. Our documentation folder which includes all examples, all methods and all PC# references and other texetual information is 2.5 Megabytes in size. If you print them all, you end with a stack of paper which is about 3.0 inches thick. When we tried to compare that with the documentation folder of the .NET v3.5, here is what we have found (We must state here that we cannot guarantee the accuracy of this comparison. Try to do the comparison by yourself): ** The size of the .NET v3.5 documentation folder is 900 Megabytes which is more than 350 times the size of Personal C Sharp's. ** If we try to print all the .NET documentation material, based on its size in comparison with personal C. Sharp's, we could end with a stack of paper which is 90 feet high. This is as high as a 10-story building! Does it sound unbelievable? We apologize if our calculations have not been accurate. However, we know that learning Personal C Sharp could not cost you a significant part of the time you spend to learn the .NET. Which C# language version do I need to learn? ============================================= Just like the .NET, the C# language has been constantly growing in size since its first version was introduced. Its first version which was mostly familiar to a person who knows the original C language, is all what you need to know in order to learn all PC# examples. If you find any problem, see Microsoft documentation at this site: https://msdn.microsoft.com/en-us/library/x53a06bb(v=vs.71).aspx ================================================================================================ GENERAL EXAMPLES ================ RECOMMENDED STUDY ORDER: ======================== (1) Demonstrative examples - Desktop applications. (2) Desktop application reference. (3) Demonstrative examples - Web applications. (4) Web application reference. A printed copy of "Personal C Sharp public methods" should be available to look at during the study. ============================================================================================== EXAMPLE 1: Let us see how to write the simplest program to display the message "Hello World!" on the system screen. ============================================================================================== class a:pcs { // Your class "a" extends PC# class. public override void run() { // The method which runs your program. cm("fe"); // Eliminate form to allow System Screen to appear os="Hello World!";tm("dl"); // call the text method tm() with the text to be displayed } } ============================================================================================== HOW TO WRITE THE PROGRAM? Use NotePad. Since "a" has been chosen to be the name of the class, save the program into a file named "a.cs". HOW TO COMPILE IT? From Command mode type: 'pcp a' and hit [ENTER]. The program will be compiled and you will see the new executable file "a.exe" in your directory. HOW TO RUN THE PROGRAM? Just type 'a' and hit [ENTER] WHAT DOES "pcp" GO FOR: "pc" is for PC# and the last "p" means that it is a program (not a library file). If you wanted to compile it as a library file, you should have used the command "pcl" instead which could have generated the library file "a.dll" instead of the executable file "a.exe". You could have also combined compiling the program and running it by using the command "pcpr". REMARKS: (1) Here is how to get into command mode: a) Using old versions of Windows: [Start][All Programs][Accessories][Command Prompt] b) Using Wondows 10: [Start][All Apps][Windows System][Command Prompt] OR: You may ask Cortana to "Open Command Prompt". (2) If you get the message "Access is denied" when you try to save the file, click on "Reference-Desktop" and read the section titled: "GETTING THE MESSAGE 'ACCESS IS DENIED" WHEN ATTEMPTING TO SAVE A FILE'". ============================================================================================== TUTORIAL: (1) Your class extends class "pcs". This allows you to access PC# methods in addition to the entire ".NET" library. (2) The text method tm() does many tasks one of them is displaying a line of text on the screen. Each task is identified with a string of upto 3 characters called the "mode" string. Assigning "dl" to the mode string means that you want the method to display a line of text for you. (3) You may have noticed that all names in PC# include their type code. (os) is a string and tm() is a method. Here are the type identifiers of the most common simple types: integer: i or none double : d string: s boolean: b character: c byte : y object : o method : m (4) Now you may like to ask "All variable names I have seen so far are in lower case. Is this a rule? C# is a case sensitive language, however PC# has simplified program writing and reduced typing errors by setting rules for its public variable names (through which your program and PC# communicate with each other) The rules are: (a) All "single value" variable names are made of lower case characters only. (b) All arrays and other "multiple value" variable names are made of upper case characters only. As an example: i,jb,kc,os and OS[] are valid public PC# variable names. You need to know here that you do not have to apply this rule to the names which you define and use within your program. (5) You may also like to ask "How come we have not defined variable (os) as a string within the class and where are method main() and the "using" direcives which are necessary for any C# executable class? In order to simplify programming further all "single character + type" variables have been predefined for you. The command "pcp" which you have used to compile the program with has internally added method main() and all necessary "using" directives. For more details See "Personal C# reference". =========================================================================================


EXAMPLE 2: Let us now try two more ways to display the same message. ============================================================================================== public class a : pcs { // Displaying text graphically public override void init() { base.init(); // Initialize pc# classes } public override void run() { os="Hello World!";gm("ctf"); // Create text graphics and draw-fill } } ============================================================================================== class a : pcs { // Displaying text into a dialog box public override void init() { base.init(); // Initialize pc# classes } public override void run() { os="Hello World!";cm("d"); // Call the controls handling method cm() to draw the } // text into a dialog box. } ============================================================================================== HOW TO WRITE, COMPILE AND RUN THE PROGRAM? See Example 1. However, you have one more option this time. If you use the tool "pwp" instead of the tool "pcp", the resulting executable file will be a clickable windows application. See "PC# reference, desktop" for more details. ============================================================================================== TUTORIAL: (1) This time, we have used two new methods to display the text. The "graphics" method gm() displays the text graphically and the "controls" method cm() displays the text into a dialog box. (2) You may be wondering why we always use the variable name (os) to assign the text to before accessing either method. All PC# methods expect their parameters to be of two character names, the first character can be i, j, or k and the second character denotes the type. Similarly, the return values of all PC# methods are assigned to variable names which are made of the letter 'o' and a type code. 'i' is for "method's input", 'o' is for method's output. 'j,k' which are the two characters following 'i' in the alphabet are also used for input. With some methods like tm("dl") or cm("d") which require only one parameter and returns it unchanged, (os) is used for both input and output. The "i,j,k and o" based variables are called the "General Use Variables" or GUV's. At the end of each method all the (i,j,k) based GUV's are reset. This means that they are assigned zeros if numeric, assigned "" if strings and assigned 'false' if they are boolean. They are guaranteed to stay reset all the time except immediately before you access a method. When you access a method, you assign values to the them then immediately call the method which resets them all again before your program execution is resumed. (3) In Example 1, we did not include the initialization method init() in order to keep things simple. This method is necessary when we need to set default values as we'll see in the next example and it is always a good practice to include it. When you include this method, you must initialize PC# classes with the statement "base.init();" at its end. ==============================================================================================


EXAMPLE 3: Let us now use a much better display. ============================================================================================= class a:pcs { public override void init() { toa="t"; // Select "text screen" for txt output base.init(); // Initialize pc# class. Must be the last statement } public override void run() { cls="b0"; // Set color at pure blue fns="esb24"; // Set font at "Edwardian Script", bold, size 24 os="Hello World!";tm(); // call the text method tm() with the txt to be displayed } } ============================================================================================= HOW TO WRITE, COMPILE AND RUN THE PROGRAM? See Example 1. ============================================================================================= TUTORIAL: ========= (1) In Example 1, the text was displayed on the Console. That was because we did not tell PC# which text output device to use for displaying text and the Console is the default. In this example we have requested making the "text screen" the device to be used. The text screen has been developed by PC#. It displays a scrollable text to the user and allows the user to enter a text line at the bottom which it sends back to your program whenever your program requires user response. The text screen also allows the user several options like searching, printing and filing of the displayed text. (2) You may be wondering why we accessed method tm() this time without specifying the mode. The reason is that mode "dl" is the default mode of this method. So tm("dl") and tm() mean the same thing to the method. (3) The symbol for the text output device is (toa) is this another naming method for PC#? Yes. There are two naming systems: a) "One char + type code" which is used for simple values like numbers and strings. They are predefined for you. This means that you can use the int (n), the double (nd) and the string (ns) without type declaration. b) "Two char's + type code" Which is used for general objects. The two char's are normally the first char in the object's name + the next non-vowel character. If the object name was made of more than one word, the two char's are selected to be the first char of the first word and the first char of the second word. The type codes in this case are the same as the ones used with the "single char + type" var's except that there are some additional ones. As an example, the 2-char code for the object (color) is "cl", so we can expect that: (clo) is a color object. (cls) is a string which is related to color. (cli) represents an int which is also related to color and arrays CLS[] and CLI[] are arrays which are related color. Additionally, (clp) means present color object and (cla) means "Applet's color". Applet is a name which was borrowd from Java. We mean by this type "a default value for the entire class. So (cla) is the default color for your program. similarly, (toa) is the default text output device for your program. =============================================================================================


EXAMPLE 4: Let us now get into a more serious program. We'll create a menu which gives the user the choice of displaying the message "Hello World!" in either red, blue or green colors. Each time the user selects one color, the message will be displayed in that color then the menu will appear again to allow him a new choice. ============================================================================================= public class a : pcs { public override void init() { tia=toa="t"; // Select "text screen for both text input & output bli=1; // Requesting to start execution at block 1. base.init(); // Must be the last in init() } public override void run() { if (blp==1) { // Start of code block 1. cls="r0"; // Set color to "Pure red". fns="trb14"; // Set font to "times roman",bold,size 14. os=" MENU"; // and display this text. tm(); // Calling method tm() to execute. os="";tm(); // Skip one line cls="S9";fns="trb10"; // Change color, font os=" (R) Red.";tm(); // Display this line. os=" (B) Blue.";tm(); // and this line. os=" (G) Green.";tm(); // and this line os=" (E) Exit.";tm(); // and this line os="";tm(); // skip one line cls="b0"; // Change Color. os="Type your selection into the text field at bottom then hit the [ENTER] key."; tm(); os="Selection :";bli=2;tm("i");// Get user selection and jump to block 2. return; } if (blp==2) { // Start of code block 2. String message="Hello World."; // Message to be displayed. int index="EeRrBbGg".IndexOf(os);// Check selection if (index<0){ // If unexpected char entered bli=1;um("b"); // return to block 1. return; } else if (index<2) sm("e"); // If selection was "E or e" exit program else if (index<4) {os=message;cls="r0";tm();} // If selection was "R or r" display msg in red. else if (index<6) {os=message;cls="b0";tm();} // If selection was "B or b" display msg in blue. else if (index<8) {os=message;cls="G2";tm();} // If selection was "G or g" display msg in green. bli=1;um("b"); // Then return back to block 1 to repeat the menu. return; } } } ============================================================================================= HOW TO WRITE, COMPILE AND RUN THE PROGRAM? See Example 1. ============================================================================================= TUTORIAL: ========= (1) The first thing to notice is that the program is divided into seperate blocks. Each block is assigned a unique number and in method init(), we have made a request to start execution at block 1. Now what are blocks for? a) The utilities method um() allows us to jump from any block to another which greatly simplifies programing tasks as you'll see later. b) When we come to examples on controls, you'll see an additional programming simplification. You do not have to worry about delegates any more. Handling events is very easy. (2) JUMPING BETWEEN BLOCKS: You can do any jump (forward or backward) by assigning the destination block to (bli) and calling the utilities method at mode "b". There is one important rule. The jump statement should be the last one to be executed in the original block. Since this rule is very important, always follow each jump statement with a (return;) even if it was naturally the last in the block. (3) GETTING DATA BACK FROM THE USER: Method tm() at mode "i" (the text input mode) allows the user to supply your program with texetual data whenever instructed to do so. In the example, after we have displayed the menu to the user, we wanted to display the phrase "Selection?" then read back user's response. Method tm() at mode "i" does the two jobs. It uses (os) for both jobs, which means that it expects our phrase to be assigned to (os) and it sends us the user response back assigned also to (os) There is only one simple problem, your program cannot continue on same block. Method tm() must send the user response to a different block. So, we supply the method with the number of the block which we like to continue at, terminate our current block and resume the program at the new block. Since method tm("i") executes a jump, it must also be followed with (return;) (4) Whenever method tm() displays text on the "text screen", it uses default color and font for the display unless you assign them new values. The default color is black and the default font is "TimesRoman", bold, size 12. Whenever you like to change the color or font assign your wanted color or font codes to (cls) or (fns) respectively before calling method tm() to display your text. (5) FORMING THE COLOR CODE: Your program can state the color it wants either accurately by supplying the red, green, blue and opacity components or by using the PC# color code. For text purposes, we prefer to use the color code. The color code is made of three characters like "r25". The first char tells the color wanted which is "red" in this case. The second char is a digit which tells the shade. It means how much white color or black color you want to mix your color with. If you want to mix it with white color you make the first char a lower case one and if you want to mix it with black color you make it an upper case one. The second character can be in the range 0:9 in either case. "r0" means pure red and "r5" means midway between red and white. "R0" also means pure red and "R5" means midway between red and black. The third char is for the opacity and it is optional. "0" means fully transparent, "9" means fully opaque and if eliminated it will be considered to be "9". (6) FORMING THE FONT CODE: Let us analyze the code "trbiu12" .The first two chars represent the font name. tr=Times Roman cr=Courier hl=Helvetica. The number at the end represents the font size. The chars in between the two are optional. You may add any or all of them. They are: b=bold i=Italic u=Underlined s=Strikeout. For more information on color and font, see PC# Reference. =========================================================================================


============================================================================================== The old fashioned menues which you have seen a sample of, have been used for years to perform entire programming projects. The menu of the previous example was a single tier menu. In the next example we are going to show you how to write a multi tier menu. Multi tier menues have been used for decades to encapsulate all the software necessary to run an entire company. They normally start with a "Main" menu which branches to a number of submenues, one for each department of the company. Each submenu may also contain other submenues and this may continue to any depth as the company software requires. When we get into the more exciting world of graphics, you'll learn how to create modern menues. For now, we are going to write a multi tier old fashioned menu which shows how to do most programming tasks in PC# which do not involve graphics. ============================================================================================== EXAMPLE 5: Write a multi tier menu which shows how to use PC# methods to perform General, System, Filing and Networking operations. ============================================================================================== This program is large in size, but don't let this worry you. Most of it is text to display and you already know every thing necessary to understand it. So look at it, then read the tutorial. ---------------------------------------------------------------------------------------------- public class a : pcs { // ** VAR's Used: // ** x=order of selection in first menu y=order of selection in second menu public override void init() { tia=toa="t"; // Select "text screen for both text input & output bli=1; // Requesting to start execution at block 1. base.init(); // Initializing PC# classes. Must be last statement } public override void run() { // ------------------------------------ Main Menu --------------------------------------- if (blp==1) { // Main Menu Block cls="r0";fns="trb14";tm("c"); // Set font,clor, clear screen. os=" MAIN MENU";tm(); os="";tm(); // Display title cls="b0";fns="trbi12"; // change to blue bold, italic size 12 text writing os=" Demonstrates how easy and efficient Personal C# programming can be!"; tm(); // Display sub-title. os="";tm(); // Skip one line cls="S9";fns="trb10"; // Change color, font os=" (G) General tasks menu.";tm(); os=" (S) System operations menu.";tm(); os=" (F) Files and Directories menu.";tm(); os=" (N) Networking menu.";tm(); os=" (E) Exit Program.";tm(); os="";tm(); // skip one line cls="b0";os="Selection :";bli=2;tm("i");return; // Get user selection and jump to block 2. } // -------------------------- Main Menu Selection Processing----------------------------- else if (blp==2) { os=os.ToUpper(); // Convert selection to upper case x="GSFNE".IndexOf(os); // Get selection index if (x<0){ // If unexpected char entered bli=1;um("b");return; // return to block 1. } // else jump to the block which executes selection else if (x==0) {bli=3;um("b");return;} else if (x==1) {bli=4;um("b");return;} else if (x==2) {bli=5;um("b");return;} else if (x==3) {bli=6;um("b");return;} else if (x==4) sm("e"); // If selection was "E or e" exit program } // -------------------------------- General Tasks Menu ----------------------------------- else if (blp==3) { cls="r0";fns="trb14";tm("c"); os=" GENERAL TASKS MENU";tm(); os="";tm(); cls="S9";fns="trb10"; os=" (1) Get a random number.";tm(); os=" (2) Display my message in large size letters.";tm(); os=" (3) Display a message into a dialog box.";tm(); os=" (E) Exit to Upper menu.";tm(); os="";tm(); cls="b0";os="Selection :";bli=9;tm("i");return; // Get user selection and jump to block 9. } // ----------------------------- System Operations Menu --------------------------------- else if (blp==4) { cls="r0";fns="trb14";tm("c"); os=" SYSTEM OPERATIONS MENU";tm(); os="";tm(); cls="S9";fns="trb10"; os=" (1) Display all environment names and their values.";tm(); os=" (2) Display user's domain name, computer name and user name.";tm(); os=" (3) Display local drives of this computer.";tm(); os=" (4) Get version number of both C# and Operating System.";tm(); os=" (5) Display current Date and Time.";tm(); os=" (E) Exit to upper menu.";tm(); os="";tm(); cls="b0";os="Selection :";bli=9;tm("i");return; // Get user selection and jump to block 9. } // ---------------------------- Files & Directories Menu -------------------------------- else if (blp==5) { cls="r0";fns="trb14";tm("c"); os=" FILES AND DIRECTORIES MENU";tm(); os="";tm(); cls="S9";fns="trb10"; os=" (1) Get the name of current directory.";tm(); os=" (2) Create a file.";tm(); os=" (3) Delete a file.";tm(); os=" (4) Tell me if it is a file, directory or non-existing.";tm(); os=" (5) List all sub-directories and files in current directory.";tm(); os=" (6) Copy a file to another.";tm(); os=" (E) Exit to upper menu.";tm(); os="";tm(); cls="b0";os="Selection :";bli=9;tm("i");return; // Get user selection and jump to block 9. } // -------------------------------- Networking Menu ------------------------------------ else if (blp==6) { cls="r0";fns="trb14";tm("c"); os=" NETWORKING MENU";tm(); os="";tm(); cls="S9";fns="trb10"; os=" (1) Get a web page from the internet and display its contents.";tm(); os=" (E) Exit to Upper menu.";tm(); os="";tm(); cls="b0";os="Selection :";bli=9;tm("i");return; // Get user selection and jump to block 9. } // ------------------------- Sub-Menues Selection Processing ---------------------------- else if (blp==9) { os=os.ToUpper(); // Convert selection to upper case y="123456E".IndexOf(os); // Get selection index if (y==6) { // If "Exit to upper menu" selected bli=1;um("b");return; // return to main menu block } // Else, if unexpected char or larger than expected // number for the particular sub-menu was entered else if (y<0 || (x==0 && y>2) || (x==1 && y>4) || (x==2 && y>5) || (x==3 && y>0)) { bli=x+3;um("b");return; // return to the same sub-menu. } else { bli=x*2+10;um("b");return; // else jump to the block which executes selection } } // ----------------------- Execution of Sub-Menue G Selections -------------------------- else if (blp==10) { // Data Collection Block if (y==0){ // Sel 1: Random number os="Enter the highest integer value, the random number can be:"; bli=11;tm("i");return; // Get data from user and jump to execution block } else if (y==1 || y==2){ // Sel 2,3: Msg to be displayed os="Enter message to be displayed: ";bli=11;tm("i");return; } } else if (blp==11) { // Execution Block if (y==0){ // Sel 1: Random number i=Int32.Parse(os);um("mr"); // Convert to int and call um("mr) with it os="Random Number: "+o;tm(); // Display Random number obtained } else if (y==1){ // Sel 2: Banner fns="trb48";cls="p0";tm(); // Change Font to large size, display msg fns="trb10";cls="S9"; // return font & color to their original values } else if (y==2){ // Sel3: dialog box display cm("d"); // Display returned string in (os) into a dialog box } os="";tm();cls="r0"; // After selection has been executed,Skip one line // then display the following instruction in red: os="Hit [ENTER] to return to menu.";bli=x+3;tm("i");return; // then return to the same sub-menu } // ----------------------- Execution of Sub-Menue S Selections -------------------------- else if (blp==12) { // Data Collection Block bli=13;um("b");return; // Go to execution block direcly since no data // is required by any selection in this menu. } else if (blp==13) { // Execution Block if (y==0){ // Sel 1: Display environment var's sm("gE"); // Get all env keys in KS[] and values in OS[] for (c=0;c < KS.Length;c++) { // Scan the 2 arrays, if (KS[c].Length<1) continue; // Skip no data rows. cls="b0";os="KEY: "+KS[c];tm(); // Display each key in blue cls="S9";os="VALUE: "+OS[c];tm(); // and its value in black. os="";tm(); // Skip one line for seperation. } } else if (y==1){ // Sel 2: Get System/User info sm("gd");os="User's Domain: "+os;tm();// Get & Display Usr's Domain sm("gc");os="Computer name: "+os;tm();// Get & Display Computer name sm("gu");os="User name: "+os;tm(); // Get & Display User name } else if (y==2){ // Sel 3: Get logical drives sm("gl"); // Get drive names in OS[] om("fa");tm(); // Convert OS[] to (os) and display. } else if (y==3){ // Sel 4: Get Version numbers sm("gv");os="C# Version number: "+os;tm(); sm("go");os="Operating Systm Version: "+os;tm(); } else if (y==4){ // Sel 5: Get date/time sm("dl");os="Current Date: "+os;tm(); // Get long format of date & display it. sm("dt");os="Current Time: "+os;tm(); // Get time & display it. } os="";tm();cls="r0"; // At the end return to the same sub-menu os="Hit [ENTER] to return to menu.";bli=x+3;tm("i");return; } // ----------------------- Execution of Sub-Menue F Selections -------------------------- else if (blp==14) { // Data Collection Block if (y==0) { // Sel 1: Get Current dir bli=15;um("b");return; // Go to Execution block directly. } else if (y==1 || y==2){ // Sel 2,3: Create/Delete a file os="Enter file name (Remember to double backslashes): "; bli=15;tm("i");return; // Get data from user and jump to execution block } else if (y==3){ // Sel 4: Check attributes os="Enter file or directory name (Remember to double backlashes): "; bli=15;tm("i");return; } else if (y==4){ // Sel 5: Listing folder contents. os="Enter directory name (Remember to double backlashes): "; bli=15;tm("i");return; } else if (y==5){ // Sel 6: Copy os="Enter source, destination files seperated with a comma: ";bli=15;tm("i");return; } } else if (blp==15) { // Execution Block if (y==0){ // Sel 1: Get current dir fm("."); // Get directory name in (os) and display it. os="Current Directory: "+os;tm(); } else if (y==1){ // Sel 2: Create file fls=os;ks="f";fm("M"); // Create the file os="File has been created.";tm(); } else if (y==2){ // Sel 3: Delete file fls=os;ks="f";fm("D"); // Delete the file os="File has been deleted.";tm(); } else if (y==3){ // Sel 4: Check attributes fls=os;fm("A"); // Get file attributes. n="fd ".IndexOf(os); // Check to see if returned string is "f", "d" or " " if (n==0) os="a file"; else if (n==1) os="a directory"; else os="non existing"; os="It was found to be "+os;tm(); // Display result. } else if (y==4){ // Sel 5: Display folder contents fls=os;ks="d";fm("L"); // Get all sub-dir's in OS[] om("fa"); // Convert OS[] to (os) ns=os; // save (os) temporarely ks="f";fm("L"); // Get all files in OS[] om("fa"); // Convert to (os) os=ns+os;tm(); // Add the 2 lists & display } else if (y==5){ // Sel 6: Copy a file oc=',';om("s"); // Seperate the 2 files names recieved into OS[] fls=OS[0];os=OS[1];fm("C"); // Copy source file to dest file os="File copied";tm(); // Inform user } os="";tm();cls="r0"; // At the end return to the same sub-menu os="Hit [ENTER] to return to menu.";bli=x+3;tm("i");return; } // ----------------------- Execution of Sub-Menue N Selections -------------------------- else if (blp==16) { // Data Collection Block cls="r0";os="Please know that retrieving your web page may take a long time.";tm(); cls="b0";os="Enter web page address: "; bli=17;tm("i");return; // Get data from user and jump to execution block } else if (blp==17) { // Execution Block urs=os; // Assign received string to (urs), restore color nm("hg");tm(); // Get the web page and display its contents os="";tm();cls="r0"; // At the end return to the same sub-menu os="Hit [ENTER] to return to menu.";bli=x+3;tm("i");return; } } } ============================================================================================== HOW TO WRITE, COMPILE AND RUN THE PROGRAM? See Example 1. ============================================================================================== TUTORIAL: ========= Program design is simple. Because it is easier to work with numbers than with strings, we have used the orders of selected items in each menu to identify the selection. We used (x) to store main menu selection and (y) to store the sub-menu selection. x and y are two variables of "int" type which you don't have to declare since PC# has done this job for you. See PC# Reference for a list of variables of this kind. Every thing else in this program is self explanatory. =============================================================================================


EXAMPLE 6: Can we do the same using the Console instead of the "Text Screen"? Yes we can. Although using Graphical Controls for text input and output is a must for some applications, using the Console is the better choice for others. Let us see how to modify example 4's code to use the console for text input and output. ========================================================================================= public class a : pcs { public override void run() { cm("fe"); // Eliminate form to allow System Screen to appear j=78;k=20;dm("cs"); // Resize Console to 78 char's/line - 20 lines/page cls="s0";dm("ccb"); // Paint background with light gray. tm("c"); // Clear Screen while(true) { // Start of endless loop. cls="r0"; // Set color to "Pure red". fns="trb14"; // Set font to "times roman",bold,size 14. os=" MENU"; // and display this text. tm(); // Calling method tm() to execute. os="";tm(); // Skip one line cls="S9";fns="trb10"; // Change color, font os=" (R) Red.";tm(); // Display this line. os=" (B) Blue.";tm(); // and this line. os=" (G) Green.";tm(); // and this line os=" (E) Exit.";tm(); // and this line os="";tm(); // skip one line cls="b0"; // Change Color. os="Selection :";tm("i"); // Get user selection. String message="Hello World."; // Message to be displayed. int index="EeRrBbGg".IndexOf(os);// Check selection if (index<0){ // If unexpected char entered continue; // return to start of endless loop. } else if (index<2) break; // If selection was "E or e" exit loop else if (index<4) {os=message;cls="r0";tm();} // If selection was "R or r" display msg in red. else if (index<6) {os=message;cls="b0";tm();} // If selection was "B or b" display msg in blue. else if (index<8) {os=message;cls="G2";tm();} // If selection was "G or g" display msg in green. } } } ========================================================================================= HOW TO WRITE, COMPILE AND RUN THE PROGRAM? See Example 1. ========================================================================================= TUTORIAL: We needed to modify the following: (1) The block jumps have become unnecessary. When we use the Console for text input, we don't need to continue into a new block each time we get user's response. So, we have found that the entire program can be written as one block. (2) Since there are no blocks, we have used a new mathod to jump back to the top of the menu after each selection has been executed. The new method was to enclose the entire program into an endless loop which keeps repeating until the user selects exit (e) to cause the program execution to break off the loop and the program ends. (3) Selection of colors is not as wide for the Console as it is for the "Text Screen". However PC# allows you to specify the color in the same manner as you do with "Text Screen". If the color you want was found to be unavailable, PC# replaces it with the nearest available color. (4) You cannot specify the font programmatically when you use the Console for display. =========================================================================================


============================================================================================== What do you like to do next? ============================ If you were a person who used to write his or her own programs in one of the old languages like Cobol, Pascal, C or Basic and like to do the same using C# and the .NET, you have already got most of what you need. The only other chapter which you need to study is "Filing". If you like to access the old programs from your new PC# program see the chapter of "Accessing External objects". If you have a Web page which you like to interact with programmatically, you'll find what you need in the chapter of "Networking". This same chapter can also take you to the more advanced subjects of "Client and Server developing". If you like to learn how to use modern graphical means to interact with users, study the chapter of "Controls". If you like to learn how to draw in 2D and 3D spaces, how to create, edit and file images, read the chapters of "Drawing" and "Imaging". If you like to go further with 3D drawing and video, read the chapter of "Windows Presentation Foundation". If you are a professional web developer and like to learn the most powerful way to develop web pages with the ASP.NET, look at "Examples-Web" and study all the examples in order. If you like to learn the .NET in full, study the entire course at the recommended order. ==============================================================================================