Presentation is loading. Please wait.

Presentation is loading. Please wait.

More Visual Basic!. Creating a Standalone Program A standalone program will allow you to make a program file that can be run like other Windows programs,

Similar presentations


Presentation on theme: "More Visual Basic!. Creating a Standalone Program A standalone program will allow you to make a program file that can be run like other Windows programs,"— Presentation transcript:

1 More Visual Basic!

2 Creating a Standalone Program A standalone program will allow you to make a program file that can be run like other Windows programs, without Visual Basic being loaded.

3 Open your last VB program that you have saved to your disk. Choose Make (name of your program) from the File menu. Save to your disk. Choose A:\ Change the file name within the Make Project dialog box to VBStandalone and click the OK button. After the EXE file is created, exit Visual Basic. Double-click the MyComputer icon and open VBStandalone file on your disk.

4 Performing Calculations in Visual Basic Operators Are symbols that perform specific operations in Visual Basic Statements

5 Mathematical Operators OperatorDescription =Assignment +Addition -Subtraction *Multiplication /Division \Integer division ModModulus

6 Creating Label Controls Label Control Is used to place text on a form Sometimes is used to identify a text box Sometimes is used to add a title Sometimes is used to add a message Cannot be changed by user Also can be used to provide output

7 Creating some labels! 1.Open Visual Basic. 2.Open New Standard EXE project. 3.In the properties window, give the new form the name frmAddition and the caption Addition. 4.Insert a label and click the Caption property. 5.Key in your name for the label. 6.Name your label lblMyName. 7.Save the project with the form named frmAddition and project name Addition.

8

9 1.Insert another label on the form. 2.Position it in the center of the form. 3.Change the caption of the label to the number zero (0). 4.Change the name of the new label to lblAnswer. 5.Insert a command button. 6.Name the command button cmdCalculate. 7.Change the button’s caption to Calculate. 8.Add code in code view window. lblAnswer.Caption = 16 + 8 9.Close the code view window and run your program.

10

11 Using Text Boxes and the Val Function Text boxes Are the fields placed on dialog boxes and in other windows that allow the user to enter a value. The text property of a text box specifies what text will appear on the text box.

12 Text –vs-Numeric Data Text Boxes Accept data from the user. Comes in the form of text. Includes letters, symbols, and numbers. Numeric Data Numbers in a text box must be converted to a true numeric value before they can be used in a calculation. The conversion used to convert to numbers is the Val Function!

13 The Val Function Takes numbers that are in a text format and returns numeric value that can be used in calculations. Example: lblTotal.caption = Val(txtPrice.Text) + Val(txtSalesTax.Text)

14 Splitting Code Statements Among Lines When splitting a line of code among two or more lines use a underscore (_)! Example: lblTotal.caption = Val(txtPrice.Text)+_ Val(txtSalesTax.Text) The underscore is called _______?_______ and it tells the compiler to skip to the next line and treat the text there as if it were part of the same line.

15 Comments! The apostrophe ( ‘ ) at the beginning of the code tells the compiler to ignore everything that follows. Example: ‘ Calculate total expenses.

16 Profit and Loss Program 1.Open your profit&loss program. * Need to make an adjustment before we begin to type code. We need to change some of the text boxes to labels before we continue.

17

18 Name your labels, command buttons, and text boxes. See handout! Double-click the Calculate button. Add code to Calculate the total expense. 'Calculate Total Expenses lblTotalExp.Caption = Val(txtRent.Text) + Val(txtPayroll.Text) + _ Val(txtUtil.Text) + Val(txtSupp.Text) + Val(txtOther.Text)

19 3.Add code to calculate profit. 'Calculate Profit lblProfit.Caption = Val(txtRev.Text) - Val(lblTotalExp.Caption) 4.Add code to calculate loss. 'Calculate Loss lblLoss.Caption = -Val(lblProfit.Caption)

20 5.Add code to calculate expense percentages. 'Calculate Expense Percentages lblRentPerc.Caption = Fix(Val(txtRent.Text) / _ Val(lblTotalExp.Caption) * 100) lblPayrollPerc.Caption = Fix(Val(txtPayroll.Text) / _ Val(lblTotalExp.Caption) * 100) lblUtilPerc.Caption = Fix(Val(txtUtil.Text) / _ Val(lblTotalExp.Caption) * 100) lblSuppPerc.Caption = Fix(Val(txtSupp.Text) / _ Val(lblTotalExp.Caption) * 100) lblOtherPerc.Caption = Fix(Val(txtOther.Text) / _ Val(lblTotalExp.Caption) * 100)

21 6.Add code to exit button. END 7. Save your program. 8. Run your program. 9. Key the following data into the your program. Rent350 Payroll 600 Utilities200 Supplies 100 Other50

22 10.Debug your program if needed. 11.Insert your name. 12.Print your program (all 3 copies). 13.Turn in your program for credit. The End!

23 Homework! 1.Page 78 – True and False questions. 2.Page 78 – Written Questions. 3.Study for Quiz on Friday!


Download ppt "More Visual Basic!. Creating a Standalone Program A standalone program will allow you to make a program file that can be run like other Windows programs,"

Similar presentations


Ads by Google