You are on page 1of 70

1

http://www.dreamincode.net/forums/topic /40143-introduction-to-graphs-in-vbnet/
Visual Basic .NET Syllabus
VB.NET 2005 Training The .NET Framework 1. Introducing Windows Forms 2. Implementing Class Library Object in VB.NET 2005 3. Introduction of .NET Architecture 4. Visual Studio.NET Namespaces 5. Designing a Form using Windows Forms Designer Window 6. Exploring the Forms Designer generated code 7. Adding Controls 8. Common Controls and Handling Control Events 9. Dialog Boxes in Visual Basic .NET 2005 10. Different date/time formats in Visual Basic .NET 2005 11. Common Windows Forms Controls Section 12. DomainUpDown and NumericUpDown 13. Creating Menu and Menu Items 14. Creating Multiple-Document Interface (MDI) Applications 15. Simple Data Binding 16. Complex Data Binding 17. Using the Data Form Wizard ADO.NET

18. Access and Manipulate SQL Server data - Using Ad Hoc Queries 19. Access and Manipulate Data - Working with Disk Files 20. Access and Manipulate SQL Server data - Using Stored Procedures 21. Access and Manipulate Data - The ADO .NET Object Model 22. Access and Manipulate Data - Using Datasets 23. Finding and Sorting Data in Datasets 24. Editing Data with ADO .NET XML CONCEPT 25. 26. 27. 28. 29. 30. 31. 32. Using XML Data Creating XML File using Windows Application Access Xml File using Data Control Converting Sql/Access Tables into Xml format System Side Development Creating Reports using Crystal Report Backup Reports in different formats (.doc, Sorting datas using Crystal Report by String, etc..,

Generate Reports

.pdf) Date, Generate .EXE 33. How to configure and deploy a windows Application file into Installation (setup.exe) file.

Introduction
What is Microsoft .Net Framework? The Microsoft .Net Framework is a platform that provides tools and technologies you need to build Networked Applications as well as Distributed Web Services and Web Applications. The .Net Framework provides the necessary compile time and run-time foundation to build and run any language that conforms to the Common Language Specification (CLS).The main two components of .Net Framework are Common Language Runtime (CLR) and .Net Framework Class Library (FCL).

The Common Language Runtime (CLR) is the runtime environment of the .Net Framework that executes and manages all running code like a Virtual Machine. The .Net Framework Class Library (FCL) is a huge collection of languageindependent and type-safe reusable classes. The .Net Framework Class Libraries (FCL) is arranged into a logical grouping according to their functionality and usability is called Namespaces. In the following sections

describes how to .Net Framework manages the code in compile time and run time. How to Microsoft .Net Framework Microsoft .Net Languages Source Code is compiled into Microsoft Intermediate Language (MSIL). MSIL we can call it as Intermediate Language (IL) or Common Intermediate Language (CIL). Microsoft Intermediate Language (MSIL) is a CPU independent set of instructions that can be converted to the native code. Metadata also created in the course of compile time with Microsoft Intermediate Language (MSIL) and stored it with the compiled code. Metadata is completely self-describing. Metadata is stored in a file called Manifest, and it contains information about the members, types, references and all the other data that the Common Language Runtime (CLR) needs for execution.
MSIL Meta Data [JIT ] CL R Outp ut

Source Code

.NET Compiler

The Common Language Runtime (CLR) uses metadata to locate and load classes, generate native code, provide security, and execute Managed Code. Both Microsoft Intermediate Language (MSIL) and Metadata assembled together is known as Portable Executable (PE) file. Portable Executable (PE) is supposed to be portable across all 32-bit operating systems by Microsoft .Net Framework.
During the runtime the Common Language Runtime (CLR)'s Just In Time (JIT) compiler converts the Microsoft Intermediate Language (MSIL) code into native code to the Operating System. The native code is Operating System independent and this code is known as Managed Code , that is, the language's functionality is managed by the .NET Framework . The Common Language Runtime (CLR) provides various Just In Time (JIT) compilers, and each works on a different architecture depends on Operating Systems, that means the same Microsoft Intermediate Language (MSIL) can be executed on different Operating Systems. In the following section you can see how Common Language Runtime (CLR) functions.

Common Language Runtime

The Common Language Runtime (CLR) is an Execution Environment. It works as a layer between Operating Systems and the applications written in .Net languages that conforms to the Common Language Specification (CLS). The main function of Common Language Runtime (CLR) is to convert the Managed Code into native code and then execute the Program. The Managed Code compiled only when it needed, that is it converts the appropriate instructions when each function is called. The Common Language Runtime (CLR)s Just In Time (JIT) compilation converts Intermediate Language (MSIL) to native code on demand at application run time. During the execution of the program ,the Common Language Runtime (CLR) manages memory, Thread execution, Garbage Collection (GC) , Exception Handling, Common Type System (CTS), code safety verifications, and other system services. The CLR (Common Language Runtime) defines the Common Type System (CTS), which is a standard type system used by all .Net languages. That means all .NET programming languages uses the same representation for common Data Types , so Common Language Runtime (CLR) is a language-independent runtime environment. The Common Language Runtime (CLR) environment is also referred to as a managed environment, because during the execution of a program it also controls the interaction with the Operating System. In the coming section you can see what are the main functions of Common Language Runtime (CLR). How to Common Language Runtime The Common Language Runtime (CLR) is an Execution Environment. Common Language Runtime (CLR)'s main tasks are to convert the .NET Managed Code to native code, manage running code like a Virtual Machine and also controls the interaction with the Operating System. Common Language Runtime (CLR) manages Thread executions, Memory Management that is allocation of Objects and Buffers , Garbage Collection (GC) - Clean up the unused Objects and buffers , Exception Handling, Common Type System (CTS) that is all .NET language that conforms to the Common Language Specification (CLS) have the same primitive Data Types, Code safety verifications - code can be verified to ensure type safety, Language integration that is Common Language Runtime (CLR) follow a set of specification called Common Language Specification (CLS) , this will ensure the interoperability between languages, Integrated security and other system services. .Net Framework Class Library (FCL)

The .Net Framework class library (FCL) provides the core functionality of .Net Framework architecture. The .Net Framework Class Library (FCL) includes a huge collection of reusable classes, interfaces, and value types that expedite and optimize the development process and provide access to system functionality. The .Net Framework class library (FCL) organized in a hierarchical tree structure and it is divided into Namespaces. Namespaces is a logical grouping of types for the purpose of identification. Framework class library (FCL) provides the consistent base types that are used across all .NET enabled languages. The Classes are accessed by namespaces, which reside within Assemblies. The System Namespace is the root for types in the .NET Framework. The .Net Framework class library (FCL) classes are managed classes that provide access to System Services . The .Net Framework class library (FCL) classes are object oriented and easy to use in program developments. Moreover, third-party components can integrate with the classes in the .NET Framework.

Framework, Languages, And Tools

VB VB

VC++ VC++

VC# VC#

JScript JScript

Visual Studio.NET Studio.NET Visual

Common Common Language Language Specification Specification ASP.NET: ASP.NET: Web Web Services Services and and Web Web Forms Forms Windows Windows Forms Forms

ADO.NET: ADO.NET: Data Data and and XML XML Base Base Class Class Library Library Common Common Language Language Runtime Runtime
Common Language Specification

Common Language Specification (CLS) is a set of basic language features that .Net Languages needed to develop Applications and Services , which are compatible with the .Net Framework. When there is a situation to communicate Objects written in different .Net Complaint languages, those objects must expose the features that are common to all the languages. Common Language Specification (CLS) ensures complete interoperability among applications, regardless of the language used to create the application. Common Language Specification (CLS) defines a subset of Common Type System (CTS). Common Type System (CTS) describes a set of types that can use different .Net languages have in common, which ensure that objects written in different languages can interact with each other. Most of the members defined by types in the .NET Framework Class Library (FCL) are Common Language Specification (CLS) compliant Types. Moreover Common Language Specification (CLS) standardized by ECMA. Microsoft Intermediate Language MSIL stands for Microsoft Intermediate Language. We can call it as Intermediate Language (IL) or Common Intermediate Language (CIL). During the compile time, the compiler convert the source code into Microsoft Intermediate Language (MSIL) .Microsoft Intermediate Language (MSIL) is a CPU-independent set of instructions that can be efficiently converted to the native code. During the runtime the Common Language Runtime (CLR)'s Just In Time (JIT) compiler converts the Microsoft Intermediate Language (MSIL) code into native code to the Operating System. When a compiler produces Microsoft Intermediate Language (MSIL), it also produces Metadata. The Microsoft Intermediate Language (MSIL) and Metadata are contained in a portable executable (PE) file. Microsoft Intermediate Language (MSIL) includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations Just In Time Compiler The .Net languages, which is conforms to the Common Language Specification (CLS), uses its corresponding runtime to run the application on different Operating Systems. During the code execution time, the Managed Code compiled only when it is needed, that is it converts the appropriate instructions to the native code for execution just before when each function is called. This

process is called Just In Time (JIT) compilation, also known as Dynamic Translation. With the help of Just In Time Compiler (JIT) the Common Language Runtime (CLR) doing these tasks. The Common Language Runtime (CLR) provides various Just In Time compilers (JIT) and each works on a different architecture depending on Operating System. That is why the same Microsoft Intermediate Language (MSIL) can be executed on different Operating Systems without rewrite the source code. Just In Time (JIT) compilation preserves memory and save time during application initialization. Just In Time (JIT) compilation is used to run at high speed, after an initial phase of slow interpretation. Just In Time Compiler (JIT) code generally offers far better performance than interpreters. .Net Metadata Metadata in .Net is binary information which describes the characteristics of a resource. This information include Description of the Assembly , Data Types and members with their declarations and implementations, references to other types and members , Security permissions etc. A module's metadata contains everything that needed to interact with another module. During the compile time Metadata created with Microsoft Intermediate Language (MSIL) and stored in a file called a Manifest . Both Metadata and Microsoft Intermediate Language (MSIL) together wrapped in a Portable Executable (PE) file. During the runtime of a program Just In Time (JIT) compiler of the Common Language Runtime (CLR) uses the Metadata and converts Microsoft Intermediate Language (MSIL) into native code. When code is executed, the runtime loads metadata into memory and references it to discover information about your code's classes, members, inheritance, and so on. Moreover Metadata eliminating the need for Interface Definition Language (IDL) files, header files, or any external method of component reference.

Designing a Form using Windows Forms Designer Window

Variable Deceleration:
In C Language Syntax Data type variable name; Example int a, b, c; In VB.NET Syntax Dim variable name as Data type Example Dim a, b, c as integer Object Name Deceleration: In C++ Language

10 Syntax: Class name Object name Example: Student SS;

In VB.NET Syntax: Dim Object name as New Class name Example: Dim SS as New Student Addition Program:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Me.Label3.Text = Val(Me.TextBox1.Text) + Val(Me.TextBox2.Text) Dim a, b, c As Integer a = Me.TextBox1.Text b = Me.TextBox2.Text c = a + b Me.Label3.Text = c End Sub

Login Window:

11

Code for Login without using backend (sql-server)


Public Class LoginForm1 Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click If Me.UsernameTextBox.Text = "Apollo" And Me.PasswordTextBox.Text = "kumar" Then MsgBox("login Sucess") Dim f1 As New Form1 f1.Show() Else MsgBox("Login Failed") End If End Sub Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click Me.Close() End Sub End Class

Common Controls and Handling Control Events

Combo box:

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i As Integer

12
For i = 1940 To 2030 Me.ComboBox1.Items.Add(i) Next To add String Values Me.ComboBox2.Items.Add("apr") Me.ListBox1.Items.Add("apr") End Sub

DateTime Picker

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged Me.Label1.Text = Me.DateTimePicker1.Value End Sub

MonthCalendar

Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged Me.Label1.Text = Me.MonthCalendar1.SelectionEnd End Sub

13

Treeview with Textbox

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect If Me.TreeView1.SelectedNode.Text = ".Net Tech" Then Me.TextBox1.Text = ".Net Technology" Me.TextBox2.Text = "15000" ElseIf Me.TreeView1.SelectedNode.Text = "Java Tech" Then Me.TextBox1.Text = "Java Technology" Me.TextBox2.Text = "15000" ElseIf Me.TreeView1.SelectedNode.Text = "MMV" Then Me.TextBox1.Text = "MMV" Me.TextBox2.Text = "55000" End If End Sub

Picture Box and Progress bar with Timer Control

14

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.PictureBox1.Image = Image.FromFile("F:\Ramji\basiccontrol\basiccontrol\img\7.jpg") End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Me.ProgressBar1.Value += 5 If Me.ProgressBar1.Value <= 20 Then Me.PictureBox2.Image = Image.FromFile("F:\Ramji\basiccontrol\basiccontrol\img\nokia-500000.jpg") ElseIf Me.ProgressBar1.Value <= 40 Then Me.PictureBox2.Image = Image.FromFile("F:\Ramji\basiccontrol\basiccontrol\img\5.jpg") ElseIf Me.ProgressBar1.Value <= 60 Then Me.PictureBox2.Image = Image.FromFile("F:\Ramji\basiccontrol\basiccontrol\img\1.JPG") ElseIf Me.ProgressBar1.Value <= 80 Then Me.PictureBox2.Image = Image.FromFile("F:\Ramji\basiccontrol\basiccontrol\img\nokia5310_001[1].jpg") ElseIf Me.ProgressBar1.Value <= 100 Then Me.PictureBox2.Image = Image.FromFile("F:\Ramji\basiccontrol\basiccontrol\img\nokia_n96_00.jpg" ) ElseIf Me.ProgressBar1.Value <= 120 Then Me.PictureBox2.Image = Image.FromFile("F:\Ramji\basiccontrol\basiccontrol\img\nokia_2630_2[1]. jpg") ElseIf Me.ProgressBar1.Value <= 140 Then Me.PictureBox2.Image = Image.FromFile("F:\Ramji\basiccontrol\basiccontrol\img\nokia_2630[1].jp g") ElseIf Me.ProgressBar1.Value <= 160 Then Me.PictureBox2.Image = Image.FromFile("F:\Ramji\basiccontrol\basiccontrol\img\nokia-e5100[1].jpg") ElseIf Me.ProgressBar1.Value <= 180 Then

15
Me.PictureBox2.Image = Image.FromFile("F:\Ramji\basiccontrol\basiccontrol\img\nokia-630000[1].jpg") ElseIf Me.ProgressBar1.Value <= 200 Then Me.PictureBox2.Image = Image.FromFile("F:\Ramji\basiccontrol\basiccontrol\img\5.jpg") End If If Me.ProgressBar1.Value = 200 Then Me.Timer1.Dispose() End If End Sub

Trackbar

Public Class Form1 Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll Label1.Text = "The slider value is: " & TrackBar1.Value End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TrackBar1.Minimum = 1 TrackBar1.Maximum = 1000 TrackBar1.TickFrequency = 50 TrackBar1.SmallChange = 50 TrackBar1.LargeChange = 100 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Close()

16
End Sub End Class

Dialog Boxes in Visual Basic .NET 2005

Code for Message Box


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim msg, heading As String Dim res As DialogResult heading = "Example message box" msg = "ok button only" res = MsgBox(msg, MsgBoxStyle.OkOnly, heading) msg = "ok cancel button" res = MsgBox(msg, MsgBoxStyle.OkCancel, heading) If res = Windows.Forms.DialogResult.OK Then MsgBox("you have clicked ok") End If If res = Windows.Forms.DialogResult.Cancel Then MsgBox("you have clicked cancel") End If

17
msg = "retry cancel button" res = MsgBox(msg, MsgBoxStyle.RetryCancel, heading) If res = Windows.Forms.DialogResult.Retry Then MsgBox("you have clicked retry") End If msg res msg res msg res msg res msg res heading) heading) = = = = = = = = = = "critical icon" MsgBox(msg, MsgBoxStyle.Critical, heading) "question icon" MsgBox(msg, MsgBoxStyle.Question, heading) "exclamation icon" MsgBox(msg, MsgBoxStyle.Exclamation, heading) "information icon" MsgBox(msg, MsgBoxStyle.Information, heading) "yesno button+information icon" MsgBox(msg, MsgBoxStyle.YesNo + MsgBoxStyle.Information,

msg = "yesnobutton+question icon" res = MsgBox(msg, MsgBoxStyle.YesNo + MsgBoxStyle.Question, msg = "yesnobutton+informationicon"

End Sub

Different date/time formats in Visual Basic .NET 2005

Code for Different Date/Time


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = Format(DateTime.Now, "G") Label1.Text = "general date:month date year" MsgBox("proceed") TextBox1.Text = Format(DateTime.Now, "D") Label1.Text = "long date"

18
MsgBox("proceed") TextBox1.Text = Format(DateTime.Now, "d") Label1.Text = "short date" MsgBox("proceed") TextBox1.Text = Format(DateTime.Now, "f") Label1.Text = "fulldate and time" MsgBox("proceed") TextBox1.Text = Format(DateTime.Now, "r") Label1.Text = "GMT time" MsgBox("proceed") TextBox1.Text = Format(DateTime.Now, "T") Label1.Text = "long time" MsgBox("proceed") TextBox1.Text = Format(DateTime.Now, "t") Label1.Text = "short time" MsgBox("proceed") TextBox1.Text = Format(DateTime.Now, "y") Label1.Text = "year and month" MsgBox("proceed") TextBox1.Text = Format(DateTime.Now, "MM/yyyy") Label1.Text = "month and year" MsgBox("proceed") TextBox1.Text = Format(DateTime.Now, "dd/MM/yyyy") Label1.Text = "date month and year" MsgBox("proceed") TextBox1.Text = DateTime.Now.ToLongDateString Label1.Text = "long date string" MsgBox("proceed") TextBox1.Text = DateTime.Now.ToShortDateString Label1.Text = "short date string" MsgBox("proceed") TextBox1.Text = DateTime.Now.ToLongTimeString Label1.Text = "long time string" MsgBox("proceed") TextBox1.Text = DateTime.Now.ToShortTimeString Label1.Text = "short time string" MsgBox("proceed") TextBox1.Text = DateTime.Now.ToLocalTime Label1.Text = "local time=currenttime" MsgBox("proceed") TextBox1.Text = DateTime.Now.ToUniversalTime Label1.Text = "universal time=currenttime" MsgBox("proceed") TextBox1.Text = DateTime.Now.Year If Date.IsLeapYear(DateTime.Now.Year) Then Label1.Text = "leap year" Else Label1.Text = "not leap year" End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Me.Label2.Text = Format(DateTime.Now, "G") End Sub

19

File Concept
Creating Folder and File Without mode

Imports System.IO Public Class Form1

Create a Text File:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim writeFile As System.IO.TextWriter = New StreamWriter("D:\Reader.txt") writeFile.WriteLine("File Hanling Class") writeFile.Flush() writeFile.Close() End Sub

20

Read a Text File:


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim line As String Dim readFile As System.IO.TextReader = New StreamReader("D:\Reader.txt") line = readFile.ReadToEnd() MsgBox(line) readFile.Close() End Sub

Create a Folder:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If Directory.Exists("D:\testDir1") Then 'shows message if testdir1 exist MsgBox("Directory 'testDir' Exist ") Else 'create the directory testDir1 Directory.CreateDirectory("D:\testDir1") MsgBox("testDir1 created ! ") 'create the directory testDir2 Directory.CreateDirectory("D:\testDir1\testDir2") MsgBox("testDir2 created ! ") 'move the directory testDir2 as testDir in c:\ ' Directory.Move("D:\testDir1\testDir2", "D:\testDir\") ' MsgBox("testDir2 moved ") 'delete the directory testDir1 ' Directory.Delete("D:\testDir1") ' MsgBox("testDir1 deleted ") End If End Sub

Creating Folder and File With mode

21

Imports System.io Public Class Form2

Create a Text File:


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim writeStream As FileStream writeStream = New FileStream("D:\testBinary.txt", FileMode.Create) Dim writeBinay As New BinaryWriter(writeStream) writeBinay.Write("This is a test for BinaryWriter 12345 !") writeBinay.Close() End Sub

Read a Text File:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim readStream As FileStream Dim msg As String readStream = New FileStream("D:\testBinary.txt", FileMode.Open) Dim readBinary As New BinaryReader(readStream) msg = readBinary.ReadString() MsgBox(msg) readStream.Close() End Sub End Class

Input Box

22

Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a, b, c As Integer a = (InputBox("Enter first value", "Example pgm for Addition", "0", 100, 500)) b = (InputBox("Enter first value", "Example pgm for Addition", "0", 200, 100)) c = (InputBox("Result", "Result", Val(a + b), 200, 100)) End Sub End Class

Creating Calculator using VB.Net Code:

23
Public Class Form1 Dim a As Integer Dim n, m As Double Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Me.TextBox1.Text = TextBox1.Text + "1" End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Me.TextBox1.Text = TextBox1.Text + "2" End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Me.TextBox1.Text = TextBox1.Text + "3" End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click Me.TextBox1.Text = TextBox1.Text + "4" End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click Me.TextBox1.Text = TextBox1.Text + "5" End Sub Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click Me.TextBox1.Text = TextBox1.Text + "6" End Sub Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click Me.TextBox1.Text = TextBox1.Text + "7" End Sub Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click Me.TextBox1.Text = TextBox1.Text + "8" End Sub Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click Me.TextBox1.Text = TextBox1.Text + "9" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

24
Me.TextBox1.Text = TextBox1.Text + "0" End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If m = 1 Then a = TextBox1.Text + n Me.TextBox1.Text = a ElseIf m = 2 Then a = n - TextBox1.Text Me.TextBox1.Text = a ElseIf m = 3 Then a = TextBox1.Text * n Me.TextBox1.Text = a ElseIf m = 4 Then a = n / TextBox1.Text Me.TextBox1.Text = a Else MsgBox("error") End If End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click n = TextBox1.Text m = 1 TextBox1.Text = "" End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click n = TextBox1.Text m = 2 TextBox1.Text = "" End Sub Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click n = TextBox1.Text m = 3 TextBox1.Text = "" End Sub Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click n = TextBox1.Text m = 4 TextBox1.Text = "" End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.TextBox1.Text = "" End Sub

25

Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click If TextBox1.TextLength = 0 Then Exit Sub Else Me.TextBox1.Text = Me.TextBox1.Text.Remove(Me.TextBox1.TextLength - 1) End If End Sub End Class

Using Checkbox and Radio Button:

Public Class Form2 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Me.CheckBox1.CheckState = CheckState.Checked Then Me.Label1.Text = "The selected Item is = " + Me.CheckBox1.Text ElseIf Me.CheckBox2.CheckState = CheckState.Checked Then Me.Label1.Text = "The selected Item is = " + Me.CheckBox2.Text 'Radio Button ElseIf Me.RadioButton1.Checked = True Then Me.Label1.Text = "The selected Item is = " + Me.RadioButton1.Text ElseIf Me.RadioButton2.Checked = True Then Me.Label1.Text = "The selected Item is = " + Me.RadioButton2.Text

26
End If End Sub Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged Me.CheckBox1.Checked = False End Sub Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged Me.CheckBox2.Checked = False End Sub End Class

How to like command in VB.Net

Imports System.Data.SqlClient Public Class Form1 Dim con As New SqlConnection("Data Source=hitha;Initial Catalog=Wipro;Integrated Security=True") Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cboProducts.Items.AddRange(New Object() {"<ALL>", "A", "B", "C", "D", "E", "F", "G", _ "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}) cboProducts.Text = "<ALL>" Me.ComboBox1.Items.AddRange(New Object() {"<ALL>", "A", "B", "C", "D", "E", "F", "G", _ "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"})

27
Me.ComboBox1.Text = "<ALL>" Me.ComboBox2.Items.AddRange(New Object() {"<ALL>", "A", "B", "C", "D", "E", "F", "G", _ "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}) Me.ComboBox2.Text = "<ALL>" Me.ComboBox3.Items.AddRange(New Object() {"<ALL>", "A", "B", "C", "D", "E", "F", "G", _ "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}) Me.ComboBox3.Text = "<ALL>" End Sub Private Sub cmdProductNames_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles filter.Click Dim com As New SqlCommand("select * from edet where Ename like '" + Me.cboProducts.Text + "%' ", con) con.Open() Dim da As New SqlDataAdapter(com) Dim ds As New DataSet da.Fill(ds) Me.DataGridView1.DataSource = ds.Tables(0) con.Close() End Sub Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged Dim com As New SqlCommand("select * from edet order by Ename asc", con) con.Open() Dim da As New SqlDataAdapter(com) Dim ds As New DataSet da.Fill(ds) Me.DataGridView1.DataSource = ds.Tables(0) con.Close() End Sub Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged Dim com As New SqlCommand("select * from edet order by Ename desc", con) con.Open() Dim da As New SqlDataAdapter(com) Dim ds As New DataSet da.Fill(ds) Me.DataGridView1.DataSource = ds.Tables(0) con.Close()

28
End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim com As New SqlCommand("select * from edet where Ename like '%" + Me.ComboBox2.Text + "%' + '" + Me.ComboBox3.Text + "%' ", con) con.Open() Dim da As New SqlDataAdapter(com) Dim ds As New DataSet da.Fill(ds) Me.DataGridView1.DataSource = ds.Tables(0) con.Close() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim com As New SqlCommand("select * from edet where name = '" & Me.TextBox1.Text & "'", con) con.Open() Dim da As New SqlDataAdapter(com) Dim ds As New DataSet da.Fill(ds) Me.DataGridView1.DataSource = ds.Tables(0) con.Close() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim com As New SqlCommand("select * from edet where name = '" & Me.TextBox1.Text & "'", con) con.Open() Dim da As New SqlDataAdapter(com) Dim ds As New DataSet da.Fill(ds) Me.DataGridView1.DataSource = ds.Tables(0) con.Close() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim com As New SqlCommand("select * from edet where name like '%" + Me.ComboBox1.Text + "'", con) con.Open() Dim da As New SqlDataAdapter(com) Dim ds As New DataSet da.Fill(ds) Me.DataGridView1.DataSource = ds.Tables(0) con.Close() End Sub End Class

Tree view Control:

29

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect If Me.TreeView1.SelectedNode.Text = "1" Then Me.WebBrowser1.Navigate("D:\Praveen\GPK\Praveen vbnet\Ammu\Treeview\Treeview\1.txt") ElseIf Me.TreeView1.SelectedNode.Text = "2" Then Me.WebBrowser1.Navigate("D:\Praveen\GPK\Praveen vbnet\Ammu\Treeview\Treeview\ccc.txt") ElseIf Me.TreeView1.SelectedNode.Text = "3" Then Me.WebBrowser1.Navigate("E:\Amutha\Treeview\Treeview\Net ques.doc") ElseIf Me.TreeView1.SelectedNode.Text = "4" Then Me.WebBrowser1.Navigate("E:\Amutha\Treeview\Treeview\1.txt") ElseIf Me.TreeView1.SelectedNode.Text = "5" Then Me.WebBrowser1.Navigate("E:\Amutha\Treeview\Treeview\XP Hard Disk.vhd") ElseIf Me.TreeView1.SelectedNode.Text = "6" Then Me.WebBrowser1.Navigate("E:\Amutha\Treeview\Treeview\key.txt") ElseIf Me.TreeView1.SelectedNode.Text = "7" Then Me.WebBrowser1.Navigate("E:\Amutha\Treeview\Treeview\vwd.webinfo") ElseIf Me.TreeView1.SelectedNode.Text = "8" Then Me.WebBrowser1.Navigate("E:\Amutha\Treeview\Treeview\WIN51IA") ElseIf Me.TreeView1.SelectedNode.Nodes(0).Text = "9" Then Me.WebBrowser1.Navigate("E:\Amutha\Treeview\Treeview\WIN51IA")

30

ElseIf Me.TreeView1.SelectedNode.Text = "8" Then Me.WebBrowser1.Navigate("E:\Amutha\Treeview\Treeview\WIN51IA") ElseIf Me.TreeView1.SelectedNode.Text = "8" Then Me.WebBrowser1.Navigate("E:\Amutha\Treeview\Treeview\WIN51IA") End If End Sub

Using Print Dialog Control:

Public Class Form1 Dim savedFile As String = "" 'Nothing Dim changed As Integer = 0 Dim frmTitle As String = "csWriting Pad - New Document" Dim pDocumentName As String

Code to Open a file:


Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click Me.OpenFileDialog1.Title = "Select the file you want to open." Me.OpenFileDialog1.Filter = "All Supported Document Formats (*.doc; *.rtf; *.txt)|*.txt;*.doc;*.rtf|All Text Document Types (*.txt)|*.txt|Rich Text Format (*.rtf)|*.rtf| ||All Documents and Files (*.*)|*.*" Dim dlgRst As DialogResult = Me.OpenFileDialog1.ShowDialog ' 'A filename would have been selected if the user pressed OK. The

31
'dialog will not allow a user to successfully select OK without 'file being selected. Well, thats my understanding of it. :) If dlgRst = Windows.Forms.DialogResult.OK Then ' mnuClose.PerformClick() savedFile = Me.OpenFileDialog1.FileName If savedFile.EndsWith(".txt") Or savedFile.EndsWith(".doc") Then Me.RichTextBox1.LoadFile(savedFile, RichTextBoxStreamType.PlainText) ElseIf savedFile.EndsWith(".rtf") Then Me.RichTextBox1.LoadFile(savedFile, RichTextBoxStreamType.RichText) Me.RichTextBox1.LoadFile(savedFile) ', RichTextBoxStreamType.PlainText) End If ' changed = 0 'frmTitle = "csWriting Pad - " & extractFilename() Me.Text = frmTitle End If End Sub Else

Code for Print Preview:


Private Sub PrintpreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintpreviewToolStripMenuItem.Click ' Me.PrintPreviewDialog1.Document = PrintDocument1 Me.PrintPreviewDialog1.StartPosition = FormStartPosition.CenterParent Me.PrintPreviewDialog1.ShowInTaskbar = True Me.PrintPreviewDialog1.Text = "csWritingPad - Print Preview" Me.PrintPreviewDialog1.ShowDialog(Me) End Sub

Code for Page Setup:


Private Sub PagesetupToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PagesetupToolStripMenuItem.Click '

32
' Dim pgSettings As New Drawing.Printing.PageSettings Me.PageSetupDialog1.PageSettings = pgSettings PageSetupDialog1.Document = PrintDocument1 PageSetupDialog1.ShowDialog(Me) End Sub

Code for to Print a Document:


Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click ' PrintDocument1.DocumentName = pDocumentName Me.PrintDialog1.Document = PrintDocument1 Dim dlg As DialogResult = PrintDialog1.ShowDialog(Me) If dlg = Windows.Forms.DialogResult.OK Then PrintDocument1.Print() Else MessageBox.Show("The printing task was cancelled.", " Print Canceled", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End Sub Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage ' Dim b As Brush = New SolidBrush(Me.RichTextBox1.ForeColor) e.Graphics.DrawString(Me.RichTextBox1.Text, Me.RichTextBox1.Font, b, 0, 0) e.HasMorePages = False End Sub Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click Me.RichTextBox1.Text = "" End Sub End Class

33

How to Create a XML File:

Imports System.Xml Imports System.Data.OleDb Imports System.IO Public Class Form1

Database Connection code


Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\sample.mdb")

Code for to Convert the Sql Table into XML File


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim com As New OleDbCommand("select * from ee", conn) conn.Open() Dim da As New OleDbDataAdapter(com) Dim ds As New DataSet da.Fill(ds) ds.WriteXml("E:\Product.xml") conn.Close() MsgBox("Done") End Sub

Code For to Read a Converted Xml File in Table format using DataGridview Control:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim xmlfile As XmlReader xmlfile = XmlReader.Create("E:\Product.xml", New XmlReaderSettings)

34
Dim ds As New DataSet ds.ReadXml(xmlfile) Me.DataGridView1.DataSource = ds.Tables(0) End Sub

Code to create a XML file using Coding:


Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim writer As New XmlTextWriter("E:\Product.xml", System.Text.Encoding.UTF8) writer.WriteStartDocument(True) writer.WriteStartElement("table") createnode(1, "product1", "1000", writer) createnode(2, "product2", "1300", writer) createnode(3, "product3", "1400", writer) writer.WriteEndElement() writer.WriteEndDocument() writer.Close() MsgBox("xml file created") End Sub Private Sub createnode(ByVal pID As String, ByVal Pname As String, ByVal price As String, ByVal writer As XmlTextWriter) writer.WriteStartElement("productrr") writer.WriteStartElement("productid") writer.WriteString(pID) writer.WriteEndElement() writer.WriteStartElement("productname") writer.WriteString(Pname) writer.WriteEndElement() writer.WriteStartElement("productprice") writer.WriteString(price) writer.WriteEndElement() writer.WriteEndElement() End Sub End Class

How to Create a loading window using Progress bar and Timer Control:

35

Code:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Me.ProgressBar1.Value += 5 If Me.ProgressBar1.Value <= 30 Then Me.Label4.Text = "Collecting Application Data's" ElseIf Me.ProgressBar1.Value <= 60 Then Me.Label4.Text = "Restore Database Details" ElseIf Me.ProgressBar1.Value <= 80 Then Me.Label4.Text = "Please Wait..............." End If If Me.ProgressBar1.Value = 100 Then Me.Timer1.Dispose() Dim logi As New LoginForm1 logi.Show() Me.Hide() End If End Sub

ADO.NET Concept:
How to Insert, Edit, Select, and Delete the data using Sql-server with VB.NET: Declaring Namespace for Sql-server as client
Imports System.Data.SqlClient Public Class Form2

Database Connection Code

36
Dim conn As New SqlConnection("Data Source=kassim;Initial Catalog=stud;Integrated Security=True;Pooling=False")

Insert Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Me.TextBox1.Text = "" Then MsgBox("Enter Student name") Me.TextBox1.Focus() ElseIf Me.TextBox2.Text = "" Then MsgBox("Enter Father name") Me.TextBox2.Focus() End If

Insert Code:

Table name

Dim save As New SqlCommand("insert into ss2 values ('" & Me.TextBox1.Text & "','" & Me.TextBox2.Text & "', _ '" & Me.ComboBox1.SelectedItem & "','" & Me.RichTextBox1.Text & "', _ '" & Me.MaskedTextBox1.Text & "','" & Me.TextBox3.Text & "' )", conn) conn.Open() save.ExecuteNonQuery() conn.Close() End Sub

Tab Control:

37

To View Data from Table using MS-Access as Backend:


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim detail As New OleDbCommand("select * from studetail", conn) conn.Open() Dim da As New OleDbDataAdapter(detail) Dim ds As New DataSet da.Fill(ds) Me.DataGridView1.DataSource = ds.Tables(0) conn.Close() End Sub

38

To Read Data One by One From Table:


Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim read As New OleDbCommand("select * from studetail where sno='" + Me.TextBox1.Text + "'", conn) conn.Open() Dim dr As OleDbDataReader dr = read.ExecuteReader While (dr.Read) Me.TextBox2.Text = dr("studentname") Me.TextBox3.Text = dr("course") Me.TextBox4.Text = dr("fees") End While dr.Close() conn.Close() End Sub

39

To Delete a Particular Record from Table:


Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Dim del As New OleDbCommand("delete from studetail where sno='" + Me.TextBox1.Text + "'", conn) conn.Open() del.ExecuteNonQuery() conn.Close() End Sub

To Edit a Record in Table:


Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim updt As New OleDbCommand("update studetail set name='" + Me.TextBox2.Text + "' where sno='" + Me.TextBox1.Text + "'", conn) conn.Open() updt.ExecuteNonQuery() conn.Close() End Sub

40 TO Read a Data by Data from Table using DataBinding:

Public Class Form1 Dim con As New SqlConnection("Data Source=kassim;Initial Catalog=Apollo;Integrated Security=True;Pooling=False") Dim databydata As CurrencyManager Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim com As New SqlCommand("select * from raj order by itemcode", con) 'establish StudentID data adapter/data table Dim da As New SqlDataAdapter() da.SelectCommand = com Dim ttable As New DataTable() da.Fill(ttable) Me.TextBox1.DataBindings.Add("Text", ttable, "Itemcode") Me.TextBox2.DataBindings.Add("Text", ttable, "Itemname") Me.TextBox3.DataBindings.Add("Text", ttable, "qty") Me.TextBox4.DataBindings.Add("Text", ttable, "price") Me.TextBox5.DataBindings.Add("Text", ttable, "Total") databydata = DirectCast(Me.BindingContext(ttable), CurrencyManager) End Sub

For To View Next data from Table by Clicking Button

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click databydata.Position += 1 End Sub

41 For To View Previous data from Table by Clicking Button


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click databydata.Position -= 1 End Sub End Class

Menu Control:

'To create a notepad using vb.net Public Class Form1 Dim savedFile As String = "" 'Nothing Dim frmTitle As String = "csWriting Pad - New Document" Dim pDocumentName As String Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click Me.RichTextBox1.Text = "" End Sub

Using Open File Dialog Control:


Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click

42
Me.OpenFileDialog1.Title = "open" Me.OpenFileDialog1.Filter = "All Supported Document Formats (*.doc; *.rtf; *.txt)|*.txt;*.doc;*.rtf| All Text Document Types (*.txt)|*.txt|Rich Text Format (*.rtf)|*.rtf| ||All Documents and Files (*.doc)|*.doc" Me.OpenFileDialog1.FilterIndex = 1 Dim dlgRst As DialogResult = OpenFileDialog1.ShowDialog ' 'A filename would have been selected if the user pressed OK. The 'dialog will not allow a user to successfully select OK without 'file being selected. Well, thats my understanding of it. :) If dlgRst = Windows.Forms.DialogResult.OK Then ' mnuClose.PerformClick() savedFile = OpenFileDialog1.FileName If savedFile.EndsWith(".txt") Or savedFile.EndsWith(".doc") Then Me.RichTextBox1.LoadFile(savedFile, RichTextBoxStreamType.PlainText) ElseIf savedFile.EndsWith(".rtf") Then RichTextBox1.LoadFile(savedFile, RichTextBoxStreamType.RichText) Else RichTextBox1.LoadFile(savedFile) ', RichTextBoxStreamType.PlainText) End If Me.Text = frmTitle Me.ToolStripStatusLabel5.Text = "Status: No changes has occured since you last saved the document." End If End Sub Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged Me.ToolStripStatusLabel1.Text = "Cursor Position: " & RichTextBox1.SelectionStart.ToString Me.ToolStripStatusLabel2.Text = "Current Line: " & RichTextBox1.GetLineFromCharIndex(RichTextBox1.SelectionStart) + 1 Me.ToolStripStatusLabel3.Text = "Total Lines: " & RichTextBox1.GetLineFromCharIndex(RichTextBox1.Text.Length) + 1 Me.ToolStripStatusLabel4.Text = "Total Characters: " & RichTextBox1.Text.Length.ToString End Sub

43
Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click Me.RichTextBox1.Cut() End Sub Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click Me.RichTextBox1.Copy() End Sub Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click Me.RichTextBox1.Paste() End Sub Private Sub SelectallToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectallToolStripMenuItem.Click Me.RichTextBox1.SelectAll() End Sub End Class

WEB BROWSER:
1)File >new project>windows application (name it web browser or what ever)

44 2) Make screen size to any size but big enough to see an entire web browser. 3) Add a Panel and dock it to the top (when clicked on the panel. Properties window on the right Dock" )

45 4) Personally i don't like the default color but that is not important but if you insist on changing the color...

5) Add a text box and a buttons to the panel

6) Web browser. Just drag and drop it

46

*ok don't rename anything ( you can change the text but NOT the name unless you change the coding) e.g. Say *originally it was " textbox1" and you rename it "Type here" you would have to put "Typehere.Text" understand? ) *double click the button so it opens the code window Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click

47 WebBrowser1.Navigate(TextBox1.Text) End Sub


Back Button

Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click WebBrowser1.GoBack() End Sub Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As Forwar System.EventArgs) Handles d PictureBox2.Click Button WebBrowser1.GoForward() End Sub

Refresh Button

Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click WebBrowser1.Refresh() End Sub

Crystal Reports
VB.NET Crystal Reports for Beginners Start your first VB.NET Crystal Reports. All Crystal Reports programming samples in this tutorials is based on the following database (crystaldb). Please take a look at the database structure before you start this tutorial - Click here to see Database Structure .

48

Open Visual Studio .NET and select a new Visual Basic .NET Project.

Create a new Crystal Reports for Product table from the above database crystalDB. The Product Table has three fields (Product_id, Product_name, and Product_price) and we are showing the whole table data in the Crystal Reports. From main menu in Visual Studio select PROJECT-->Add New Item. Then Add New Item dialogue will appear and select Crystal Reports from the dialogue box.

49

Select Report type from Crystal Reports gallery.

Accept the default settings and click OK. Next step is to select the appropriate connection to your database. Here we are going to select OLEDB connection for SQL Server Select OLE DB (ADO) from Create New Connection .

50

Select Microsoft OLE DB Provider for SQL Server .

Next screen is the SQL Server authentication screen . Select your Sql Server name , enter userid , password and select your Database Name . Click next , Then the screen shows OLE DB Property values , leave it as it is , and click finish.

51

Then you will get your Server name under OLEDB Connection from there select database name (Crystaldb) and click the tables , then you can see all your tables from your database. From the tables list select Product table to the right side list .

Click Next Button Select all fields from Product table to the right side list .

Click Finish Button. Then you can see the Crystal Reports designer window . You can arrange the design according your requirements. Your screen look like the following picture.

52

Now the designing part is over and the next step is to call the created Crystal Reports in VB.NET through Crystal Reports Viewer control . Select the default form (Form1.vb) you created in VB.NET and drag a button and CrystalReportViewer control to your form.

Select Form's source code view and put the code on top Imports CrystalDecisions.CrystalReports.Engine

53

Put the following source code in the button click event VB.NET Source Code
Imports CrystalDecisions.CrystalReports.Engine Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cryRpt As New ReportDocument cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt") CrystalReportViewer1.ReportSource = cryRpt CrystalReportViewer1.Refresh() End Sub End Class

NOTES: cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt") The Crystal Reports is in your project location, there you can see CrystalReport1.rpt . So give the full path name of report here. After you run the source code you will get the report like this.

54

Hope this tutorial helps you to create your first Crystal Reports.

VB.NET Crystal Reports from multiple tables All Crystal Reports programming samples in this tutorials is based on the following database (crystaldb) . Please take a look at the database structure before you start this tutorial - Click here to see Database Structure . Here we are going to do is to generate Crystal Reports from multiple tables. Here we have three table (ordermaster , orderdetails amd product ) and we are generating report from these three tables by connecting each tables with their related fields. Open Visual Studio .NET and select a new Visual Basic .NET Project.

From main menu in Visual Studio select PROJECT-->Add New Item . Then Add New Item dialogue will appear and select Crystal Reports from the dialogue box.

55

Select Report type from Crystal Reports gallery.

Accept the default settings and click OK. Next step is to select the appropriate connection to your database. Here we are going to select OLEDB connection for SQL Server

56

Select OLE DB (ADO) from Create New Connection .

Select Microsoft OLE DB Provider for SQL Server .

57

Next screen is the SQL Server authentication screen . Select your Sql Server name , enter userid , password and select your Database Name . Click next , Then the screen shows OLE DB Property values , leave it as it is , and click finish. Then you will get your Server name under OLEDB Connection from there select database name (Crystaldb) and click the tables , then you can see all your tables from your database. Select all table from the table list to right side list box, because we are creating report from three tables ( OrderMaster, OrderDetails, Product) .

58

The next step is to make relation between these selected tables. Here we are connecting the related fields from each table. For that we arrange the tables in visible area in the list (this is not necessary ) and select the field we are going to make relation and drag to the related field of the other table. After made the relation the screen is look like the following picture .

Next step is to select the fields from the tables . Here we are selecting only Customername , orderdate from ordermastertable , Productname from product table and quantity from order details.

59

Click the Finish button because now we are not using other functionalities of this wizard. After that you will get the Crystal Reports designer window . You can arrange the fields in the designer window according to your requirement to view the report . For rearranging you can drag the field object in the screen . For editing right click the field object and select Edit Text Object. The following picture shows the sample of designer window after rearrange the field.

60

Now the designing part is over and the next step is to call the created Crystal Reports in VB.NET through Crystal Reports Viewer control . Select the default form (Form1.vb) you created in VB.NET and drag a button and CrystalReportViewer control to your form.

Select Form's source code view and put the code on top Imports CrystalDecisions.CrystalReports.Engine Put the following source code in the button click event VB.NET Source Code
Imports CrystalDecisions.CrystalReports.Engine Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cryRpt As New ReportDocument cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt") CrystalReportViewer1.ReportSource = cryRpt CrystalReportViewer1.Refresh() End Sub End Class

61

NOTES: cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt") The Crystal Report is in your project location, there you can see CrystalReport1.rpt . So give the full path name of report here. After you run the source code you will get the report like this.

Here we connected three tables related field and get the result. If you have any comments please contact the email address in our contact page.

VB.NET Crystal Reports String parameter All Crystal Reports programming samples in this tutorials is based on the following database (crystaldb) . Please take a look at the database structure before you start this tutorial - Click here to see Database Structure . Here we are passing a String parameter from vb.net to Crystal Reports . For that , from vb.net program we pass a customer name as parameter and show all the order of that customer to the Crystal Reports.

62

In the previous tutorial we saw how to generate a Crystal Reports from multiple tables. Here is the continuation of that tutorial , the only different is that we are passing a Customer Name as a String parameter and get the report of that particular Customer only . Before starting to this tutorial just take a look at the previous tutorial ( Crystal Report from multiple tables ). In the previous section we are getting the report of all orders from all customers , that is the all order placed by all customers , here is only one customer. Hope you went through previous tutorial , if not click here ( Crystal Report from multiple tables ). Next step is to create a string parameter in Crystal report. Select the Field Explorer from CrystalReport Menu.

Then you can see Field Explorer in the Left hand side. Select Parameter Field from Field Explorer and right Click.

Fill the appropriate name for Name and Promoting text fields

63

After creating the parameter field, we have to create the selection formula for the Crystal Reports. For creating selection formula, Right click on Crystal Reports designer window, select REPORT -> SELECTION FORMULA -> RECORD.

Then you can see the record Selection Formula Editor. This for entering the selection formula. For that you have to select the fields from above fields and make the formula. First you have to select OrderMaster.OrderMaster_customername from Report Field and select the comparison operator and select the parameter field. Double click each field then it will be selected.

64

Form the following picture you can understand the selection fields.

After the creation of selection formula close that screen. Now the designing part is over and the next step is to call the created Crystal Reports in VB.NET through Crystal Reports Viewer control. Select the default form (Form1.vb) you created in VB.NET and drag a Textbox , button and CrystalReportViewer control to your form.

65

Select Form's source code view and import the following: Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Put the following source code in the button click event VB.NET Source Code
Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim cryRpt As New ReportDocument cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt") Dim crParameterFieldDefinitions As ParameterFieldDefinitions Dim crParameterFieldDefinition As ParameterFieldDefinition Dim crParameterValues As New ParameterValues Dim crParameterDiscreteValue As New ParameterDiscreteValue crParameterDiscreteValue.Value = TextBox1.Text crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields crParameterFieldDefinition = _ crParameterFieldDefinitions.Item("Customername") crParameterValues = crParameterFieldDefinition.CurrentValues crParameterValues.Clear() crParameterValues.Add(crParameterDiscreteValue) crParameterFieldDefinition.ApplyCurrentValues(crParameterValues) CrystalReportViewer1.ReportSource = cryRpt CrystalReportViewer1.Refresh() End Sub End Class

NOTES: cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt") The Crystal Report is in your project location, there you can see

66

CrystalReport1.rpt . So give the full path name of report here. Now you can run the program. Enter a Customer Name (enter any existing customer from Order master table) and click the button, then your report is look like the following picture.

Here we get the result of the Customer4's order details.

VB.NET Crystal Reports Integer parameter All Crystal Reports programming samples in this tutorials is based on the following database (crystaldb) . Please take a look at the database structure before you start this tutorial - Click here to see Database Structure . In this tutorial we are passing an Integer Parameter to Crystal Reports from VB.NET. In the previous tutorial , we saw passing a string parameter to Crystal Reports from VB.NET and get the result. This is very similar to that tutorial , so here showing only the change information part only. So please take a look at the complete part of passing a string parameter to Crystal Reports from VB.NET.

67

When we pass an Integer parameter , we have to create a new Integer parameter in the Parameter Fields of Field Explorer. Then we will get the following screen and fill the fields like in the picture .

After creating the parameter field, we have to create the selection formula for the Crystal Reports. For creating selection formula, Right click on Crystal Reports designer window, select REPORT -> SELECTION FORMULA -> RECORD. Then you can see the record Selection Formula Editor. This for entering the selection formula. For that you have to select the fields from above lists and make the formula. Here we made the formula like select the records from Product table whose value is greater than the input value. For that first we select the table field that is Product_price from Product table and then we select the comparison operator and finally we select our Parameter we created earlier. Double click each field then it will automatically selected

68

After the creation of selection formula close that screen. Now the designing part is over and the next step is to call the created Crystal Reports in VB.NET through Crystal Reports Viewer control. Select the default form (Form1.vb) you created in VB.NET and drag a Textbox , button and CrystalReportViewer control to your form. Select Form's source code view and import the following: Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared .Put the following source code in the button click event VB.NET Source Code
Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim cryRpt As New ReportDocument cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")

69
Dim crParameterFieldDefinitions As ParameterFieldDefinitions Dim crParameterFieldDefinition As ParameterFieldDefinition Dim crParameterValues As New ParameterValues Dim crParameterDiscreteValue As New ParameterDiscreteValue crParameterDiscreteValue.Value = Convert.ToInt32(TextBox1.Text) crParameterFieldDefinitions = _ cryRpt.DataDefinition.ParameterFields crParameterFieldDefinition = _ crParameterFieldDefinitions.Item("Price") crParameterValues = crParameterFieldDefinition.CurrentValues crParameterValues.Clear() crParameterValues.Add(crParameterDiscreteValue) crParameterFieldDefinition.ApplyCurrentValues(crParameterValues) CrystalReportViewer1.ReportSource = cryRpt CrystalReportViewer1.Refresh() End Sub End Class

NOTES: cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt") The Crystal Report is in your project location, there you can see CrystalReport1.rpt . So give the full path name of report here. Now you can run the program. Enter any price, then you can see the report of the Product list whose price is greater than or equal to the entered price.

70

Here we got the result of Product list whose price is grater than 50.

You might also like