Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 01 Forms in excel Tahani ALdweesh 1. 1. Insert form into your project. 2. Change form’s properties. 3. Put controls on the form. 4. Change controls’

Similar presentations


Presentation on theme: "Lab 01 Forms in excel Tahani ALdweesh 1. 1. Insert form into your project. 2. Change form’s properties. 3. Put controls on the form. 4. Change controls’"— Presentation transcript:

1 Lab 01 Forms in excel Tahani ALdweesh 1

2 1. Insert form into your project. 2. Change form’s properties. 3. Put controls on the form. 4. Change controls’ properties. 5. Write code. 6. Use Show method to display the form. Tahani ALdweesh 2

3 VBA : Standard programming language for office programs. Can be used in any office applications in same way. As you do more work with VBA you will need to use VBE(Visual Basic Editor ), Tahani ALdweesh 3

4 :The Visual Basic Editor (VBE) is the environment in which you work with VBA programming code. Tahani ALdweesh 4

5 5 -Open Microsoft Excel - Tools > Macro > Visual Basic Editor (2003) ALT + F11.user form < -insert

6 Tahani ALdweesh 6 Project window properties window User Form Work Area

7 Project window: shows a hierarchical view of the contents of the current VBA project view  project explorer or Ctrl+R Properties window: shows the various properties available for whatever object that is highlighted view  Properties window or F4 User form window : the design area,the toolbox will appear by default insert  user form Code window: where the procedures take place view  code or F7 Work area: the rest of the VBE Tahani ALdweesh 7

8 Properties are the physical descriptions of all Excel objects, and the description of the particular property is called the value of the property. Contains detailed information about any selected part of a project in.the Project Explorer Tahani ALdweesh 8

9 9 ToolBox

10 Label: used to instruct the user Textbox: enables the user to enter textual info. List box: list of choices. Checkbox: allow you to choose more than one option. Combo box: is so named because it combines the function of textbox and a list box. Option buttons: restricts the user to one choice. Frame: used for: 1-groups option buttons 2-visually, arranging different portions of the form Tahani ALdweesh 10

11 In term of VB, variables are areas allocated by the computer memory to hold data. Like the mail boxes, each variable must be given a name. To name a variable in Visual Basic, you have to follow a set of rules. Tahani ALdweesh 11

12 variables The following are the rules when naming the :in Visual Basic It must be less than 255 characters. Must start with a letter (a to z, A to Z). It must not begin with a number. No spacing is allowed. Can contain any number of letters or digits (a digit is 0 to 9). Can contain the underscore. Tahani ALdweesh 12

13 Invalid nameValid name My.bookMy_book 1studentSchool *&fatherBoy_&hifather Tahani ALdweesh 13

14 Declaring Variables In Visual Basic, one needs to declare the variables before using them by assigning names and data types. They are normally declared in the general section of the codes' windows using the Dim statement. The format is as follows: Dim Variable Name As Data Type Tahani ALdweesh 14

15 Dim password As String Dim yourName As String Dim firstnum As Integer Dim secondnum As Integer Dim total As Integer Dim doDate As Date You may also combine them in one line, separating each variable with a comma, as follows: You may also combine them in one line, separating each variable with a comma, as follows: Dim password As String, yourName As String, firstnum As Integer Tahani ALdweesh 15

16 Constants are different from variables in the sense that their values do not change during the running of the program. Declaring a Constant Const Constant Name As Data Type = Value : Example Const Pi As Single=3.142 Const Temp As Single=37 Const Score As Single=100 Tahani ALdweesh 16

17 After declaring various variables using the Dim statements, we can assign :values to those variables. The general format of an assignment is Variable=Expression variable or a control property value The variable can be a declared variable or a control property value. mathematical expression, a number, a string, a Boolean value (true or false) and more. The expression could be a mathematical expression, a number, a string, a Boolean value (true or false) and more. Tahani ALdweesh 17

18 firstNumber=100 secondNumber=firstNumber-99 userName="John Lyan" userpass.Text = password Label1.Visible = True Command1.Visible = false Label4.Caption = textbox1.Text ThirdNumber = Val(usernum1.Text) total = firstNumber +secondNumber+ThirdNumber Tahani ALdweesh 18

19 Tahani ALdweesh 19

20 Private Sub CommandButton1_Click() Dim rad As Double rad = Val(TextBox1.Text) Dim area As Double area = 3.17 * rad * rad TextBox2.Text = area End Sub Private Sub CommandButton2_Click() UserForm1.Hide End Sub Tahani ALdweesh 20

21 Tahani ALdweesh 21


Download ppt "Lab 01 Forms in excel Tahani ALdweesh 1. 1. Insert form into your project. 2. Change form’s properties. 3. Put controls on the form. 4. Change controls’"

Similar presentations


Ads by Google