INSTRUCTIONS FOR CREATING THE CUSTOMER INFORMATION INPUT FORM

We will now construct the Customer Form, which will we store in a file called FRMCUST.FRM and we will nickname this file FRMCUST. Why do we need to nickname this form FRMCUST? Because off the title form menu option MnuFileOpenNotes, we told visual basic to display: If the user hits open-notes: FRMCUST.SHOW FRMTITLE.HIDE The customer form has 14 objects:
  1. Form (default)
  2. Label “Customer Information”
  3. Label “Name:”
  4. Label “Address:”
  5. Label “City:”
  6. Label “State:”
  7. Label “Zip:”
  8. Textbox for Name
  9. Textbox for Address
  10. Textbox for City
  11. Textbox for State
  12. Textbox for Zip
  13. Command Button for “Okay” to send user to the notes form
  14. Command Button for “Exit” to send the user back to the main menu
OBJECT PROPERTY VALUE 1.Form Caption Customer Info Name Frmcust 2.Label Caption “Customer Information” Autosize True Fontsize 24 3.Label Caption “Name:” Autosize True Fontsize 12 4.Label Caption “Address:” Autosize True Fontsize 12 5.Label Caption “City:” Autosize True Fontsize 12 6.Label Caption “State:” Autosize True Fontsize 12 7.Label Caption “Zip:” Autosize True Fontsize 12 For the textboxes, it is vital you name them correctly because we will use these names during the programming code! 8.Textbox for Name: Name TxtName Fontsize 12 Text (put in blanks) 9.Textbox for Address: Name TxtAddr Fontsize 12 Text (put in blanks) 10.Textbox for City: Name TxtCity Fontsize 12 Text (put in blanks) 11.Textbox for State: Name TxtState Fontsize 12 Text “WY) 12. Textbox for Zip: Name TxtZip Fontsize 12 Text (put in blanks) For the Command Buttons: 13. Command Button for “Okay” to send user to the notes form: Name CmdOK Caption Okay 14. Command Button for “Exit” to send the user back to the main menu Name CmdExit Caption Exit To complete the form, we must program what we want Visual Basic to do in response to the user. We need to specify two things: 1. What do we want the user to do when they click on the Exit button? We want to hide the customer form and show the title form: FRMTITLE.SHOW FRMCUST.HIDE 2. What do we want the user to do when they click the Okay button? We want to verify that the user filled in all the text boxes: If they did not fill in all the text boxes, we want to display a message: “Please complete customer information form” Else if they did complete all the information: We want to load the notes form, copy all the information entered on the customer form to the note form, and hide the customer form.

VARIABLES

To do all this coding, we are going to create some new variables. Variable: A placeholder that stores data in RAM for you. Variable Name: A name that the computer will you to store and locate the value of the variable. Variable names converts to an address in RAM Variable Value: The actual contents of a variable In programming, you put a new variable on the left hand side of the equation and then assign its value on the righthand side of the equation: Variable Name = Variable Value Lastname= “Lacity” Counter = 5 Notice that alphanumeric variables use “ ” whereas numeric variables do not. Visual basic automatically starts building variables for you. Assume the user enters the following on the FRMCUST Name: Mary Lacity Address: 4356 Lindell City: St. Louis State: MO Zip: 63402 Visual Basic creates the following variables in RAM: TxtName.Text = “Mary Lacity” TxtAddr.Text = “4356 Lindell” TxtCity.Text = “St. Louis” TxtState.Text = “MO” TxtZip.Text = “63402” Notice that the variable names are a concatenation of the object name and the property type. Object name: TxtName Property type: Text Notice the variable value is equal to the property value: “Mary Lacity” Back to out visual basic assignment, I am going to create three variables that will correspond to the three lines on the top of the FRMNOTES form. I will create these variables to eventually tell Visual Basic where to put the name, address, city, state, and zip on the FRMNOTES Line1 = TxtName.Text Line2 = TxtAddr.Text Line3 = TxtCity.Text & “,” & TxtState.Text & “ “ & TxtZip.Text I am also going to create a variable for a carriage return: NL = Chr(13) & Chr(10) (See page 198 of your Visual Basic textbook--this isn’t such an obvious command, trust me on this one.” Now I am ready to specify how to layout all the variables gathered on FRMCUST to FRMNOTES: Frmnotes.TxtCustomer.Text = Line1 & NL & Line2 & NL & Line3 This will place our information as follows: Mary Lacity 4356 Lindell St. Louis,MO 63402 The coding to make sure the user fills in all the text boxes is: IF TxtName.Text = “” OR TxtAddr.Text =“” OR TxtCity.Text = “” OR TxtState.Text = “” OR TxtZip.Text = “” THEN Msgbox “Please Complete The Customer Information Form” ELSE FRMCUST.HIDE ENDIF Note: The VISUAL BASIC editor wants the IF -THEN portion all on 1 line When will the IF expression be true? When one or more of the statements are true. Thus, only one of the fields has to be blank for the expression to be true. When the expression is true, the THEN portion of the IF command is executed. Msgbox “Please Complete The Customer Information Form” When the expression is false, the ELSE portion of the IF command is executed: FRMCUST.HIDE The last piece of coding we will do for FRMCUST is known as a load event.

Load Event

Description: Occurs when a form is loaded as the result of a reference to an unloaded form's properties or controls. Syntax: Sub Form_Load ( ) Remarks Typically, you use a Load event procedure to include initialization code for a form. For example, specifying default settings for controls, indicating contents to be loaded into combo boxes or list boxes, and initializing form-level variables. In code, when you reference a property on an unloaded form, the form is automatically loaded, but is not automatically made visible until you either use the Show method. For our example,we will use: Sub Form_Load ( ) FrmNotes.Show To get to this Sub Form-Load window in Visual Basic, put your cursor anywhere on the form where there are now objects and double click. Be sure to save this form as FRMCUST.FRM Note: Check the tab properties on your text boxes. You want the user to go to the name textbox first, the address second, the city third, the state forth, zip fifth.