Showing posts with label Console programing. Show all posts
Showing posts with label Console programing. Show all posts

Saturday, July 15, 2017

console barmenu -3- c sharp - 170714Fr

  Console BarMenu - 3  
.
(DOS era text-mode style Colorful Bar-Menu in c#)
Version: 170714Fr
.
During the era of DOS 3, creating a bar menu in text or graphic mode was a cutting-edge topic in programming. I vividly remember writing a ".prg" program in dBase III Plus on my institute's PC, which impressed my friends, lab assistants, and teachers. That program was my first attempt at creating a bar menu, and I'm proud to say it was a success. Although I'm not sure if the printout of that program still exists in my archives, I'm not eager to find out also. In memory of that bar menu, I've now recreated that bar menu as a Console project in C#.
.
Salient  features of above mentioned c# project are as follows:
(A) Display bar-menu.
(B) Provide menu-item selection mechanism through navigation keys like Up-arrow, Down-arrow, Home, End and Enter keys.
(C) Process menu-item selection and perform action accordingly.
(D) Return back to menu at end of action processed.
(E) Provide mechanism for exiting from 'bar-menu' and application.
.
Then I tried and made the above required project. Code for achieving above task is simple and is described as follows.
(1) First menu processing method is called. There must be one such method per menu.
(2) Then from menu processing method menu-driver method is called with information like menu-item-list etc.
(3) Then in menu-driver things happen in following sequence:
(3a) First menu is displayed.
(3b) Then user-input is taken.
(3c) Then user-input is processed based on input key as follows:
(3c1) Navigation key: Selected menuitem index is updated.
(3c2) Enter key: Current menuitem index is selected for returning.
(3c3) Escape key: Menu exit code is selected for returning.
(3c4) If user input is not Escape-Key or Enter-Key go back to step 3a.
(3c5) Menu-driver exits when user-input is Escape-Key or Enter-Key.
(4) Back in menu processing method returned value is processed as follows:
(4a) Respective methods are called according to returned value. On return control goes back to step 2.
(4b) Else menu exits when selection code is Escape-Key.
.
Keys used by menu are displayed in menu footer and are described in the following:
Navigation:
Down-arrow key for next menuitem.
Up-arrow key for previous menuitem.
Home key for First menuitem.
End key for last menuitem.
Selection:
Ente key for selecting current menuitem.
Exit:
Escape key for exiting menu.
.
Following is the C# code of the project I described above. It is not so simple or easy to understand. But it is full of helpful comments throughout it.
.

.
Code of "Console BarMenu - 3" in Visual C# 2010
.

.
Application Output
Following are some screen-shots of the application I took at different state of application to explain the application's look and feel.
.
Application is loaded
(When Application is loaded.)
.
.
Application Menu bar navigation
(When selection bar is on first menu-item)
.
(When selection bar is on last menu-item)
.
(When selection bar is on some other menu-item)
.
.
Application Menu item selected
When menu's any selection bar is selected by pressing ENTER key and application is moved to the respective section.
.
(When 'Grains and cereals' menu-item is selected and respective method is run)
.
(When 'Vegetables' menu-item is selected and respective method is run)
.
(When 'Bakery & Confectionery Products' menu-item is selected and respective method is run)
.

.
Method which displays message based on menu selection,  randomly selects background for console screen from a few dark ConsoleColors making display a little colorful.
.

.
A brief overview of Console application:
In the context of C#, a Console Application is a type of program that interacts with users through the command-line interface. This type of application reads input from the user through the standard input stream (STDIN), processes the input, and then displays output to the user through the standard output stream (STDOUT). Additionally, any error messages or exceptions are directed to the standard error stream (STDERR). Console Applications are commonly used for tasks that require user input, such as command-line tools, utilities, and interactive programs. They provide a simple and efficient way to interact with the user, making them a fundamental part of the C# programming landscape.
.

.
If there are any mistakes then I will surely remove them whenever found.
.

.
Enjoy Complete Source code of application written and compiled in visual studio 2010 Ultimate by me. Download it. Extract it. Read 'ReadMeFirst.txt' file and do as is explained in it.
.


Thursday, June 29, 2017

Turbo C assignment - No 1 - C Sharp - 170629Thu

  Turbo C assignment # 1  
.
(Re-Written in visual C# 2010 for producing here)
Version: 170629Thu
.
A few decades ago when I was learning computer programming in some institute in Karachi, Sindh, Pakistan, during orientation class a teacher, who after-wards taught us 'dBASE III plus' and was very good teacher, praised 'C' computer programming language a lot. And that created special kind of curiosity in me for 'C' programming language. And a line he spoke about benefits of learning 'C' computer programming language is still very valid in 2017.
.
And when in 2nd semester we started learning 'C' programming language, I was going ahead of class work; at least I was thinking so. I was reading my 'C' book faster than class lecture was going. I was going to library and reading different books on 'C' programming language. I was going to computer lab and writing sample and example programs from books looking interesting to me and experimenting with those programs and was also solving exercises from different books.
.
In that class I/we learned 'C' programming language through 'Turbo C Ver 2'. 'Turbo C's IDE was very excellent and advance. During that time before and beside 'Turbo C' I liked 'GW-Basic' for its own good IDE and 'dBASE III plus' for it's very good IDE.
.
As I am writing this text, time then spent in that institute is coming to my mind. Friends of that time/institute, teachers and specially that of 'C' subject, class room, computer labs and especially 'C' lab, library etc. Everything is revisiting my mind in pieces in random sequence. And a gentle wish of some-how going back in time to that time and place is also coming in my mind. But because it cannot happen so I am getting a strange feeling of loosing something.
.
From that time a program written in 'Turbo C' is still available with me in hard copy. Special thing about that program is that it was first assignment of 'Turbo C', my favorite subject/class of 2nd semester, and so still is very memorable for me. One more thing special about it is that, on assignment submitting day in 'C Lab' after loading 'C' assignment in 'Turbo C' IDE, I was waiting for 'C' teacher to come up to me to inspect/check my assignment. I was sitting in front of PC with my back towards PC. On my turn teacher came to me and while looking on monitor of PC I was using said to me with his ever smiling face and eyes "Oh, you did nothing". I got shocked and looked back at computer screen ... Computer monitor was blank ... "What happened? Where is everything? ..." I said to myself. Meanwhile teacher touched some key on keyboard and everything came back, monitor becomes alive again. I felt relieved and relaxed. My teacher then looked at the code for a while and then ran/executed the program by pressing 'Ctrl+F9'. Turbo C IDE compiled the program and displayed it’s output. Teacher looked at program’s output and smiled. Then teacher again looked at the code and ran the code a few more times. Then my teacher praised me for my assignment, but not before disturbing my heart beat, and went to next student sitting in front of next PC beside me, who was then a very good friend of mine. Meanwhile my heart beat started to come back to normal.
.
Turbo C assignment requirement
Requirement for 'Turbo C' assignment #1 was to display all tables from '2' to '10' together on computer monitor with proper formatting.
.
Assignment Code migration from Turbo C to C# 2010
'Turbo C' is available on my Pentium 3 and that Pentium 3 is not booting, in fact it is not getting ON, and I am neither fixing it myself nor taking it to shop for fixing it. So I cannot write that assignment in 'Turbo C'. So I wrote it in visual c# 2010 as a console application for producing here on my this blog post.
.
Following is the C# code for achieving above discussed 'Turbo C' assignment requirements in 'C# 2010' Console application. I made a few +/- to original code for adjusting to C# console application. Code is well documented and easy to understand.
.

.
Visual C# 2010 Code
.

.
Application Output
(Console screen/window after program execution)
.
If there are any mistakes then I will surely remove them whenever found.
.
I used 'Snipping Tool' for getting Screen-shot of application discussed above. And I did this for the first time for this post. Doing this helped me keeping background color of post.

Enjoy Complete Source code of application written and compiled in visual studio 2010 Ultimate by me. Download it. Extract it. Read 'ReadMeFirst.txt' file and do as is explained in it.