Visual Basic User Interface -IV
-
Upload
sharbani-bhattacharya -
Category
Engineering
-
view
88 -
download
7
Transcript of Visual Basic User Interface -IV
![Page 1: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/1.jpg)
Visual Basic –User Interface-III
Visual Basic –User Interface-IV
Govt. Polytechnic(W)
Faridabad
27th September 2016
![Page 2: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/2.jpg)
![Page 3: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/3.jpg)
![Page 4: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/4.jpg)
![Page 5: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/5.jpg)
![Page 6: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/6.jpg)
![Page 7: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/7.jpg)
![Page 8: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/8.jpg)
![Page 9: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/9.jpg)
Public Class Form1
Dim St, Mt1, MT2 As String
Dim Mb1, Mb2, Mt1ToolStripMenuItem, MT2ToolStripMenuItem As ToolStripMenuItem
![Page 10: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/10.jpg)
Private Sub Add_Menu_Click(sender As Object, e As EventArgs) Handles Add_Menu.Click
Mt1 = TextBox2.Text MT2 = TextBox3.Text St = TextBox1.Text Dim Ab1, Ab2 As
ToolStripDropDownItem Mb1 = ColorToolStripMenuItem Mb2 = CalenderToolStripMenuItem Ab1 = Me.Mb2 Ab2 = Me.Mb1
Me.RunTimeOptionToolStripMenuItem.Name = St
Me.RunTimeOptionToolStripMenuItem.Size = New System.Drawing.Size(120, 22)
Me.RunTimeOptionToolStripMenuItem.Text = St
Me.RunTimeOptionToolStripMenuItem.DropDownItems.AddRange({Ab1, Ab2})
End Sub
CODE
![Page 11: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/11.jpg)
![Page 12: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/12.jpg)
![Page 13: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/13.jpg)
![Page 14: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/14.jpg)
Mt1 = TextBox2.Text
MT2 = TextBox3.Text
St = TextBox1.Text
Dim Ab1, Ab2 As ToolStripDropDownItem
Me.Mt1ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
Me.Mt1ToolStripMenuItem.Name = Mt1
Me.Mt1ToolStripMenuItem.Size = New System.Drawing.Size(120, 22)
Me.Mt1ToolStripMenuItem.Text = Mt1
Me.MT2ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
Me.MT2ToolStripMenuItem.Name = MT2
Me.MT2ToolStripMenuItem.Size = New System.Drawing.Size(120, 22)
Me.MT2ToolStripMenuItem.Text = MT2
Mb1 = Mt1ToolStripMenuItem
Mb2 = MT2ToolStripMenuItem
Ab1 = Me.Mb2
Ab2 = Me.Mb1
Me.RunTimeOptionToolStripMenuItem.Name = St
Me.RunTimeOptionToolStripMenuItem.Size = New System.Drawing.Size(120, 22)
Me.RunTimeOptionToolStripMenuItem.Text = St
Me.RunTimeOptionToolStripMenuItem.DropDownItems.AddRange({Ab1, Ab2})
End Sub
Code
![Page 15: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/15.jpg)
![Page 16: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/16.jpg)
![Page 17: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/17.jpg)
![Page 18: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/18.jpg)
Private Sub Start_Timer_Click(sender As Object, e As EventArgs) Handles Start_Timer.Click
TextBox1.Text = 0
Timer1.Start()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Stop()
TextBox1.Text = TextBox1.Text + Timer1.Interval
End Sub
Codes
![Page 19: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/19.jpg)
![Page 20: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/20.jpg)
![Page 21: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/21.jpg)
Private Sub Add_Menu_Click(sender As Object, e As EventArgs) Handles Add_Menu.Click
Mt1 = TextBox2.Text MT2 = TextBox3.Text St = TextBox1.Text Me.Mt1ToolStripMenuItem = New
System.Windows.Forms.ToolStripMenuItem() Me.Mt1ToolStripMenuItem.Name = Mt1 Me.Mt1ToolStripMenuItem.Size = New
System.Drawing.Size(120, 22) Me.Mt1ToolStripMenuItem.Text = Mt1
Me.MT2ToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem()
'Friend WithEvents Mt1ToolStripMenuItem As ToolStripMenuItem
'Friend WithEvents MT2ToolStripMenuItem As ToolStripMenuItem
Me.MT2ToolStripMenuItem.Name = MT2 Me.MT2ToolStripMenuItem.Size = New
System.Drawing.Size(120, 22) Me.MT2ToolStripMenuItem.Text = MT2
Mb1 = Mt1ToolStripMenuItem Mb2 = MT2ToolStripMenuItem Ab1 = Me.Mb1 Ab2 = Me.Mb2 Me.RunTimeOptionToolStripMenuItem.Name = St Me.RunTimeOptionToolStripMenuItem.Size = New
System.Drawing.Size(120, 22) Me.RunTimeOptionToolStripMenuItem.Text = St
Me.RunTimeOptionToolStripMenuItem.DropDownItems.AddRange({Ab1, Ab2})
End Sub
![Page 22: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/22.jpg)
![Page 23: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/23.jpg)
![Page 24: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/24.jpg)
![Page 25: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/25.jpg)
Private Sub Mt1ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles Mt1ToolStripMenuItem.Click
MsgBox("Menu Item 1" & " " & Mt1ToolStripMenuItem.Text)
End Sub
Private Sub MT2ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MT2ToolStripMenuItem.Click
MsgBox("Menu Item 2" & " " & MT2ToolStripMenuItem.Text)
End Sub
![Page 26: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/26.jpg)
![Page 27: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/27.jpg)
![Page 28: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/28.jpg)
Masked TextBox
![Page 29: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/29.jpg)
![Page 30: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/30.jpg)
![Page 31: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/31.jpg)
![Page 32: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/32.jpg)
![Page 33: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/33.jpg)
.NET framework offers a myriad of languages which puts us programmers into a deepthought process about which programming language best suits our needs.
![Page 34: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/34.jpg)
A variable is a named memory location. They are programming elements that can change during program execution.
Data that needs to be stored in memory & accessed at a later time are stored in variables.
![Page 35: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/35.jpg)
All the primitive types such as int, double etcare value type variables.
The simple types basically consist of Boolean and Numeric types, where Numeric is further divided into Integral and Floating Point.
![Page 36: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/36.jpg)
Object type or reference type variables are those, which are allocated storage space in the heap.
Reference type objects can be null. When a reference type is allocated under the covers a value is allocated on the heap and a reference to that value is returned.
There are basically four reference types:
classes,
interfaces,
delegates
arrays.
![Page 37: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/37.jpg)
Class type consists of custom user defined data types such as the Class Employee.
Class Employee
Dim empid As Integer
Dim empname As String
Public Sub New()
empid = 10
empname = "Reshmi"
End Sub
End Class
![Page 38: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/38.jpg)
Overloading provides the ability to create multiple methods or properties with the same name, but with different parameters lists.
This is a feature of polymorphism. It is accomplished by using the Overloads keyword in VB.NET.
![Page 39: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/39.jpg)
Class testPublic Overloads Function Add(ByVal x As Integer, ByVal y AsInteger)Return x + yEnd FunctionPublic Overloads Function Add(ByVal x As String, ByVal y AsString)Return x & yEnd FunctionShared Sub main()Dim a As new testDim b As IntegerDim c As Stringb = a.Add(1, 2)c = a.Add("Reshmi", " Nair")System.Console.Writeline(b)System.Console.Writeline(c)End SubEnd Class
![Page 40: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/40.jpg)
In VB.NET by using the Overridablekeyword with the base class method and the Overrideskeyword with the derived class method.
![Page 41: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/41.jpg)
Public Class shapes
Public Overridable Sub display()
Console.WriteLine("Shapes")
End Sub
End Class
Public Class square
Inherits shapes
Public Overrides Sub display()
Console.WriteLine("This is a square")
End Sub
End Class
Public Class rectangle
Inherits shapes
Public Overrides Sub display()
Console.WriteLine("This is a rectangle")
End Sub
End Class
![Page 42: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/42.jpg)
Properties are named members of classes, structs, and interfaces.
They provide a flexible mechanism to read, write, or compute the values of private fields through accessors.
![Page 43: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/43.jpg)
Structures are very similar to classes but there are some restrictions present in the case of structures that are absent in the case of classes.
A structure allows to create own custom data types and it contains one or more members that can be of different data types.
![Page 44: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/44.jpg)
Namespaces are used in .Net to organize class libraries into a hierarchical structure and reduce conflicts between various identifiers in a program.
Namespaces enables reusable components from different companies to be used in the same program without the worry of ambiguity caused by multiple instances of the same identifier.
Namespaces provide a logical organization for programs to exist. Starting with a top level namespace, sub-namespaces are created to further categorize code, based upon its purpose.
![Page 45: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/45.jpg)
The base class library begins at the System namespace.
Nested namespaces within the System namespace are
System.Security
System.IO
System.Data
System.Collection
![Page 46: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/46.jpg)
Boxing is the implicit conversion of a
Value type to a reference type or
To any interface type implemented by this value type.
When boxing occurs, the contents of value type are copied from the stack into the memory allocated on the managed heap.
The new reference type created contains a copy of the value type and can be used by other types that expect an object reference.
![Page 47: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/47.jpg)
UnBoxing is the explicit conversion from
A reference type to a value type or
From an interface type to a value type that implements the interface.
![Page 48: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/48.jpg)
VB.Net does not support the ability to explicitly unbox values.
It relies on the helper functions in the Microsoft.VisualBasic.Helpersnamespace to carry out unboxing.
![Page 49: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/49.jpg)
Enumerations are types that inherit from System.Enum.
The elements of an enumeration are expressed in words rather than numbers, which makes it convenient for understanding the meaning of the value being used.
Enumerations symbolically represent a set of values of one of the primitive integral types.
![Page 50: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/50.jpg)
The type of the elements of an enumeration can be Byte, Short, Integer or Long.
If no type is specified explicitly, the default type is Integer.
Enumeration Type
![Page 51: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/51.jpg)
The runtime supports constructs called delegates, which enable late-bound operations such as method invocation and callback procedures.
With delegates, a program can dynamically call different methods at runtime.
They are type safe, secure, managed objects that always point to a valid object and cannot corrupt the memory of another object.
The closest equivalent of a delegate in other languages is a function pointer, but whereas a function pointer can only reference Shared functions, a delegate can reference both Shared and instance methods.
Delegates are Marshal by Value Objects.
The members of a delegate are the members inherited from class System.Delegate.
A delegate defines the signature and return type of a method. The resulting delegate can reference any method with a matching signature.
Each instance of a delegate can forward a call to one or more methods that take those parameters and return the same type.
Once a method has been assigned to a delegate, it is called when the delegate is invoked.
![Page 52: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/52.jpg)
When ByVal keyword is used, it causes the parameter to be passed by value.
In this case, a copy of the original parameter is passed to the called module.
Thus any changes made to the copy of the parameter do not affect the original value of the parameter.
![Page 53: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/53.jpg)
When ByRef keyword is used, it sends a reference (pointer) to the original value to the called module rather than its copy.
Thus any changes made to the parameter in the function/procedure will cause the original value to be modified.
![Page 54: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/54.jpg)
Ctype is a general cast keyword that coerces an expression into any type.
It returns the result of explicitly converting an expression to a specified data type, object, structure, class, or interface.
If no conversion exists from the type of the expression to the specified type, a compile-time error occurs.
When Ctype is used to perform explicit conversion, execution is faster since it is compiled inline and hence no call to a procedure is involved to perform the conversion.
![Page 55: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/55.jpg)
Integer Type VB.NET CLR Type
8-bit Integer Byte System.Byte
16-bit Integer Short System.Int16
32-bit Integer Integer System.Int32
64-bit Integer Long System.Int64
![Page 56: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/56.jpg)
![Page 57: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/57.jpg)
The .NET Framework provides a run-time environment called the Common Language Runtime, which manages the execution of code and provides services that make the development process easier.
![Page 58: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/58.jpg)
Compilers and tools expose the runtime's functionality and enable you to write code that benefits from this managed execution environment.
Code developed with a language compiler that targets the runtime is called managed code.
![Page 59: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/59.jpg)
dotNET Tutorial for Beginners,India Community Initiative
Microsoft Visual Studio 2010 byMichael Halvorson, Microsoft
Microsoft Visual Basic 6.0 by Francesco Balena ,Microsoft Press
![Page 60: Visual Basic User Interface -IV](https://reader031.fdocuments.net/reader031/viewer/2022022419/58ad26d21a28ab02268b463b/html5/thumbnails/60.jpg)
THANK YOU