Presentation is loading. Please wait.

Presentation is loading. Please wait.

05/09/20151 1.1 Introducing Visual Basic Sequence Programming.

Similar presentations


Presentation on theme: "05/09/20151 1.1 Introducing Visual Basic Sequence Programming."— Presentation transcript:

1 05/09/20151 1.1 Introducing Visual Basic Sequence Programming

2 205/09/2015 Learning Objectives: What a visual Basic Project is made up of. How to build a program. Name some examples of controls. Name a common event and understand what they do. What the ‘=‘ sign is used for.

3 305/09/2015 Program 1.1 Display My Name Specification: Specification: Display your name on a form in large letters at the click of a button. Display your name on a form in large letters at the click of a button.

4 405/09/2015 Program 1.1 Display My Name 1.Launch Microsoft Visual Basic 2005 Express Edition. 2.Create a New Project.

5 505/09/2015 Program 1.1 Display My Name 3.Save with name ‘Display My Name’. 4.Click the Toolbox and click Auto Hide. This will stop the Toolbox from collapsing.

6 605/09/2015 Design View Form 1 Properties Window

7 705/09/2015 Program 1.1 Display My Name 5.Hover over and examine the ‘Common Controls’ and ‘Containers’. 6.Try clicking some controls and placing them on form1 but delete them before moving onto the next slide.

8 805/09/2015 Properties  All controls have properties. Descriptive features of controls. Descriptive features of controls. Form 1 Properties Window

9 905/09/2015 Properties  Change the Text property of the form to ‘Display My Name’.  The Text property simply dictates what text is displayed in the form’s header.

10 1005/09/2015 Labels 1.Add a label control to the form. 2.Change the BorderStyle property to ‘FixedSingle’. 3.Delete the text in the text property.

11 1105/09/2015 Name property 1.Note the default name ‘Label1’. When you add controls they are given a default name which reflects the type of control. When you add controls they are given a default name which reflects the type of control. They are also automatically numbered at a the end. They are also automatically numbered at a the end. So if you were to add another label it would be named by default as Label2, etc… So if you were to add another label it would be named by default as Label2, etc… 2.Set the Name property to ‘lblDisplayMyName’. Note no spaces allowed in any control Name.

12 1205/09/2015 Difference between Name and Text properties Name property – the name you will use in program code to refer to this control. Text property the text displayed in the control for the user to see.

13 1305/09/2015 Naming Controls It will help you if use the common programming convention of adding a lower case three-character prefix to a control name. So when you come across these names in your code you will know what type of control it is.

14 1405/09/2015 Common Prefixes ControlPrefix CheckBoxchk ComboBoxcbo Buttonbut DataSetdat HScrollBarhsbControlPrefixLabellbl ListBoxlst MenuStripmnu Text box txt Timertmr

15 1505/09/2015 Font Property  All font properties are in Font section which must be opened before any font properties can be set.

16 1605/09/2015 Font Property 1.Set the Font property of the label to size 12 and Style Bold (True). Note the label must be selected! Note the label must be selected!

17 1705/09/2015 Buttons Add a button to the form. Name NamebutName Font FontBold Text Text Click here

18 1805/09/2015 Programs / Projects Event-driven languages like Visual Basic are built using one or more forms. On these you place a variety of other controls and write procedure code for some of them to suit the purpose of your program (a form is also an example of a control).

19 1905/09/2015 Coding 1.Double click butName. 2.You will now see the procedure code template below. Write code here for the butName’s click event. List of events drop down menu.

20 2005/09/2015 Events When you double-click any control or the form itself, Visual Basic supplies the procedure code template for the event which the makers of the language think is the most common one for that control. For a button they think the Click event should be the default one. Click the list of events (next to Load) to see other events.

21 Syntax Errors While you are writing in what we call the “Integrated Development Environment (IDE)” if you get blue squiggly lines underneath your procedure code, then there is a syntax error. Errors in a program that break the grammar rules of the language being used. Errors in a program that break the grammar rules of the language being used. The IDE constantly checks that the rules of the language are being followed. This could be due to many reasons but the following are the most common: You have used a name that does not exist. You have used a name that does not exist. You have misspelt a reserved or keyword and VB does not recognise it (it should offer you suggestions like a spell check if you right click the error). You have misspelt a reserved or keyword and VB does not recognise it (it should offer you suggestions like a spell check if you right click the error). You have misused a reserved or keyword. You have misused a reserved or keyword. A reserved or keyword is any word in the vocabulary of a programming language which can only have the meaning defined in that language. Also note that VB will give you suggestions as soon as you start typing. Use these suggestions to save your fingers and time!

22 2205/09/2015 Coding Between the two lines of the procedure template code type the following code: lblDisplayMyName.Text = “ ……… “ lblDisplayMyName.Text = “ ……… “ “=” mathematically indicates equality. “=” in programming, in this case, is an arithmetical operator meaning to change (store or assign) the text inside “…” to the Text property of the control. It does not mean “it is equal” it means “make it equal”. It does not mean “it is equal” it means “make it equal”. Left Side -> Right Side So order is important. So order is important. Your Name

23 2305/09/2015 Design View Return to Design View by clicking the Design tab. File – Save All – Save Note all projects are by default save in My Documents/Visual Studio 2005/Projects.

24 2405/09/2015 Running the Program Run the Program by clicking the Play button in the top toolbar. If there are any errors it will tell you below in the error window where the error occurred.

25 2505/09/2015 Files File menu – Save All option Go and have a look at the files that have been created for your project: My Documents/Visual Studio 2008/Projects My Documents/Visual Studio 2008/Projects

26 2605/09/2015 Executable files Make an executable file of your program which can be installed as ‘proper program’ by Build menu – Publish.

27 2705/09/2015 Program 1.2 Change A Message Specification: Specification: When a button is clicked the message “I LIKE Visual Basic” appears. When a second button is clicked the message changes to “I HATE Visual Basic”. When a button is clicked the message “I LIKE Visual Basic” appears. When a second button is clicked the message changes to “I HATE Visual Basic”.

28 2805/09/2015 Program 1.2 Change A Message 1.Launch Microsoft Visual Basic 2005 Express Edition. 2.Create New Project (File – New Project / in top toolbar or Project in Start Page). 3.Save with name ‘Change a Message’. 4.Make sure you have Form1 selected. 5.Change the Text property of the form to ‘Change A Message’.

29 2905/09/2015 Labels 1.Add a Label control to the upper part of the form. 2.Change the Name property of the Label to ‘lblMessage’. 3.Change the BorderStyle property to ‘FixedSingle’. 4.Change the Font Property Size to ’14’ and style to ‘Bold’. 5.Change the Text property of the label to ‘Message’

30 3005/09/2015 Buttons 1.Add 2 buttons to lower part of the form (left and right sides). 2.One with Name property ‘butGoodMessage’ and Text property ‘Good Message’. 3.The other with Name property ‘butBadMessage’ and Text property ‘Bad Message’.

31 3105/09/2015 Coding the buttons 1.Double-click the Good Message button and the procedure template code for the click event pops up (remember Visual Basic assumes you want this code to occur if the button is clicked as this most likely event for a button. 2.Write the following code between the lines of the procedure template code: lblMessage.Text = “I LIKE Visual Basic” 3.Return to Design View and do the same for the Bad Message button, but this time the code is: lblMessage.Text = “I HATE Visual Basic”

32 3205/09/2015 Saving and Running your program In Design View File – Save All – Save Run the Program by clicking the Play button in the top toolbar. If there are any errors it will tell you below in the error window where the error occurred.

33 3305/09/2015 Executable files Make an executable file of your program which can be installed as ‘proper program’ by Build menu – Publish.

34 Changing Properties ObjectName. Property = whatever you wish to change it to The property you use depends on what you wish to change and will be something from the property list. Which properties you can change depends on the object concerned (different objects have different properties available). Click the object and check out the properties available in the Property list. How or what you change the property to depends on how it works in the property list. For example: To change the Visible property you have use True or False.

35 Displaying updated information while a program is running This will normally be done in a label so: lbl LabelName.Text = whatever you want to display If you want to display a standard text message then enclose the text in “…….”.

36 3605/09/2015Plenary What is a visual Basic Project is made up of? One or more forms How do we build a program? Place controls from the toolbox onto a form Can you name some examples of controls? TextBoxes, Labels, Buttons, Forms

37 3705/09/2015 Plenary Can you name some common events and explain what they do? Click Event Most controls have procedures The code inside these procedures are fired off when an event happens. What is the ‘=‘ sign is used? Often used as an assignment statement

38 38 Extension Programs 1. 1.Add code to Program 1.1 to display IBSB in a second label when the program runs. 2. 2.Write a program which displays the message “Welcome to Visual Basic” in the title of a form when a Welcome button is clicked (when referring to a form you must use Me. ) 3. 3.Write a program which initially hides a label saying Visible, clicking a Show button should show it and clicking a Hide should hide it. Add two buttons on a form whose text properties should be set to Show and Hide. Add a label to the form whose text property should be “Visible” and it’s visible property should be set to false. Clicking the Show button should show the label and clicking the Hide button should hide it again. Use lblMessage.Visible = True or False 4. 4.Write a program so that the background and words typed into a text box change to red or blue when associated buttons are clicked. Use txtBox.ForeColor = Color.Red or Color.Blue Use txtBox.BackColor = Color.Red or Color.Blue


Download ppt "05/09/20151 1.1 Introducing Visual Basic Sequence Programming."

Similar presentations


Ads by Google