visual basic examples for order form

Reviews
Shared by: Mark Hardigan
Stats
views:
174
rating:
not rated
reviews:
0
posted:
1/22/2009
language:
English
pages:
0
Introduction to Programming Using Visual Basic Lesson 3: Data and Variables Covering Hour 5: Putting Code into Visual Basic Hour 6: Message and Input Boxes Lecture Data and Variables What is data? Data is information. From “Hello, World” to your name to the number 6, all of this is data. A program’s main purpose is to process information or data. Without data your programs would not have much value. What is a data type? A data type is term used to describe the kind of information the data represents. The data type of “Hello, World” is string, while the data type of 6 is integer. What is the difference between literal and variable data? There are two classes of data: literal data (often referred to as constant data) and variable data. Literal or constant data is written directly into the program and cannot change for the life of the program. Variable data can be entered by the user, or obtained via other sources, and can change throughout the operation of the program. What are variables? Variables are locations in the computers memory where a program can store or retrieve variable data. What types of variables are there? The following are some variable types: Variable Type String Integer Currency Boolean Single, or Double Examples “Hello, World”, “Name” 6, 7, -1, 0 1.01, -10.30, 100.50 True, False 0.00000054, 100000000 What are variable naming conventions? Naming conventions are a method of documenting the meaning and type of a variable by giving it a useful prefix and name. The following are some prefixes that should be used with the variable types. Variable Type String Integer Currency Boolean Single Double Prefix str int cur bln sgl dbl What does it mean to declare a variable? Basic requires that all variables be declared prior to use. This means that you inform your program of the variable name and its data type. The following syntax shows how: Dim As Examples: Dim intYears As Integer Dim strName As String How do I assign data to a variable? In order to use a variable, it must contain data. To store the data in the variable you use an assignment statement. If you are assigning data to the variable for the first time, this is often called initializing the variable. The following syntax is for assigning data to a variable. Let = Examples: Let strName = “Carolyn” Let intYears = 2001 What are expressions? Expressions are things that must be evaluated. A single piece of literal data is an expression. A variable is an expression. Mathematical expressions are also valid (i.e. 8 + 10, intYears + 1) What mathematical operators are there in Basic? The following operators can be used: + (addition), - (subtraction), * (multiplication), and / (division). Do you remember the increment statement? What is concatenation? When you add two strings, they are concatenated so that the second string is placed at the end of the first. For example: Let strCaption = “Hello, “ + “World” strCaption would be equal to “Hello, World”. Message Box Message boxes are a quick way to get information to the user via a preprogrammed dialog box. Syntax: Example: Input Box Input boxes are much like message boxes except that they have a text box in them so the user can type text which can then assigned to a variable. Syntax: strAnswer = InputBox( strPrompt [, strTitle] [, strDefault] [, intXpos, intYpos]]]) Example: strAnswer = InputBox(“Type something here”) New Controls Shapes are simple filled or transparent figures that you can create on the form. Use shp as the first three letters for the name of any shape control you create. Timers are invisible controls that allow you to execute the same code at regular intervals. Use tim as the first three letters for the name of any timer control you create. IntButton = MsgBox( strMsg, [, [intType] [, strTitle]}) MsgBox(“Display this.”) Lab for Week 3: Mover Part 1 Create a New Project 1. Start Visual BASIC, select New Project from the File menu and create a Standard Exe 2. Save the Form to your floppy as mover 3. Save the Project to your floppy as mover Add Control Objects to your Form 1. Add a Label control: Double-click on the Label icon in the toolbox to automatically create the label on the form. Then move the label to where you want it to go, following the picture below. 2. Add a TextBox control: Double-click on the TextBox icon in the toolbox to automatically create the text box on the form. Then move the text box to where you want it to go, following the picture below. 3. Add a CommandButton control: Double-click on the CommandButton icon in the toolbox to automatically create a command button on the form. Then move the command button to where you want it to go, following the picture below. 4. Add a Shape control: Double-click on the Shape icon in the toolbox to automatically create a shape on the form. Then move the shape to where you want it to go, following the picture below. 5. Add a Timer control: Double-click on the Timer icon in the toolbox to automatically create a timer on the form. Then move the timer to where you want it to go, following the picture below. Now your form should look something like this: Set Properties for your Objects Use the property box on the right-hand side of the form to set the following properties for your controls: 1. Select the Label1 object. Change the Caption property to X Increment: 2. Select the Text1 object. Change the (Name) property to txtX and the Text property to 0. 3. Select the Command1 object. Change the (Name) property to cmdSet and the Caption property to Set Increment. 4. Select the Shape1 object. Change the (Name) property to shpMover and experiment with the other properties to produce the shape of your choice. Don’t make it too big! 5. Select the Timer1 object. Change the (Name) property to timMover and the interval property to 1000. 6. Select the Form1object. Change the (Name) property to frmMover and the Caption property to Mover. Declare your variables 1. Click on the code View button or select View Code from the menu to bring up the code window 2. At the top of the code window, add the following line: Option Explicit 3. Directly underneath this line, declare the following variables: intX, intY. Use the Dim statement to declare each of these variables on their own line. Initialize the Variables We will initialize this variable when the form loads or first comes up. In order to do this, we must handle the load event for the frmMover form 1. Select View Object to go back to the object window (so that frmMover is visible) 2. Double-click on the background of the form to generate code for the load event (Do not double-click on one of the objects on the form!) The code window will appear with the following lines in it underneath the lines you typed in: Private Sub Form_Load() End Sub Between these two lines, initialize all variables to 0 by using an assignment statement for each variable. Handle the Timer event We will use the timer to move the shape on the form. In order to do this, we must handle the timer event for the timMover timer. 1. Select View Object to go back to the object window (so that frmMover is visible) 2. Double-click on the timMover to generate code for the timer event. The code window will appear with the following lines in it underneath the lines you typed in: Private Sub timMover_Timer() End Sub 3. Between these two lines, type the following line: Let shpMover.Left = shpMover.Left + intX Handle the Button Click We will change the value of the increment when the user clicks on the cmdSet button. In order to do this, we must handle the click event for the cmdSet button 1. Select View Object to go back to the object window (so that frmMover is visible) 2. Double-click on the cmdSet to generate code for the click event. The code window will appear with the following lines in it underneath the lines you typed in: Private Sub cmdSet_Click() End Sub 3. Between these two lines, type the following lines: Let intX = txtX.Text Run the Program Click the Start button on the toolbar. Enter a number into the text box and then press the Set Increment button. Try 10, 50, then 100. Now try –10, -50, -100. Did it work? Part 2 Repeat the steps from part one to allow your mover to move up and down in addition to right and left. 1. Create another label and text box on your form for the Y increment. Set their (Name) and Caption/Text properties. 2. Modify the Load event handler, the click event handler, and the timer event handler to handle the Y increment. 3. Run your program and test the Y increment by itself. Did it work? 4. Now test your program by changing both increments at the same time. Did it work? Part 3 Enhance the functionality of your program 1. The user might find it helpful to know the position of shpMover even when it is no longer visible on the form. Create a new label on the form to display the position. 2. Add a Stop button and a Go button to start and stop the mover. In the click event handlers for these buttons, use the Enabled property of timMover to stop and start the mover. 3. Add a Restart button to move shpMover back into a starting position and reset the increments back to zero.

Related docs
Visual Basic
Views: 79  |  Downloads: 2
Visual Basic
Views: 187  |  Downloads: 0
Visual Basic
Views: 56  |  Downloads: 4
Programming Visual Basic NET
Views: 565  |  Downloads: 119
visual basic example
Views: 731  |  Downloads: 94
Visual Basic Tutorial
Views: 788  |  Downloads: 209
Visual Basic Fundamentals
Views: 245  |  Downloads: 15
The Visual Basic NET Coach
Views: 74  |  Downloads: 31
Overview of Visual Basic 9.0
Views: 70  |  Downloads: 13
Overview of Visual Basic 9.0
Views: 55  |  Downloads: 11
Visual basic 6 tutorial
Views: 1707  |  Downloads: 108
A Comparison Of Visual Basic NET And C
Views: 24  |  Downloads: 9
Software Development And Visual Basic NET
Views: 76  |  Downloads: 30
premium docs
Other docs by Mark Hardigan
Employment Offer Letter Exempt Employee
Views: 813  |  Downloads: 18
Ford Motor Co Ammendments and Bylaws
Views: 182  |  Downloads: 1
Employee Promissory Note
Views: 484  |  Downloads: 3
Interview Questions to Ask Job Candidates3
Views: 1038  |  Downloads: 115
china paper1
Views: 231  |  Downloads: 2
Customer Satisfaction Survey
Views: 905  |  Downloads: 67
Three Contributions to the Theory of Sex
Views: 386  |  Downloads: 14
Board Resolution Setting Record Date
Views: 169  |  Downloads: 1
Real property lease checklist
Views: 452  |  Downloads: 6
Tom Brown Inc Ammendments and By laws
Views: 161  |  Downloads: 3
Articles of Incorporation California
Views: 359  |  Downloads: 8
Agreement-Trade Name License Agreement
Views: 337  |  Downloads: 13