Visual Basic
02 Formatted Output Programs

In this unit, you will learn to format your output in a variety of ways including:

  1. sending the output to a label by concatenating a string using the ampersand character "&",
  2. sending the output to columns using the tab() function,
  3. sending output to the printer, and
  4. formatting numbers with specific decimal places and dollar format using the format() function.

Please read the sections in the VB Help Index related to the format function (examples) and the tab function. Read the EndDoc and NewPage information in the help sections relating to printer commands. If you really care to learn about printer commands, you might check out such things as underline, fontbold, etc. These control the way print is sent to the printer.

Notes


The ampersand character "&" is used to concatenate (add) strings together to form a sentence. The advantage is that I can now put my output into a label box on the form which will word wrap and never run off of the screen. To make this happen:

  1. Create a label box and name it something like lblAnswer.
  2. In your source code, use the line something like lblAnswer.caption = "Driving " & format(miles) & " using " & format(gallons) & " of gas is " & format(miles/gallons) & "mpg."

The end result is that the sentence is placed into the caption of the label box named lblAnswer.


Using the printer:

  1. Any valid line in a print statment may be used in a printer command.
  2. Use a Printer.Print command to send the output to the printer.
  3. Use a Printer.EndDoc command at the end of every document to send the output to the printer and end the print job.
  4. Always include a Printer.Print "YOUR NAME" prior to the Printer.EndDoc command in the printout so that we can determine to whom the page belongs.
  5. A Printer.Print command with no other data on the line will send a blank line to the printer.
  6. A semi-colon (;) tells the printer to continue on the same line. When a print line ends without a semi-colon, the printer will begin the next print statement on a new line.


Assignments

Name the programs 02???#. The 02 indicates we are now in unit 2 and ??? is your three initials with # as the program number. Use a separate form for each problem.

Make the form caption be your name and the program number such as "Your Name - Output n".

1. Write a program that uses text boxes to enter the whole number, numerator and denominator of a mixed fraction and prints the decimal value of the fraction with 4 decimal places. An example would be:

2. Write a program which will use inputboxes to input the interest rate as a percentage, principal and time. Find the amount of simple interest earned. Display the interest earned in a label. All money values should be in $ format.

3. Write a program which will use text boxes to input the item name, cost, and quantity. Using a tax rate of 6.0%, create a chart in the following format.

Name

Cost

Quantity

Subtotal

Tax

Grand Total

Jacket

$34.00

4

$136.00

???

????

Use two command buttons on this form. One should print the information to the chart on the form. The second should print the information to the printer in table form using the tab() function. Make sure your name and block number is printed on the paper as discussed in the notes section.

4. Write a program which would use an intputboxes to enter the distance travelled in feet and the time in seconds. Determine the speed in mile per hour to two decimal places.

Visual Basic Assignment Page

 
51837
 
© 2004-2008, Jerel L. Welker
Page Updated: January 15, 2009