PROGRAMMING EXERCISE

Daily Menu Planner

 

Description:

      Provide the user with the capability to plan his or her daily menu by selecting foods for breakfast, lunch, dinner, and snacks from a master list of foods. The user will decide at the beginning of each session whether they wish to track calories, fat, carbohydrates, protein, or cholesterol.  The program will then monitor this quantity and present the total of that quantity for each meal as well as for the whole day.

 

Input File:

      The input file for this program is a sequential file called FOODLIST.DAT, which is available from your instructor and should be copied into the same directory as your project.  The first two records of the file consist of headings and should be ignored by the program (just read past them).  The data records consist of fixed-width fields, in the following format (for this program, we are not concerned with the last two fields):

 

Field

Record (byte) positions

Target Data Type

Food description

1 – 30

String

Serving Size

31-40

String

Fat (grams)

44-48

Integer

Calories

53-58

Integer

Carbohydrates (grams)

65-70

Integer

Protein (grams)

76-79

Integer

Cholesterol (mg)

84-89

Integer

Weight (grams) [not used in this project]

93-99

Single

Saturated Fat (grams) [not used in this project]

103-108

Single

 

      If you wish, you can view the contents of this file by opening it in WordPad or MS-DOS EDIT.

 

      To read a record from the file, you should use the Line Input # statement to read the entire record into a string variable.  Then, using VB string functions, break up the string variable into separate variables representing the fields of the record

 

Program Operation:

 

·         Present the user with a combo box containing the following items: Calories, Fat, Carbohydrates, Protein, and Cholesterol.  Pre-select Calories for the user as a default.  Whatever the user selects from this combo box is the item that will tracked by the program.

 

·         Your interface should contain list boxes for the following: master food list, breakfast, lunch, dinner, and snacks.  Command buttons should also be provided to add or remove items from the breakfast, lunch, dinner, and snack list boxes.

 

·         Load the master food list box from with the food description concatenated with the serving size from the input file.  In addition, the food count item selected by the user (calories, fat, carbos, etc.) should be loaded into this listbox's ItemData property.

 

·         The user should be able to select one or more items from the master food list.  When the user clicks the "Add to Breakfast" (or Lunch, Dinner, or Snacks) button, the items selected from the master food list should then appear in the listbox for that meal.  A label next to the listbox for that meal should display the total of the food count selected for this run (calories, fat, etc.).  In addition, a running total for all meals should be displayed at the bottom of the form.

 

·         The user should be able to remove items from the meal listboxes.  When the user selects items from a meal listbox and clicks the "Remove" button for that meal, the selected items should disappear from that listbox, and the calorie count  (or fat count, or whatever) should be subtracted from that meal's total and from the running total.

 

·         When the user clicks the Print button, print a simple report showing the user's food selections for each meal, along with the food count totals for each meal and for the whole day.

 

To give you an idea of what the forms should look like, I have provided screen shots of my solution to the project. Feel free to vary the design according to your liking, as long as you meet the project requirements.

 

Splash Screen:

 

 

 

Selection Screen:

 



 

Main Screen:

 

 

 

 

 

 

 


Notes on Printing:

 

Sample report output is shown on the next page.  To print a hard copy report in VB, you use the Printer object.  Print your formatted lines of output using the Print method of the Printer object – your statements would begin with Printer.Print ...  Use the printing and formatting techniques discussed earlier in the course.

 

Before you begin generating output lines, you should include the following statements in your code:

 

       Dim intX    As Integer

 

    ' Have the user make sure his/her printer is ready ...

    If MsgBox("Make sure your printer is on-line and " _

            & "loaded with paper.", vbOKCancel, "Check Printer") = vbCancel Then

        Exit Sub

    End If

   

    ' Set the printer font to Courier, if available (otherwise, we would be relying on the

    ' default font for the Windows printer, which may or may not be set to an appropriate

    ' font) ...

    For intX = 0 To Printer.FontCount - 1

        If Printer.Fonts(intX) Like "Courier*" Then

            Printer.FontName = Printer.Fonts(intX)

            Exit For

        End If

    Next

   

    Printer.FontSize = 10

   

    Printer.NewPage

 

   ' "Printer.Print" statements would begin here ...

 

   ' When you are done generating the output lines, be sure to include the following

   ' statement:

    Printer.EndDoc


 

Sample Report Output:

 

  

                Daily Menu Planner for October 13, 1999

 

 

              Food                                         Calories

              ----                                         --------

 

Breakfast     ALL-BRAN CEREAL (1 OZ)                           70

              BANANAS (1 BANANA)                              105

              MILK, SKIM, NO ADDED MILKSOLID (1 CUP)           85

                                                           ------

                                                              260

 

Lunch         TUNA, CANND, DRND,WATR, WHITE (3 OZ)            135

              LETTUCE, CRISPHEAD, RAW,WEDGE (1 WEDGE)          20

              TOMATOES, RAW (1 TOMATO)                         25

              ITALIAN SALAD DRESSING,LOCALOR (1 TBSP)           5

                                                           ------

                                                              185

 

Dinner        CHICKEN, ROASTED, BREAST (3.0 OZ)               140

              POTATOES, BAKED WITH SKIN (1 POTATO)            220

              VEGETABLES, MIXED, CKED FR FRZ (1 CUP)          105

                                                           ------

                                                              465

 

Snacks        APPLES, RAW, UNPEELED,2 PER LB (1 APPLE)        125

              PRETZELS, TWISTED, THIN (10 PRETZ)              240

                                                           ------

                                                              365

 

                                                           ------

                                            TOTAL            1275

 

 

 

Solutions

 

This coding for this project can be greatly simplified if control arrays are used for the "meal" listboxes, their corresponding "add" and "remove" buttons, as well as the labels that display the food count totals. However, you may find it instructive to look at or try a non-control array approach first – then you can truly appreciate the amount of work the use of control arrays would save you.

 

Download the non-control array solution for this project here.

 

Download the control array solution for this project here.