1 / 26

Chapter 3

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.

civory
Télécharger la présentation

Chapter 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 3 Introducing Visual Basic.NET

  2. 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. 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.

  4. 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)

  5. Ch. 3 – Review 1 -New Project -Name: Ch3 – Review 1 -Location: G:\ -New Form Name: Form1 Text: Message

  6. 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

  7. 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

  8. 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)

  9. 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

  10. 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.

  11. 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

  12. 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.

  13. 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

  14. 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

  15. 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

  16. 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

  17. Ch. 3 Review 4 -New Project -Add Form from review 3 -Create Click Event for mnuExit -Add code - Me.Close() -Run Program

  18. 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 “ “)

  19. 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 (=)

  20. 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

  21. 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

  22. 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

  23. 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

  24. 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

  25. 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

  26. 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

More Related