Download - Visual Basic .Net
![Page 1: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/1.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Visual Basic .net
Mr. Jose Marie M. Pacia
![Page 2: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/2.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Visual Studio .net
• Microsoft’s Integrated Development Environment (IDE) for creating running and debugging programs (called applications) written in variety of programming languages
![Page 3: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/3.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Why move from VB6 to .Net?
• World of applications is changing• Has a number of unique features
![Page 4: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/4.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Overview of Visual Studio .net
• Start Page – contains list of helpful links• There are two buttons on the page:
– Open Project– New Project
• To create a new project click new project
![Page 5: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/5.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Create New Project
Open Existing Project
![Page 6: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/6.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Up close…
• Variety of languages– Visual Basic Projects– Visual C# Projects– Visual C++ Projects– Setup and Deployment Projects– Visual Studio Solutions
![Page 7: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/7.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Visual Basic Projects
• Windows application – a program that executes inside a windows OS. – Include customized software that programmers create,
example Microsoft Word, IE6 ect.
![Page 8: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/8.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Project Name
Create Applications
![Page 9: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/9.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Project Name
Path
![Page 10: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/10.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Console Programming
• Console application – applications contain only text output• Visual Basic console applications consist of pieces called module
![Page 11: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/11.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Changing the default Module
• Click on Project > Console Properties• On the startup object change the startup object to your startup
module
![Page 12: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/12.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
To run a program
• On the menu bar press Debug• Click start without debugging (F5 for shortcut key)
![Page 13: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/13.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Console Programming
• Printing a text– Consolse.Write(“String”)– Console.WriteLine(“The text goes here!”)
• Writeline position the text in the beginning of the next line
![Page 14: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/14.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Example 1
• VB.net\LaboratoryExercise\PrintingText
![Page 15: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/15.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Variables
• Stores data or information during program execution• How to declare
– Dim variable_Name as Data_Type– To insert a value:
• Dim variable_Name as Data_Type = Value
![Page 16: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/16.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Note
• Before VB can use an object variable, it must determine its type and perform the necessary conversions, if any.
![Page 17: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/17.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Data Types
• Types of Variables– Numeric – Store Numbers
![Page 18: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/18.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
![Page 19: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/19.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Arithmetic Operators
• Addition - +• Subtraction - -• Multiplication - *• Division - /• Division (Integer) \• Modulus - Mod• Exponentiation - ^
![Page 20: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/20.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Example 2
• \VB.net\LaboratoryExercise\ConsoleCalculator\ConsoleCalC
![Page 21: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/21.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Character Variables
• You can initialize a character variable by assigning either a character or a string to it. In the latter case, only the first character of the string is assigned to the variable.– Dim string_varialble as string– Dim string_varialble as string = “Value”
![Page 22: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/22.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Concatenation
• Joining of two or more strings• Example• Dim string1 as string = “a”• Dim string 2 as string = “b”
– String1 & string2• ab
![Page 23: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/23.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Example 3
• VB.net\LaboratoryExercise\StringManipulation\StringManipulation
![Page 24: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/24.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Equality Operators
• = - Equals• <> - Not Equal• > - Greater Than• < - Less Than• >= - Greater Than Equal• <= - Less than equal
![Page 25: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/25.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
If then
If studentGrade>=60 then Console.WriteLine(“Passed”)
End If
![Page 26: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/26.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Decision Making
• If/then– Allows a program to make a decision based on the truth or
falsity of some expression – It is a condition
![Page 27: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/27.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Module Condition
Sub Main() Dim lagyu As String Dim num1 As Integer Dim num2 As Integer Console.WriteLine("Enter first number: ") num1 = Console.ReadLine() Console.WriteLine("Enter second number: ") num2 = Console.ReadLine() If num1 > num2 Then Console.WriteLine("Number 1 is greater than number 2") Else Console.WriteLine("Number 2 is greater than number 3") End If
End Sub
End Module
![Page 28: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/28.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
If else/ elseif / else
If num1 > num2 Then Console.WriteLine("Number 1 is greater than number
2!") ElseIf (num2 > num1) Then Console.WriteLine("Number 1 is greater than number
2!") Else Console.WriteLine("Number are equal!") End If
![Page 29: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/29.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Example 4
• VB.net\LaboratoryExercise\IFCondition\ifCondition
![Page 30: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/30.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
While Repetition Structure
• A repetition structure allows the programmer to specify that an action should be repeated depending on the value of the condition
![Page 31: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/31.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Do while/Loop
Module WhileLoop Dim ctr As Integer Sub Main() ctr = 1 While ctr <= 10 ctr = ctr + 1 Console.WriteLine(ctr) End While End Sub
End Module
![Page 32: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/32.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Do Until/Loop Repetition
• Test a condition for falsity for repetition to continue. Statements in the body of a are executed repeatedly as long as the loop-continuation test evaluates to false
![Page 33: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/33.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Module DoWhileLoop Dim ctr As Integer Sub Main() ctr = 10 Do Until ctr < 1 Console.WriteLine(ctr) ctr = ctr - 1 Loop
End Sub
End Module
![Page 34: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/34.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Assignment Operators
+= C=+7 C = c +7
-= C-=7 C = c - 7
*= C*=7 C = c * 7
/= c/=7 C = c /7
\= c\=7 C = c \ 7
^= C^=7 C = c ^ 7
&= D &= “llo” D= D & “llo”
![Page 35: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/35.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Module Module1
Sub Main() Dim a As Integer Dim var1 As Integer Dim sum As Integer a = 1 sum = 0 While a <= 10 Console.WriteLine("Enter Number " & a & ":") var1 = Console.ReadLine() a += 1 sum = var1 + sum End While Console.WriteLine("The sum is " & sum) End Sub
End Module
![Page 36: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/36.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
For/Next Repetition
• Repetition structure handles the details of counter-controlled repetition.
![Page 37: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/37.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Module ForLoop
Sub Main() Dim counter As Integer
For counter = 1 To 10 Console.WriteLine(counter) Next End Sub
End Module
![Page 38: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/38.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Using Dialog to Display Message
• On the solution explorer, right click on the reference and add System.windows.forms
![Page 39: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/39.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Message box
• MessageBox.Show("Text", "Title Bar caption", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)
![Page 40: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/40.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Work Space
• Form – Gray rectangle which represents the Windows Applications that the programmer is creating
• The form which is the visual part of the program which the user interact
![Page 41: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/41.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Introduction to Windows Application Program
• Messagebox
MesageboxIcon.Information
MessageBox.OK
Title Bar Text
Message Text
![Page 42: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/42.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• MessageBoxIcon.Exclamation – Excalmation Point• MessageBoxIcon.Information – Icon Containing the letter I• MessageBoxIcon.Question – Icon Containing question mark• MessageBoxIcon.Error – Icon containing the red x circle
![Page 43: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/43.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• MessageBoxButtons.OK – OK button• MessageBoxButtons.OKCancel – OK and Cancel
buttons• MessageBoxButtons.YesNo – Yes and No Buttons• MessageBoxButtons.YesNoCancel – Yes, no and
cancel buttons• MessageBoxButtons.RetryCancel – Retry and
Cancel Button
![Page 44: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/44.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Select Case Multiple-Selection Structure
Select Case variableCase <decision 1>
CodeCase <decision 2>
CodeCase Else
CodeEnd Select
![Page 45: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/45.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Module SelectCaseModule Sub Main() Dim choys As Integer Console.WriteLine("Enter Choice") choys = Console.ReadLine
Select Case choys Case 1 Console.WriteLine(1) Case 2 Console.WriteLine(2) Case Else Console.WriteLine("Default") End Select End Sub
End Module
![Page 46: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/46.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Exit Keyword in a Repetition
• Exit Do, Exit While, Exit For statements alter the flow of control by causing immediate exit from a repetition structure
![Page 47: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/47.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• Exit Do – Exit a do while repetition• Exit for – Exit a for loop• Exit While – Exit a while repetition
![Page 48: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/48.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Logical Operators
• Visual Basic provides logical operators that can be used to form complex conditions by combining simple ones
![Page 49: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/49.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• AndAlso• And• OrElse• Or• Xor• Not
![Page 50: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/50.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
AndAlso
• False + False = False• False + True = False• True + False = False• True + True = True
![Page 51: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/51.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
OrElse
• False + False = False• False + True = True• True + False = True• True + True = True
![Page 52: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/52.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Not
• True = False• True = False
![Page 53: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/53.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Xor
• False + False = False• False + True = True• True + False = True• True + True = False
![Page 54: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/54.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Sub Procedures
Module SubProc Sub Main() Dim choys As Integer Console.WriteLine("Enter Choice") choys = Console.ReadLine
Select Case choys Case 1 proc1("jpacs")
End Select End Sub
Sub proc1(ByVal name As String) Console.WriteLine(name) End SubEnd Module
![Page 55: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/55.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Procedure
• Similar to sub procedure except that function procedures return a value
Function procedure-name(parameter list) as return typeDeclarations and Statement
End Function
![Page 56: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/56.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Maximum
• Get the maximum value of two number– Math.Max(val1, val2)
![Page 57: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/57.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Public Class frmMax Inherits System.Windows.Forms.Form Dim val1, val2, val3 As Double
Private Sub cmdMax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMax.Click
val1 = txtFirst.Text val2 = txtSecond.Text val3 = txtThird.Text
lblTotal.Text = Math.Max(Math.Max(val1, val2), val3)
End SubEnd Class
![Page 58: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/58.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
More Math Functions
• Abs(x) – returns absolute value of x• Ceiling(x) – rounds x to the smallest integer• Cos(x) returns the trigonometric cosine
![Page 59: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/59.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• Exp(x) – returns the exponential ex
• Floor(x) – rounds x to the largest integer not greater than x
• Log(x) – returns the natural logarithm of x (base e)
• Max(x,y) – returns the larger value of x and y
• Min(x,y) – returns the smallest value of x and y
![Page 60: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/60.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• Pow(x,y) – Calculates x reaised to power y(xy)• Sin(x) – returns the trigonometric sine of x(x in radians)• Sqrt(x) – returns the square root of x• Tan(x) – returns the trigonometric tangent of x (x in radians)
![Page 61: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/61.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• Random– Dim randomObject as Random = New Random()– Dim randomNumber as Integer = randomObject.Next()
![Page 62: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/62.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim randomObject As Random = New Random Dim randomNumber As Integer
randomNumber = randomObject.Next(1, 10) lblRandom.Text = randomNumber End Sub
![Page 63: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/63.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Modules
• Programmers use modules to group related procedures so that they can be reused in other projects
![Page 64: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/64.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
How to add modules
• Goto File > Add new item• On the template select module
![Page 65: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/65.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Module Module1 Function reuse(ByVal lbl As Label) lbl.Text = "jpacs" End FunctionEnd Module
![Page 66: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/66.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Convert
• Use to convert variables or value on a desired data type• Example
– Convert.ToString (val2)– Convert.ToChar(1)
![Page 67: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/67.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Array
• Can store information and has indexes or memory address• Array have the same name and same type• The first element of an array is 0th Element• The position on the array is called index
![Page 68: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/68.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Public Class Form1Inherits System.Windows.Forms.FormDim numarray(10) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
numarray(0) = 1 Label1.Text = numarray(0)
End SubEnd Class
![Page 69: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/69.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
GUI
• Label – An area in which icons or un editable text is displayed
• Textbox – An area in which the user inputs data from the keyboard. This can also display information
• Button – An area that triggers an event when clicked
• CheckBox – A component that is either selected on unselected
![Page 70: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/70.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• ComboBox – A drop-down list of items from which the user can make a selection either by clicking an item in the list or by typing into a box
• ListBox – An area in which a list of items is displayed. The user can make a selection from the list by clicking on any item. Multiple elements can be selected.
![Page 71: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/71.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• Panel – A container in which components can be placed• Scrollbar – A component that allows the user to access a range of
elements that normally cannot fit in the control’s container
![Page 72: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/72.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Toolbox
• Contains all the windows forms and components• To add a component on a form, select the component on the
toolbox and drag it on the form
![Page 73: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/73.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
![Page 74: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/74.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Unload a form
• Application.exit
![Page 75: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/75.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Form Properties and Events
• AcceptButton – Button that is clicked when Enter is pressed
• AutoScroll – Boolean value that allows or disallows scrollbars to appear when needed
• CancelButton – Button that is clicked when the Escape key is pressed
• FormBorderStyle – Border style for the form (e.g., none, single, 3d)
![Page 76: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/76.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• Font – font of text displayed on the form, and the default font of controls added to the form
• Text – Text in the form’s title bar
![Page 77: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/77.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Common Methods
• Close – Closes a form and releases all resources. A closed form cannot be open.
• Hide – Hides form• Show – Display hidden forms
![Page 78: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/78.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Code
• formName.ActiveForm.Close()
![Page 79: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/79.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Textbox
• Passing a value:– txtEmpNoOut.Text = txtEmpNo.Text– txtEmpNameOut.Text = txtLastName.Text & " " &
txtFirstName.Text
![Page 80: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/80.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Mathematical Operator on Text Box
• txtPhilhealth.Text = Val(txtSalaryMain.Text) * 0.05
• txtTax.Text = Val(txtSalaryMain.Text) * 0.04• txtSSS.Text = Val(txtSalaryMain.Text) * 0.03
![Page 81: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/81.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Combo Box
• Adding Items on runtime– ComboBox1.Items.Add("ABC")
• Clearing Items on runtime– ComboBox1.Items.Clear()
![Page 82: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/82.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Properties of a combo box
• DropDownStyle – Dropdownlist, Dropdown, Simple• Items - use to insert all the choices on your combo box
![Page 83: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/83.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Adding Items on Combo on runtime
• cmbChoice.Items.Add("ABC")
Clearing the items on the combo box• cmbChoice.Items.Clear()
![Page 84: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/84.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Getting the items on a combo
• cmbChoice.Items.Item (index number)
![Page 85: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/85.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Radio Button
• Allows a user to choose a options• Properties
– Check = combo box is selected (True = Selected, False = Un Selected)
– Text = Text displayed on option Button
![Page 86: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/86.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Example GUI 1
• Calculator• Payroll System
![Page 87: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/87.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Picture Boxes
• A picture box displays an image. The image, set by an object of class Image, can be a bitmap, a GIF, JPEG, icon or metafile format.
![Page 88: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/88.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Picture Box Properties
• Image – sets the image to display in the Picture Box• SizeMode – Enumeration that controls image sizing and
positioning. StretchImage, AutoSize and Center Image)
![Page 89: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/89.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• Normal places the image in top-left corner of picture box
• CenterImage puts the image in middle (both truncate image if it is too large)
• StretchImage resizes image to fit in PictureBox.
• AutoSize resizes PictureBox to hold image
![Page 90: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/90.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Loading Picture on Runtime
• picOne.Image = Image.FromFile("D:\VB.net\LaboratoryExercise\Picture Swapper\Pictures\Pic2.jpg")
![Page 91: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/91.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Selecting the Current directory or Path
• .fromfile (directory.GetCurrentDirectory)
![Page 92: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/92.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Example GUI 2
• Picture Swapper
![Page 93: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/93.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
List Box
• Allows the user to view and select from multiple items in a list
![Page 94: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/94.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
List Box Properties
• Items – Collection of an item in a listbox• SelectedIndex – Returns the index of the selected item. If selected
multiple items, the property returns arbitrary returns one of the selected indeces. If no items are selected, the property returns to -1
![Page 95: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/95.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• SelectedIndeces – Returns a collection containing the indeces for all selected items
• SelectedItem – Returns a reference to the selected item (If multiple items are selected, it returns the items with the lowest number of index)
• SelectedItems – Returns a collection of selected items
![Page 96: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/96.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• SelectionMode – Determines the number of items that can be selected– Values(None, One, Multiple)
• Sorted – Indicates whether items are sorted alphabetically
![Page 97: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/97.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Adding of Item
• listOrder.Items.Add(“Item to Add”)
![Page 98: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/98.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Removing of items
• listOrder.Items.Clear()
• Counting of items on a list– listOrder.Items.Count
![Page 99: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/99.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
CheckedListBoxes
• Control derives from Listbox but contains checkbox before each item
![Page 100: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/100.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Properties
• CheckedItems – Contains the collection of items that are checked
• CheckedIndeces – Returns all indexes for checked items
• SelectionMode – Determines how many items can be checked. One(Multiple) and None(Does not allow)
![Page 101: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/101.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
To get checked item
tmp = listOrder.GetItemChecked(ctr - 1) If tmp = True Then listOrder.Items.RemoveAt(ctr - 1) End If
![Page 102: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/102.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Remove item
• listOrder.Items.RemoveAt(ctr - 1)
![Page 103: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/103.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Example GUI 3
• Font Browser• POS
![Page 104: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/104.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Creating Shapes
• Import System.Drawing on your program
![Page 105: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/105.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Imports System.DrawingPublic Class frmShapes Dim mygraphics As Graphics = MyBase.CreateGraphics Dim mypen As New Pen(Color.DarkRed)
Private Sub cmbShapes_SelectedIndexChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbShapes.SelectedIndexChanged
If cmbShapes.Text = "Ellipse" Then mygraphics.Clear(Color.White) mygraphics.DrawEllipse(mypen, 100, 100, 100, 10) End If End SubEnd Class
![Page 106: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/106.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Ellipse
• mygraphics.DrawEllipse(color of pen, x, y, height, width)
![Page 107: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/107.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Tree View
• Displays nodes hierarchically in a tree.• Nodes are objects that contain values and can refer to other nodes• Parent node can contain child nodes• A child node can be a parent node to other nodes
![Page 108: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/108.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• First node on the tree is the root node• Two child nodes are called siblings node
![Page 109: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/109.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Properties of Tree View
• Checkboxes – Indicates whether a checkboxes appear next to node
• ImageList – Specifies ImageList containing the node icon• Nodes – List the collection of TreeNode, in the control
![Page 110: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/110.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Methods on Treeview.Node
• Add (Adds a tree node object)• Clear (Clears the entire collection of tree node)• Remove (Delete a specific node)
![Page 111: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/111.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Code
Public Class frmTree Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnAdd.Click Dim StudName As String StudName = txtLName.Text + ", " + txtFName.Text + " " +
txtMI.Text If cmbCourse.Text = "ACT" Then treeStudents.Nodes(0).Nodes(0).Nodes.Add(StudName) End If End SubEnd Class
![Page 112: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/112.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Font Properties
• New Font(Font,Size,Font Style)
![Page 113: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/113.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Code
• Label1.Font = New Font("Comic Sans Serif", 14, FontStyle.Italic, GraphicsUnit.Pixel)
![Page 114: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/114.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Checked box
• Small white square that either is blank or contains a checkmark. When a checkbox is selected, a blank checkmark appears in the box.
![Page 115: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/115.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Properties of a checkbox
• Checked – Indicates whether the checkbox is checked or marked• CheckState – Indicates whether the checkbox is checked or
unchecked• Text – Specifies the text displayed to the right of the Checkbox
called label
![Page 116: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/116.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Code
If chkBold.CheckState = CheckState.Checked Then txtOutput.Font = New Font(cmbFonts.Text, 12,
FontStyle.Bold)Else txtOutput.Font = New Font(cmbFonts.Text, 12,
FontStyle.Regular)End If
![Page 117: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/117.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Common Dialog Box
• A rather tedious, but quite common, task in nearly every application is to prompt the user for filenames, font names and sizes, or colors to be used by the application
![Page 118: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/118.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
OpenFileDialog
• OpenFileDialog Lets users select a file to open. It also allows the selection of multiple files, for applications that must process many files at once (change the format of the selected files, for example).
![Page 119: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/119.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Files and Streams
• Create Directory contains information about a directory– AppendText – Returns a StreamWriter that appends to an
existing file or creates a file if one does not exist
![Page 120: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/120.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Database Programming using ADO.net
• Ado.net object model provides an API for accessing database systems programmatically.
• Was created for the .NET framework and is the next generation of ActiveX Data Objects (ADO), which was designed to interact with Microsoft’s Components Object Model (COM) framework
![Page 121: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/121.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
ADO.net
• simplify the code you write• allow you to bind graphical controls to DataSets
![Page 122: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/122.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Primary Library of ADO.net
• System.data• System.data.OleDb• System.Data.SqlClient• System.Data.Dataset
![Page 123: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/123.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Data Set
• uses the DataSet to store disconnected data
![Page 124: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/124.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Adding OledbAdapter
• Click on Tools > Choose Toolbox Items • Click on .Net Framework Componets• Select OledbAdapter and Click OK
![Page 125: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/125.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
oleDbConnection
• The oleDbConnection object uses OLE DB to connect to a data source. ADO.NET
• also includes a new type of connection: SQLConnection
![Page 126: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/126.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• Dim connString As String = _• “Provider= SQLOLEDB.1;Data Source=localhost;” & _• “uid=sa;pwd=;Initial Catalog=northwind;”• Dim myConn As New oleDbConnection()• myConn.ConnectionString = connString• myConn.Open()
![Page 127: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/127.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Example Database
• Dbase Application
![Page 128: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/128.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• The End!!!!
![Page 129: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/129.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Data Adapter Wizard
• New Connection– Data Source – Database Connection– Database File Name – File Name of the database
• Change the Datasource– Microsoft Access Database File– Click Ok– Find the Access File– Test the connection
![Page 130: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/130.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Continuation
• Click OK• Choose Use SQL Statements• Insert your SQL • Click Finish
![Page 131: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/131.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
More…
• You will be returned at the design tab• There are two components that has been added:
– oleDbDataAdapter1
– oleDbConnection1
![Page 132: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/132.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
• The oleDbConnection1 control describes the database connection;• The oleDbDataAdapter1 control describes your actual query• In VB.NET, the object you use to store data is called a DataSet.
![Page 133: Visual Basic .Net](https://reader030.vdocuments.site/reader030/viewer/2022020920/54687023b4af9f9b538b4cc3/html5/thumbnails/133.jpg)
VB .net © COPYRIGHT BY BADBOY INC PRESENTED BY:SIR “JPACS”
Data Set
• Click once on the form. • Notice that on the menu bar, a new menu item has appeared:
DataSet• Drag the DataSet on the form• Select untype data sets