Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 2 Introduction to Visual Basic.NET Programming Appreciation.

Similar presentations


Presentation on theme: "Lecture 2 Introduction to Visual Basic.NET Programming Appreciation."— Presentation transcript:

1 Lecture 2 Introduction to Visual Basic.NET Programming Appreciation

2 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 2 About Your Lecturer Richard C.Y. Pang Computer & Information Management Room 436 Consultation Hours Telephone - 2595 8168 Email: richardp@vtc.edu.hk Consultation Hours Wed 11am - 5pm Thu 2pm - 4pm

3 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 3 Textbook Programming in Visual Basic.NET [4th ed.] –by Bradley, Julia Case –New York, N.Y. : McGraw- Hill/Irwin, c2003. –IVE Library: QA 76.73.B3 B697 2003 Visual Basic.NET Introductory Concepts and Techniques –Gary B. Shelly, Thomas J. Cashman, Jeffrey J. Quasney –Thomson Course Technology –ISBN 0-7895-6547-1 Reference Book Any book on Visual Basic.NET

4 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 4 Writing Windows Applications with VB Windows Graphical User Interface Window = Form Toolbox of elements called Controls –Text Box –Label –Check Box –Button

5 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 5 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

6 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 6 Object Model Object ==> Noun –Form and Controls Property ==> Adjective –Color of a Form Method ==> Verb –Move a Form

7 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 7 Object Model (cont.) Event ==> Occur 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

8 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 8 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

9 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 9 Object Model Analogy Class = automobile Properties = make, model, color, year Object = each individual car –Object is also an Instance of the automobile class Methods = start, stop, speedup, slowdown Events = car arrives, car crashes

10 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 10 Visual Basic.NET Included in Visual Studio.NET –Visual Basic (can also be purchased separately) –C++ –C# –.NET Framework Complete rewrite from VB Version 6

11 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 11 Visual Studio.NET Editions Academic Professional Enterprise Developer Enterprise Architect

12 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 12 Steps for Writing VB Projects Design/Define the User Interface Plan/Set the Properties Plan/Write the Code Test and Debug

13 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 13 Open this file directly to work on a Project VB Application Files One Solution File.sln Solution User Options File.suo Project Files.vbproj Project User Options File.vbproj.user Form Files.vb Resource File for the Form.resx

14 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 14 Visual Studio Environment Integrated Development Environment (IDE) Form Designer Editor for entering code Compiler Debugger Object Browser

15 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 15 Visual Studio IDE Start Page

16 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 16 IDE New Project Dialog

17 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 17 IDE Main Window Toolbars Document Window Form Designer Solution Explorer Properties Window Toolbox

18 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 18 IDE Main Window

19 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 19 VB Toolbox Holds the tools you place on a form

20 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 20 Visual Studio Help Extensive Help feature Includes Microsoft Developer Network library (MSDN) Entire reference manual Coding examples

21 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 21 Modes Design Time Run Time Break Time “Look at the Title Bar”

22 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 22 Naming Rules (p 43-44) Always use standard names for objects 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

23 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 23 Recommended Naming Conventions for VB Objects Object ClassPrefixExample FormfrmfrmDataEntry ButtonbtnbtnExit TextBoxtxttxtPaymentAmount LabellbllblTotal Radio ButtonradradBold CheckBoxchkchkPrintSummary Horizontal ScrollBarhsbhsbRate Vertical ScrollBarvsbvsbTemperature PictureBoxpicpicLandscape ComboBoxcbocboBookList ListBoxlstlstIndegredients

24 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 24 lblMessage btnPush btnExit Hello World Project (p 15) Design the User Interface

25 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 25 Properties Window-Label1 Rename Label1 to lblMessage

26 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 26 Set the Properties Label –NamelblMessage –Textleave blank Button 1 –NamebtnPush –TextPush Me Button 2 –NamebtnExit –TextExit Form –NamefrmHello –TextHello World by your name

27 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 27 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

28 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 28 Project Property Page Dialog

29 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 29 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

30 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 30 Editor Window Declarations Section Class list Method list

31 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 31 ' Display the Hello World message 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

32 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 32 lblMessage.Text=" Hello World " Assignment Statement Assigns a value to a property or variable Operates from right to left Enclose text strings in quotation marks (" ")

33 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 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 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 34 Test and Debug Save Project - File Menu, Save All Run Project –Debug Menu, Start –Start Without Full Compile (F5) –Start With Full Compile(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."

35 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 35 Print the Code File Menu, Print Prints complete code listing Uses arrow symbol to denote line continuation Examine sample output on page 39

36 © 2001 by The McGraw-Hill Companies, Inc. All rights reserved. 1- 36 Finding and Fixing Errors Syntax Errors Run-Time Errors Logic Errors


Download ppt "Lecture 2 Introduction to Visual Basic.NET Programming Appreciation."

Similar presentations


Ads by Google