CSCI 220 Computer Programming with Visual Basic
Lecture 11: Grids, Combos, and the Common Dialog (Oh, My!)

Combo Boxes
  What are they?
     Something like a multiple label or text box
     In essence, hold a text box or label array, though you
     don't necessarily define one
  Flavors
     List Box
       Like labels, can be read by user but not written to
       Used to choose from a limited number of options
       designated by programmer
     Combo box
       List box with Text box at top.
       User can choose like a list or add new info like a
       text box.
     Standard
       As large as programmer defines it.
       Multiple lines may be visible on screen when box is
       NOT the focus
     Drop Down
       Usually shows as only one line
       When User clicks, other lines become visible
  The AddItem Method
     Used to add a value to a combo or list box
     Usually used in form load
     
The Grid
  Also like an array of labels, this time TWO DIMENSIONAL
     Characteristics:
       Frequently used as a spreadsheet or data table
       Cannot be directly edited by user
     Properties
       Row:  Current Row
       Col:    Current Column
       Text:  Text of cell at current row and column
       ColWidth(ColNum): Width of column ColNum
     Working with Grids
       Set the col and row you want to work on
         use code: grid1.Row = 5
         Let user do it through mouse input
       Set text property directly in Grid1_keypress
         Grid1.Text = Grid1.text + chr$(KeyAscii)         
       Set text indirectly through text box or list box
         Grid1.Text = Text1.Text
         For list box, code goes in change and click procedures
         In Text Box, Change is all you need

Program design considerations:
  Getting help
     Use the Search command on help menu or...
     Type a keyword, place the cursor on that word, and
     press F1 key
     Don't be afraid to experiment.
  Steps for designing a program
     Define the program in English:  What will it do?
     Sketch out a design for the program's main form(s)
     Determine what controls will be used to solve the
     problem.
     Write (in English) what will happen when the user
     activates key controls
     Translate those directions into more precise pseudocode
     Translate pseudocode into Code
     Test and Debug
     
     
Debugging
  Run your program
  Try different input methods
  Try to mess it up
Errors will happen
Tracing crashes
  Look at what was happening on screen when program crashed
  Try to anticipate what code was operating.
  Guess what went wrong.
  look carefully at error message
  Press F1 for help if you don't understand
  look at where cursor is when you are returned to code.
  Note that computer sets point where it NOTICED error,
  NOT necessarily where error OCCURRED
Bugs
  Program doesn't crash outright, but still doesn't perform
  as you expected
  Follow same technique as for crashes
  Print values of appropriate control variables to screen,
  temp labels
  Use of DEBUG window
  Debug menu Watch etc.

Your Project: The Checkbook. (VB11)

Write a simple spreadsheet that will allow the user to type
in a checkbook with a number of deposits and withdrawals.
The checkbook should look something like this:
[Image of form]
The user should be able to choose from a list of
descriptions in the list box.  Whichever item the user
selects should automatically go in the current cell.
The program will not automatically calculate, but will
calculate when the user selects the appropriate button.

You should have code that accomplishes the following tasks:
  Initialization:
     Set the grid column widths to appropriate values.   The
     Description column should be wider than the other
     columns
     Set the captions of the columns.  Use the Row, Col, and
     Text properties to do this
     Add possible items to the list box.
  Calculate
     When this button is pressed, calculate the balance
     according to the algorithm we developed in class.
  List Box
     When the user clicks on or changes the value of this 
     control, copy the current
     text value of the list box to the Description column,
     current cell.
  Quit
     I don't have to tell you what to do here.
If you get that working, try to make code that does the
following:
  Save
     Get a filename from the common dialog box
     Save all the elements of the grid to a sequential
     access file in this special format:
     Step through each cell in the row adding cells to a
     temporary string variable
     Seperate the cells by a Tab character CHR$(9)
     Write the row to the disk file
     go to the next row
  Load
     Get a filename from the common dialog box
     Make the grid one row deep
     Open the file for random access
     Step through the file one record at a time using
     ADDITEM to add the row to the grid
Save the program as VB11.MAK
Have a good time!
Return to Syllabus