Programming in Any Language
C# Tools, Techniques, and Fixes
Downloading the Language - The Debugger - Moving Your Application - Flowcharting - Removing Unwanted Event Handlers - Comments, Blank Lines, and Indentations - Tab Order and Focus - Preventing Negative Number, Garbage, and Unreasonable Data - Fixing File Processing Issues - Non-Default Mouse Events - Multiple Forms - The Image List Control - Renaming Objects After Coding - The ToString() Method - The MessageBox
Downloading the Language
Click to enlarge
This video will show you how to find Visual Studio on the internet and then download and install it on your machine.
The Debugger
Click to enlarge
A logic error is a mistake that does not prevent an application from running but causes the application to produce incorrect results. Mathematical mistakes, assigning a value to the wrong variable, or assigning the wrong value to a variable are example of logic errors.
Logic errors can be difficult to find. Today Visual Studio, Python, Java, and virtually all the most common languages have tools that make the debugging process easier. In Visual Studio it’s called the debugger.
Moving Your Application
To move an application to a new location you need to move everything and keep everything together. Visual Studio creates a lot of files. Zip will allow you to compress that application in total and place it in a new location where it can be safely opened (unzipped). The project will run as normal in the new location
Flowcharting
Things can get a little dicey when applications get complex. That’s when we really need that plan. And that plan is a flowchart.
I touched on flowcharting back in the decision section when we looked at the nested decision structure. Remember? One “if” statement was inside another. Flowcharting that concept allowed us to see the logic and how complicated it might get. Well loops can be nested as well. Not only that but just a single loop might be better understood if we could see a picture of what we are trying to do. Best to flowchart it.
Removing Unwanted Event Handlers
Click to enlarge
We’ve all done it. Double clicked on an object and accidentally created an event we didn’t want or need. This video shows you how to get rid of such events.
Comments, Blank Lines, and Indentations
Click to enlarge
Comments, Blank Lines, and Indentations have been discussed as background in a number of other videos. However, the way your code reads is very important. Commenting code, indenting code and adding blank lines to code can greatly enhance how other people can understand what you code is doing. And six months after you’ve written your code you will be surprised at how alien your code looks even to you. Your comments and the structure of your code will be important to you when you need to get back in that code and make some modifications.
This video takes you through a mortgage calculation program and shows you how the code reads so much better once a reasonable amount of comments and structure are added to the code. PDFs: Slides, Code
Tab Order and Focus
Many applications require intense data entry on the part of the user. The speed at which a user can effectively enter data is greatly affected by the amount of time the user’s hand leaves the keyboard to grab the mouse. As a programmer, it is our job to make our program work well for our users. One very important way that we can do this is to make sure the cursor is always where the user expects it to be. That means logically tabbing through our forms. That means placing the cursor at the field the user expects to enter data. And that needs to be done for the first record a user enters and continues for every record that follows.
This video simulates a data entry screen. It’s a mortgage calculation program. There are only four text boxes on this form but if they are not set up in the proper order it can be a real mess trying to enter data. PDFs: Slides, Code
Preventing Negative Numbers, Garbage, and Unreasonable Data
The actual code we write in a program to process data is nothing compared to the code we need to write to make sure proper data gets to the calculation portion of our program. This Video demonstrates the code needed to make sure proper data gets to the calculation portion of our program.
Fixing File Processing Issues
When it comes to file processing it doesn’t take too long to understand how to write the code to read and write a file. But when it comes to implementing the process in a program it can be easy to make mistakes you don’t expect. These are two short videos that demonstrate that point.
Non-Default Mouse Events
While every object has a default event, every object also has a large number of non-default events. These are events available to the programmer to allow the object to act in some different way. Some of the most popular are “mouse” events. There’s MouseHover, MouseLeave, MouseDoubleClick, and others.
This short video shows how you can access them.
Multiple Forms
What is a multi-form application? It’s just like it sounds. Multiple forms. You’ve used them all the time and maybe just weren’t aware that they were multi-form. Your phone’s apps are a good example. There’s only so much real estate on a phone’s screen. And when you need to display a lot of information it makes sense to use a number of forms and only display what is relevant at the time.
This video gives you the basics. It shows how you can create a form. Add data to a form. Display multiple forms, and so on. And it’s pretty easy. PDF: Slides
The Image List Control
The ImageList control is a tool. But it’s a tool that contains an array. It allows you to store a number of images in your application and assigns an integer index to each picture. Using that index you can refer to the image list control from a Picture Box, a Label, a Button, any control that can accept an image. I used this concept when I created the video titled “How Numeric Variables are Stored” back in “The Basics” section of this site.
An array is involved. This video will show you how to set up the ImageList control and use it. In fact, we’ll build a simple Poker Hand. This will be a fun one.
Renaming Objects After Coding
There are times when we might misname a button control. No big deal if you haven’t written any code. Just rename it. But if you have written a bunch of code, changing the name is not quite so easy.
In my case I wrote a program and it worked just fine. But I needed to write a second program that was similar to the first. Well, I made a copy of the program and decided to modify it rather than starting all over. Turns out all I needed to do was change a function name in the code of three different buttons. But I wanted those button names to match the function I was coding. That meant renaming the buttons so I would have three new button events with names that matched the buttons.
This video shows you what I did:
The MessageBox
Click to enlarge
There are four parameters available in the MessageBox.Show method. They are: 1) the message itself; 2) a MessageBox title; 3) a set of buttons other than just the familiar “OK”; and 4) an icon that can express the type of message being displayed (informational, question, error and so on).
When you see the possible button configurations available with the MessageBox you will quickly see that the MessageBox can be an excellent way to let the user make a decision. And, based on that user decision, the application can proceed down several different tracks. Basically, the MessageBox is a visual "IF" statement. PDFs: Slides, Code