260 likes | 278 Views
Chapter 3. Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming. -Used to create Windows, Web, and Console applications -Uses predefined classes to create the interface -We will be creating event driven applications -We are using Visual Basic.NET version 2003.
E N D
Chapter 3 Introducing Visual Basic.NET
3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined classes to create the interface -We will be creating event driven applications -We are using Visual Basic.NET version 2003
3.2 The VB.NET IDE -IDE (Integrated Development Environment) -Start Page is the first thing to be loaded. -make sure projects tab is selected.
3.3 Creating a New Project -Select New Project Button -In Dialog Box -Project type: Visual Basic Project -Templates: Windows Application -Name: Descriptive (ex. Ch 3 Review 2) -Location: Corresponding folder in your files on the share drive (ex. G:\Programming\) -Parts of IDE (Visual Aide p. 14)
Ch. 3 – Review 1 -New Project -Name: Ch3 – Review 1 -Location: G:\ -New Form Name: Form1 Text: Message
3.4 The Windows Form -Use cursor to resize form accordingly -Properties (controls behavior, appearance, position, etc) -Name: Form1 (must be this for now) -Text: What is shown in Title Bar -BackColor: Changes color of Form -BackgroundImage: Sets an image as the background
3.5 The Label Control -Control Objects: get user data or display information -Label Control (displays text that can’t be changed by user) -can be added to form by dragging from toolbox or double clicking -can be moved to desired location on form by dragging
Label Properties Name: lbl + description (ex. lblMessage) Text: text to be displayed Font: click on … and control size, style, etc. TextAlign: use button to align text in label area -notice the name property (lbl stands for label and tells other programmers what type of object and information goes there)
Ch. 3 – Review 2 -New Project -Name: Ch3 – Review 2 -Location: G:\ -Add form from Review 1 -Add Label -Name: lblMessage -Text: Hello World! -Font: Bold, 20 -TextAlign: MiddleCenter -Run Program
3.6 Saving and Running an Application -All projects should be saved frequently -To run an application (click on the play button or hit F5) -During the compiling phase the software converts your program into machine code so the computer can run it.
3.7 The MainMenu Control -Add menu by dragging or double clicking the icon in the tool bar. -Adds 2 parts (the visible menu and sub-menus) -these are called menuItems -MenuItem Properties -Name: mnu + description (mnuProgram) -Text: Text to be displayed -Might have to declare the correct menu in the form
3.8 Closing & Opening a Project in VB.NET -If you are restarting VB.NET it should show the recent projects on the start screen. -If you are starting it for the first time today, you will have to choose open project from the toolbar. Then select the appropriate folder/file.
Ch. 3 Review 3 -New Project -Add Form from review 2 -Add a mainmenu from toolbox -Create menu -Name: mnuProgram -Text: Program -Create Sub - menu -Name: mnuExit -Text: Exit -Run Program -Complete Lesson 3.1 Review Worksheet
3.9 Program Code -Statement (each line of computer code) -All code has to be entered below the Inherits line but preferably below the “Windows Form Generated Code” box
3.10 The Event Procedure -Procedure is a block of code to perform a specific task -Event Handler is the type of procedure that performs the task. -Click Event (executes a task in response to a mouse click) -Adding an Event Procedure (In Code Window)\ -Choose object from left list box -Choose action from right list box
3.10 Continued -Will Create code similar to Private Sub mnuExit_Click (…) handles mnuExit.click End Sub -Private Sub indicates that only form1 can access the code and End Sub tells the computer where the procedure stops -Good Programming Style -All code for procedure needs to be indented one tab Private Sub mnuExit_Click (…) handles mnuExit.click me.Close() End Sub
Ch. 3 Review 4 -New Project -Add Form from review 3 -Create Click Event for mnuExit -Add code - Me.Close() -Run Program
3.11 Assignment Statements -Assignment Statements are used to change an objects property at runtime -format: form.object.property = value -example: me.lblMessage.Text = “Smile!” -When changing text property (all words must be in “ “)
3.12 Using AutoList -VB.NET attempts to make coding easier by using an autolist when you type in the dot (.) These autolist shows possible properties you can change -Me (is used to refer to the current form) -example: Me.lblMessage.Text = “Hello World!” -AutoLists are sometimes listed when you type an (=)
Ch 3 Review 6 -New Project -Add Form from review 4 -Add Sub Menu Smile (name: mnuSmile) -Add Sub Menu Hello World (name: mnuHelloWorld) -Create Click Event for mnuSmile -Add code to click event - Me.lblMessage.text = “Smile” -Create Click Event for mnuHelloWorld -Add code to click event - Me.lblMessage.text = “Hello World” -Run Program
3.13 RadioButton Control -For radio buttons to work correctly they must be grouped in a group box -GroupBox Control -Properties -Name: grp + Description (ex. grpLanguage) -Text: text to be shown on interface -RadioButton Control -Properties -Name: rad + description (ex. radFrench) -Text: text to be shown on interface -Checked: True/False (Shows which one to be checked at start) -When writing code for radio button they must be click events
3.14 Commenting Code -Used to explain or clarify program code -Have no effect on how computer runs application -To create a comment place a apostrophe (‘) before code -Use comments to put Project Name, Your Name, Class Period, and Date at the top of your program code
Ch. 3 Review 7 -New Project -New Form -Add 1 label (lblGreeting) -Add 1 Groupbox (grpLanguages) -Add 3 RadioButtons -(radEnglish, radFrench, radSpanish) -Add Comments to code (include name, project name, and date) -Add Click Events for all radio buttons -Add following code to appropriate Events -me.lblGreeting.text = “Hello, World” ‘English -me.lblGreeting.text = “Hola, Mundo” ‘Spanish -me.lblGreeting.text = “Bonjour le Monde” ‘French
3.15 Arithmetic/Numeric Expressions -Arithmetic Operators -Exponents (^) -Multiplication (*), Division (/) -Addition (+), Subtraction (-) -Normal Order of Operations Apply -ex: (Me.lblAnswer.text = 2 + 6 * 3) -Use parentheses to control order of operations -What’s the difference??? - Me.lblAnswer.text = 12 / 6 + 3 * 2 - Me.lblAnswer.text = “12 / 6 + 3 * 2” 8 12 / 6 + 3 * 2
3.16 Button Control -Common way to get selections from user -When Coding set up as a click event -Properties -Name: btn + description (ex. btnSave) -Text: text to be displayed on button
Ch 3 Review 8 -New Project -New Form -Add 4 buttons to form -btnProb1, btnProb2, btnProb3, btnProb4 -Add 4 labels to form -lblAns1,lblAns2, lblAns3, lblAns4 -Add Click Events for each button -Add following code to appropriate events -me.lblAns1.text = 5 + 2 ^ 3 -me.lblAns2.text = 4 / 2 + 5 -me.lblAns3.text = 3 + 4 * 2 -me.lblAns4.text = 7 – 3 +2