VariablesProgramming is a process that requires us to organize our actions into three stages. These are:
- Entering information into the program.
- Processing the entered data.
- Outputing the results to a screen or a printer.
Inputs Necessary for Loan Calculation
- The amount of the loan.
- The current interest rate.
- The duration of the loan.
The question is what do we do with each datum entered so that we will have it when we are ready to perform the calculation. The answer is simple. We put it in a safe place where we can go back and get it whenever we need it. If programming terms that 'safe place' is called a variable.
The beginning programmer in Visual Basic will usually say: "Well it is in a safe place, it is in the textbox where the user entered it," or "It is in the radiobutton which the user selected." They are correct, but only partly. In a simple programming we can indeed leave our data on the form and expect it to be there when we need it. However, as a person learns more about programming you learn that there are advantages to making a copy of the data which has been entered and storing it in a place which will not permit the user to accidentally change or remove it. The only real disadvantage is a bit of extra coding to create the variable and store the information in it.
Some of these adavantages are:
- Data stored in a textbox is a string. If it is to be used as a number it must first be converted from string data type to one of the number data types. If we leave the data in the textbox then this conversion must be done everytime the data is needed. So the question is: should you do this conversion every time you need the datum or do it once and store the number as a number? Experience has shown that fewer conversions are more efficient and safer because there are fewer opportunities for errors to occur.
- By storing the data we want to keep track of, we are certain to have it when we need it. A form's main purpose is to allow the user to input data, and to display output, not for holding or storing data. Information in textboxes and radiobuttons could be changed by the user. If we do not store the data we need to keep track of, it may not be there when we need it because it may have been accidentally or deliberately altered by the user. By placing the data in a variable we can control it better preventing the accidental or deliberate changing of our data.
- Separating the entry of the data from the storage of the data allows us to check each time data is entered to see if it is the right kind of data. If it passes the error checks then we can store it in a variable. This way we are only asking our program to do one thing at a time. This is an approach which has been proven to be a more reliable way to do things for over fifty years.
- Processing is sometimes done in stages. If we continually convert our data from number to string and back again we can lose precision. We should convert between data types as seldom as possible. Ideally that means twice: once just after the data is entered and second when we display the result for the user. The best way to do this is to use variables for data storage.
- Q The data which has been input is stored in a textbox but it is not text data.
- A Create a variable then convert the date to the proper data type and store it in that variable.
- Q You have two numbers stored in two variables. How do you swap the numbers?
- A Declare a third variable. Move second number into the third variable. Move first number into second variable. Now move second number, currently located in the third variable, into first variable.
- Q You need to keep track of whether the data in your program has changed so that you will know whether the file needs to be saved.
- A Declare a boolean variable and name it appropriately e.g. fileNeedsSaving When this variable is set to
Truethe flie needs to be saved and when set to
Falseit does not need to be saved. Now use this variable to note when your file needs saving. For example when we add data the file needs saving, When the file has just been saved it does not need saving.
Solving People ProblemsActually this article is not about solving people’s problems, it is about how to get people to do what you want them to do. The simplest context is that of working in a business, but the process is also applicable to personal situations. The central issue is how do you get someone to do what you want done? There is a rational process for doing this. It does require their cooperation, but assuming you have a common objective this is posible and does not have to invole blackmail or any other illeagal or immoral activity.
The BasicsGiven a situation in which someone did not do what you wanted them to do, how do you get them to change their behaviour so they will do what you want rather than repeat the undesireable behaviour. If someone does not do as you want them to do, there are only two possible reasons for their behaviour.
First: they cannot do what you want them to do because they lack the ability to do it.
The first is an ability problem. They literally can not do what you want them to do. A quick example should help qualify this situation. If you are confronted by a robber who holds a gun to your head and demands that you give them a $100 bill. In this situation most of us want to do as the robber demands. We want to live! We are motivated! If we do not have the required bill giving the robber one hundred dollars will not do—he wants a one hundred dollar bill. Assuming you do not carry one hundred dollar bills on your person, this is an ability problem, No matter how much we want to do it we cannot because we do not have the demanded banknote.
Second: they want to do something else because they lack motivation to do what you want done.
The second situation is a direct clash of our desires and their desires. Here we must point out that you can only negotiate this situation if you do indeed have a common objective. We need to jointly examine the consequences of performing or not performing the desired behaviour. One person’s wants will prevail in this situation. In other words we will have a consequence off to determine whose wants will become uppermost. We want to motivate the other person to do what we want done.
CommunicateSo our first action in our hypothetical situation mentioned above is to find out why the other person did what they did. We need information from them to understand which of the two possble reasons explain their behaviour. They we can determine what course of action we need to follow to change their behaviour.
However, two common obstacles commonly arise at this point. Let me illustrate with a couple short examples. Let us say an employee was late for work one morning and their supervisor catches up with them later that morning. What does the supervisor say?
"That was a bonehead move you pulled this morning!"
The employee now has to interpret this comment and respond. Several thoughts and responses are possible:
- What did I do? There is uncertainty because the supervisor did not spell out the topic of discussion. Lack of specificity is hampering the communication. Some supervisors actually do this deliberately with the mistaken idea that a fishing expedition is good policy because it might turn up something they did not previously know about. In the long term baiting employees in this manner only causes them to clam up and say the minimum possible. The less that is said the harder time we have determining whether their problem is an ability problem or a motivation problem.
- What does he know about? This is one step more paranoid than the above and also reduces the quantity and quality of the communication. Again we have determining whether their problem is an ability problem or a motivation problem.
- Bonehead move? who does she think she is?’ This is the other main problem because now the employee will become defensive. How much communication takes place when we are defensive?
"Bill you were fifteen minutes late for work this morning, Help me understand what happened."
This is specific. Bill knows exactly what his supervisor is asking of him. It also invites Bill to share information rather than judging him or threatening him. The very fact that his supervisor brings it up also tells him that it matters and that he should not be late. Whatever Bill's reason for being late, the supervisor has invited a response and has not threatened him. Naturally, to be effective this message must be consistent in words, as well as in tone of voice and in non-verbal behaviour.