Syllabus

Home

Class Resources

News

Problem Solution Hints

Writing programs that solve problems can be confusing at first. If you are having difficulties then you might want to consider the following procedure.
  1. Make sure that you understand the problem. You cannot write a program to solve a problem if you do not understand what is being asked. As an aid you might want to write an algebraic equation that describes the solution. Or, you could just write out the steps required using english sentences. Writing down the input and output values may also be helpful.
  2. Analyze the solution and determine what quantities will be variables. In this course all information that is to be entered into text boxes will require variables. In addition you may have variables that hold intermediate results. And, you will normally have a variable that will hold the final result.
  3. Give your variables appropriate names (names that are easily recognizable for the information) and types. In this course we will deal with three types of information: Integer numbers (Positive or Negative whole numbers); Real numbers (numbers that contain both a whole part and a fractional part) and Textual information (names, addresses, or any non-numeric information). In Visual Basic integer information is declared as type Integer, real numbers can be either type Single or type Double. (The difference between Single and Double is that Double uses twice as much storage space and has greater accuracy.) And, finally textual information is type String.
  4. Now that you understand the problem you are ready to begin writing the program. At the top of your procedure (just beneath the "Private Sub" line) you should declare the variables using the VB Dim statement. For example: Dim age as Integer, or Dim First_Name as String, or Dim cost as Single.
  5. Following the variable declarations you will need to initialize the variables. This can be done by assiging a constant value to the variable or more commonly, by importing information from text boxes. You may also need to initialize other variables with numeric constants. e.g. PI = 3.14159. . Ex: Age = CInt(txtage.text) The CInt function converts information that is of type String to Integer - CSgl converts from String to Single and CDbl converts from type String to type Double. You cannot calculate the result until you have inported all of the required information and intialized all variables used in the computations
  6. When you have all of the input data you are ready to perform the calculations. Write one or more VB statements that calculate the result. You may need to compute several intermediate results along the way.
  7. Output the results to either a text box, list box or perhaps to a label in special cases.
  8. Test the program with several input values. Verify that the results are computed correctly.
  9. You should also use comments to describe the program and identify important steps that the program is taking.