1 / 68

VB .NET

VB .NET. The Basics. The .NET Framework . Common Language Runtime Managed Code MS Intermediate Language – MSIL JIT Compiler Common Type System Common Language Specification Class Libraries – Namespace Multiple Language Support. Writing Windows Applications with VB.

crescent
Télécharger la présentation

VB .NET

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. VB .NET The Basics

  2. The .NET Framework • Common Language Runtime • Managed Code • MS Intermediate Language – MSIL • JIT Compiler • Common Type System • Common Language Specification • Class Libraries – Namespace • Multiple Language Support

  3. Writing Windows Applications with VB • Windows Graphical User Interface • VB.Net is an object-oriented language • Write application programs that run in Windows or on the Internet • Window = Form • Toolbox of elements called Controls • Text Box • Label • Check Box • Button

  4. Programming Languages • Procedural • Program specifies exact sequence • Event Driven (VB 6.0 and previous) • Object Oriented Programming (VB.NET) • User controls sequence • Click event • Double Click event • Change event

  5. Object Model • Object ==> Noun • Form and Controls • Property ==> Adjective • Color of a Form • Method ==> Verb • Move a Form

  6. Object Model (cont.) • Event ==> Occurs when the user takes action • User clicks a button, User moves a form • Class ==> Template to create new object • Each control added is an Instance of a Class

  7. Dot Notation • Used to reference object's properties and methods in code • Object dot Property • Form.Text, TextBox.Text • Object dot Method • Form.Hide( ), TextBox.Focus( ) • To reference an object's events use an underscore instead of a dot • Button_Click, ListBox_TextChanged

  8. Intellisense label1.FlatStyle =label1.Enter() label1.Equals() Event Method Property

  9. VB Application Files • One Solution File .sln • May contain multiple projects • Stores the names of the project and config info • Solution User Options File .suo • User customization options • IDE screen layout • Project Files .vbproj • Describes the project and list the files required • May contain multiple forms • Project User Options File .vbproj.user • Form Files .vb /.aspx • Resource File for the Form .resx • Code Behind .aspx.vb

  10. Visual Studio Environment • Integrated Development Environment (IDE) • Form Designer • Editor for entering code • Compiler • Debugger • Object Browser

  11. Visual Studio IDE Start Page

  12. Visual Studio IDE Start Page

  13. Visual Studio IDE Start Page

  14. IDE New Project Dialog

  15. IDE Main Window • Toolbars • Document Window • Form Designer • Solution Explorer • Properties Window • The Name property of a control is used to refer to the control in code. • The Text property holds the words that the user sees on the screen. • Toolbox

  16. IDE Main Window

  17. VB Toolbox • Holds the controls you place on a form

  18. Visual Studio Help • Extensive Help feature • Includes Microsoft Developer Network library (MSDN) • Entire reference manual • Coding examples • Dynamic Help • Technet • http://msdn.microsoft.com/library/en-us/vblr7/html/vboriVBLangRefTopNode.asp

  19. Modes • Design Time • Designing the interface and writing code • Run Time • Testing and running project • Break Time • Runtime error or pause • Debugging “Look at the Title Bar”

  20. Naming Rules – Handout • Always use standard names for objects • Numbers, letters, & underscore • Must start with letter or underscore • No spaces or punctuation marks • 3 letter lowercase prefix identifies control type • Button-btn • Label-lbl • Form-frm • If multiple words capitalize 1st letter of each word – Camel casing • btnExitProgram

  21. Object Class Prefix Example Form frm frmDataEntry Button btn btnExit TextBox txt txtPaymentAmount Label lbl lblTotal Radio Button rad radBold CheckBox chk chkPrintSummary Horizontal ScrollBar hsb hsbRate Vertical ScrollBar vsb vsbTemperature PictureBox pic picLandscape ComboBox cbo cboBookList ListBox lst lstIndegredients Recommended Naming Conventions for VB Objects

  22. Steps for Writing VB Projects • Design/Define the User Interface • Interface Design Planning Form • Plan/Set the Properties • Object and Properties Planning Form • Plan/Write the Code • Event Procedure Planning Form • One of each of the above for each *.vb form file • Test and Debug

  23. Form Design Plan EXIT PUSH ME

  24. Properties Design Plan • Label • Name lblMessage • Text leave blank • Button 1 • Name btnPush • Text Push Me • Button 2 • Name btnExit • Text Exit • Form • Name frmHello • Text Hello World by your name

  25. btnPush_Click btnExit_Click Set lblMessage.text to “Hello World” Exit program Event Design Plan

  26. Set the Project's Startup Object • The default startup object if Form1 • The name of the form should always be changed to adhere to naming rules • Using Project menu, Properties change the startup object to match the new name

  27. Write the Code • While the project is running the user can perform actions • Each action by the user causes an Event to occur • Write code for the events you care about, the events you want to respond with code • Code is written as event procedures • VB will ignore events for which you do not write code

  28. Editor Window • Declarations Section • Class list • Method list

  29. Remark Statement • Also known as Comment, used for documentation • Non-executable • Automatically colored Green in Editor • Begins with an apostrophe ( ' ) • On a separate line from executable code • At the right end of a line of executable code ' Display the Hello World message

  30. Test and Debug • Save Project - File Menu, Save All • Run Project • Debug Menu, Start (F5) • Start With Full without Debugging (CTRL F5) • Correct any Errors and Rerun • Compile errors • Run-Time Errors • Logic errors • Syntax errors "Help is always available from the Help Menu or by pressing F1."

  31. Finding and Fixing Errors • Syntax Errors • Run-Time Errors • Logic Errors

  32. Assigns a value to a property or variable Operates from right to left Enclose text strings in quotation marks (" ") Assignment Statement lblMessage.Text=" Hello World "

  33. Ending a Program • Execute the Close Method of the Form • Methods always have parentheses (this will help you distinguish them from Properties which never have parentheses) • Current Form may be referenced as Me Me.Close( )

  34. Button (btn) • Used to run/activate an Event Procedure • Click event Label (lbl) • Used for • Output on a form • Identification of objects • Directions/Information • Cannot by modified by user

  35. Text Box (txt) • Used for user input/data entry • Text Property • What is displayed in text box • What user entered in text box • TextAlign Property • Controls alignment of text in the Text Box • Change Event

  36. Check Box (chk) • Used for user input/data entry • Allows the user to select or deselect 1 or more in any group • Checked Property - Boolean • Checked = True • Unchecked = False • CheckChanged Event

  37. Radio Button (rad) • Used for user input/data entry • Allows the user to select only 1 in any group • First create a group and then create each radio button inside the group • Checked Property - Boolean • Checked = True • Unchecked = False • CheckChanged Event

  38. Data Types

  39. Data Types

  40. Variables & Constants • Variable • Memory locations that hold data that can be changed during project execution • Ex: hours worked • Named Constant • Memory locations that hold data that cannot be changed during project execution • Ex: Sales tax percentage, SSI rate

  41. Constants • Named • User defined • Intrinsic • System defined within Visual Studio • Color.red

  42. Declaration Statements • DIM|PUBLIC|PRIVATE|FRIEND|STATICused to declare Variables • CONST used to declare Named Constants • Declaration includes • Name, follow Naming Convention Rules • Data Type • Required Value for Constants • Optional Initial Value for Variables

  43. Declaration Examples Dim strName, strSSN As String Dim intAge As Short Dim decPayRate As Decimal = 8.25 Dim datHireDate As Date Dim blnInsured As Boolean Dim lngPopulation As Long Const decDISCOUNT_RATE As Decimal = .15 Note: Constants are named using all uppercase letters EXCEPT the prefix.

  44. Type-Declaration Characters • Append single character to the end of the Constant's Value to indicate the Data Type Short – S Integer – I Long – L Decimal – D Single – F Double – R

  45. Variables – Scope & Lifetime • Global/Public (use sparingly and cautiously) • Available to all modules and procedures of Project • Initialized at start of Project • Module/Private (Form) • Available to one module and all procedures within that module • Initialized 1st time the Form is loaded • Local • Available only to the procedure it is declared in • Initialized every time the Procedure runs • Block (not used until later in this course) • Available only to the block of code inside a procedure it is declared in • Initialized every time the Procedure runs

  46. Declaring Module Level Variables Example

  47. Calculations • Calculations can be performed using properties of certain objects, variables, constants, and numeric literals • Do Not use Strings in calculations • Values from Text property of Text Boxes • Are Strings, even if they contain numeric data • Must be converted to a Numeric Data Type

  48. Conversion Functions (cont.) • Function Convert To • CInt ** Integer • CDec Decimal • CStr String ** CInt rounds to the nearest Even Number

  49. Conversion Examples(also review info p 485) intQuantity = CInt(txtQuantity.Text) decPrice = CDec(txtPrice.Text) intWholeNumber = CInt(decFractionalValue) decDollars = CDec(intDollars) strValue = CStr(decValue) Function Name Argument To Be Acted Upon

More Related