1 / 61

VB.NET

VB.NET. Professor Corinne Hoisington Central Virginia Community College. Programming Curricular Changes. Why should we implement this new software developer’s tool? What language will be “THE” most used language? Is this simply another upgrade?

mstump
Download Presentation

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 Professor Corinne Hoisington Central Virginia Community College

  2. Programming Curricular Changes • Why should we implement this new software developer’s tool? • What language will be “THE” most used language? • Is this simply another upgrade? • What classes could incorporate the content of .NET?

  3. Visual Basic.NET • Easier to Use • Streamlined and Modernized • More Powerful than VB 6.0 • Higher level of access to system resources that in the past required the use of languages like C++ • True Object Inheritance • Garbage Collection for better memory management

  4. Visual Studio .NET 2003 • Released April 27, 2003 • J# • Mobile Web Applications: using the integrated ASP.NET Web Forms and the Visual Studio .NET Web Forms Designer, Visual Basic and C# developers can easily build thin-client Web-based applications that render intelligently on more than 200 devices, including wireless application protocol (WAP) phones, wireless personal digital assistants (PDAs), and pagers.

  5. New Web Development • Programming for the Web vs. Windows • New set of controls • Web page layout • ASP.NET • ADO.NET • Mobile Applications • Convert Projects

  6. Just an Upgrade??? • NO! • VB.NET omits quite a few forms of syntax • VB.NET requires a total rewrite rather than a simple port of code • VB.NET is not dependent on older libraries such as VBA runtime and ADO (ActiveX Database Object)

  7. A new Forms Engine • The forms engine has been replaced by the forms engine built into .NET • This new forms engine is called Windows Forms (or Win Forms for short) • Win Forms add such features as docking and opacity

  8. Forms are now Classes • In VB6, forms were classes, but you rarely treated them that way • VB .NET shows the code that instantiates the form • To show additional forms, you must first instantiate them

  9. Form Changes • Forms have undergone a number of changes. These include: • The Forms engine is now WinForms • Forms are classes • A Component Tray holds non-visual controls at design-time

  10. VB.NET or C#.NET • C# is a new language that was designed to be friendly to programmers who are already proficient in C or C++ • Either language can be used to write software that takes full advantage of the CLR and .NET framework

  11. NEW IDE

  12. New Tools • Calendar Tool • Date Picker Calendar • Opacity Control • Timer does not lay on form • Command Buttons are now called Buttons • Use “btn” for prefix

  13. Great New Menu Tool

  14. More Changes • The Editor window (formerly the Code window) • Lots more IntelliSense help; can be confusing • Declarations section replaces General Declarations • Collapsible Regions in code (Plus signs)

  15. Collapsed Regions Tabs Method List Class List Collapsed Region Collapsed Procedure

  16. General Changes • There have been a number of changes in VB .NET. General changes include: • Form changes • Option Strict • Event Handler changes • Default Properties • Calling Subs and Functions • Boolean operators • Using CTRL + Space to finish variables

  17. The Component Tray • In VB6, controls that were only visible at design-time still appeared on the form in the IDE • Such as the Timer control • VS .NET places controls that are invisible at runtime in a small area below the form • This area is the Component Tray

  18. A new Forms Engine • The forms engine has been replaced by the forms engine built into .NET • This new forms engine is called Windows Forms (or Win Forms for short) • Win Forms add such features as docking and opacity

  19. Forms are now Classes • In VB6, forms were classes, but you rarely treated them that way • VB .NET shows the code that instantiates the form • To show additional forms, you must first instantiate them

  20. The Component Tray • In VB6, controls that were only visible at design-time still appeared on the form in the IDE • Such as the Timer control • VS .NET places controls that are invisible at runtime in a small area below the form • This area is the Component Tray

  21. Calls to Subs and Functions Require Parentheses • In VB6, you called a Sub without parentheses AddOrder OrderNum, OrderDate • You could use the Call statement, which required parenthese Call AddOrder(OrderNum, OrderDate) • .NET always requires parentheses for a Sub, as well as with Functions

  22. New Boolean Operators • The And and Or keywords do not short-circuit in VB and VB .NET • Both sides of an operator are evaluated, even if the first option invalidates the statement • VB .NET adds two short-circuiting Boolean operators: • AndAlso • OrElse

  23. Boolean Operators Example Dim x As Integer x = 0 If x>2 And 5\x > 1 Then ... • This If statement is already false on the x>2 part, but 5\x is still checked because And does not short-circuit • In this case, 5\x causes a “divide by zero” error

  24. Boolean Operators Example cont. Dim x As Integer x = 0 If x>2 AndAlso 5\x > 1 Then ... • This If statement is already false on the x>2 part, so the AndAlso does not check the 5\x portion • The key result: No Error!

  25. The Value of True • The value of True has not changed • Originally, the value of True was going to change, but it did not • The value of True in VB .NET is still negative one (-1) • Your code should not check for -1, but for True

  26. Common Language Runtime • VB.NET has undergone a significant overhaul to accommodate the CLR • New object oriented design features • Much higher levels of type safety • Universal type system allows for greater inoperability

  27. Changes in Properties • The Alignment property becomes TextAlign • The maximum length of identifiers is 16,383 • All new Help — MSDN • OptionButton becomes RadioButton • Frame becomes GroupBox • New component tray holds non-visible controls

  28. More Property Changes • Text boxes have a Clear method txtName.Clear() txtName.Text = “” • Focus method replaces SetFocus txtName.Focus() • Many colors available through the Color class • lblMessage.ForeColor = Color.Blue Color.Aquamarine Color.Bisque Color.Chocolate Color.Cadetblue

  29. Tab Order This is neat! Click on View and Tab Order

  30. Caption / Text Property • VB 6.0 - Some controls, such as Label, have a Caption property that determines the text displayed in or next to the control. Other controls, such as TextBox, have a Text property that determines the text contained in the control • VB.NET - In Windows Forms, the property that displays text in a control is consistently called Text on all controls. This simplifies the use of controls.

  31. Data Types

  32. More Integer Data Types

  33. Other Data Types

  34. Block-Level Scope • VB .NET introduces variables that only exist within blocks of code • Blocks are items such as For…Next, Do…Loop, and If Then…End If • Variables are only visible within the block, but their lifetime is that of the whole procedure

  35. Changes in Syntax • Firstly the ‘Currency’ data type is no longer used in VB 6.0 • Currency has been replaced with Decimal in VB.NET • The Currency data type (64 bit) does not provide sufficient accuracy to avoid rounding errors, so Decimal (96 bit) was created as its own data type. • Dim x As Currency is upgraded to: Dim x As Decimal

  36. Long and Integer Data Types • VB 6.0 - Long variables were stored as 32-bit numbers and Integer variables as 16-bit numbers • VB.NET - Long variables are stored as 64-bit numbers, Integer variables are stored as 32-bit numbers, and Short variables are stored as 16-bit numbers.

  37. No More Variant Data Type • Variant data types are changed to Object due to keeping all the languages more similar. This is no longer the same as a pointer to an object. • Dim x As Variant is upgraded to: Dim x As Object

  38. Option Explicit • In VB.BET the option is turned on by default for all new projects. • When Option Explicit Off is used (not a good programming style), you can use any variable without first declaring it.

  39. Option Strict On • New Option in VB.NET • When Option Strict is turned on, the compiler/editor does not allow implicit conversions from a wider data type to a narrower one, or between String and numeric data types • CInt and CDec convert • Limits erroneous numbers or run-time errors • Place the line Option Strict On before the first line of code

  40. Converting Data Types • Initialize a variable at declaration Dim intMax As Integer = 100I Dim decRate As Decimal = 0.08D • Declare multiple variables at once Dim intCount, intNum As Integer • Convert all input to correct data type (Do not use Val function) decSale = CDec(txtSale.Text) • CInt (still rounds to even #) • CDec • CStr ** CInt and CDec parse some characters like $, commas,()

  41. Format • VB 6.0 – Format(variable, “Currency”) • VB.NET – FormatCurrency(variable) FormatPercent(variable) FormatNumber(variable) FormatNumber(variable,3) FormatDateTime(variable)

  42. New Compound Operators • New assignment Operators • += –= *= /= \= &= • decTotal += decSale same as decTotal=decTotal + decSale

  43. Case Conversions • String ToUpper and ToLower methods • Replace UCase and LCase functions • If txtInput.Text.ToUpper = “YES”

  44. Arrays • VB 6.0 - Arrays can be defined with lower and upper bounds of any whole number. The Option Base statement is used to determine the default lower bound if a range is not specified in the declaration. • VB.NET- To enable interoperability with other languages, all arrays must have a lower bound of zero. This makes the Option Base statement no longer necessary. • Dim a(1 To 10) As String is upgraded to: Dim a(10) As String

  45. Array Size • This is one area that was going to change, but did not • When you declare an array, it starts at zero, and the element number you use is the Upper Bound of the array • This means that arrays will always be one larger than the size declared • Dim x(2) As Integer has three elements

  46. Arrays Continued • Arrays in VB.NET are classes supporting properties and methods, making them quite flexible. • .Sort • .Reverse • You can sort an array in one line of code!

  47. Garbage Collection • The garbage collector periodically checks for unreferenced objects and releases all memory and system resources used by the objects • VB’s garbage collection reclaims object space automatically behind the scenes • For efficiency, VB only runs the garbage collection feature when: • There are objects to recycle • There is a need to recycle them

  48. While Loops • VB 6.0 - While statements are ended with a WEND statement. • VB.NET - WEND statements are changed to End While. This improves language consistency and readability. • While End While

  49. Parameter Passing • VB 6.0 - Parameters that do not specify either ByVal or ByRef default to ByRef • VB.NET - Parameters that do not specify either ByVal or ByRef default to ByVal. Defaulting to ByVal rather than ByRef eliminates the problem of having a procedure mistakenly modify a variable passed in by the caller.

  50. GoSub, On Goto • VB 6.0 - The GoSub line ... Return statement branches to and returns from a subroutine within a procedure. • VB.NET - GoSub...Return is a nonstructured programming construct. Its use makes programs harder to read and understand. Creating separate procedures that you can call may provide a more structured alternative or use case statements.

More Related