SlideShare a Scribd company logo
3
Most read
11
Most read
13
Most read
VB.Net Programs
Prof. K. Adisesha 1
C# & Dot Net Lab Programs
Part- B
1. VB.net Program to count the number of Vowels in a string
Public Class Form1
Private Sub resultBtn_Click(sender As Object, e As EventArgs) Handles resultBtn.Click
Dim str1, str2 As String
Dim vcount, i, str1len As Integer
vcount = 0
str1 = stringText.Text
str1len = Len(str1)
str1 = LCase(str1)
For i = 1 To str1len
str2 = Mid(str1, i, 1)
If str2 = "a" Or str2 = "e" Or str2 = "i" Or str2 = "o" Or str2 = "u" Then
vcount = vcount + 1
End If
Next i
resultText.Text = vcount
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Close()
End Sub
End Class
VB.Net Programs
Prof. K. Adisesha 2
Output:
VB.Net Programs
Prof. K. Adisesha 3
2. VB.net Program to Check a given is Even or Odd Number or Overflow
if number>10000
Code:
Public Class Form1
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles resultBtn.Click
If valueText.Text Mod 2 = 0 Then
resultText.Text = "EVEN"
Else
resultText.Text = "ODD"
End If
If valueText.Text > 10000 Then
resultText.Text = "Overflow!!!"
End If
VB.Net Programs
Prof. K. Adisesha 4
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
valueText.Text = ""
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Close()
End Sub
End Class
Output:
VB.Net Programs
Prof. K. Adisesha 5
3. VB.net Program to calculate the compound interest
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles resultBtn.Click
Dim P As Integer
Dim R As Integer
Dim n As Integer
P = principleText.Text
R = rateText.Text
n = timeText.Text
compText.Text = P * (1 + (R / 100)) ^ n - 1
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles btnExit.Click
Close()
End Sub
VB.Net Programs
Prof. K. Adisesha 6
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
principleText.Text = ""
rateText.Text = ""
timeText.Text = ""
End Sub
End Class
Output:
VB.Net Programs
Prof. K. Adisesha 7
4. VB.Net Program to Display the sum of Positive and negative numbers
using input box
Code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub resultBtn_Click(sender As Object, e As EventArgs) Handles resultBtn.Click
Dim arr(), a, b, c, i As Integer
a = CInt(limitText.Text)
ReDim arr(a)
For i = 0 To a - 1 Step 1
arr(i) = CInt(InputBox("Enter elements:"))
If arr(i) > 0 Then
b = b + arr(i)
ElseIf arr(i) < 0 Then
c = c + arr(i)
End If
Next
positiveText.Text = b
negativeText.Text = c
End Sub
VB.Net Programs
Prof. K. Adisesha 8
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Close()
End Sub
End Class
Output:
VB.Net Programs
Prof. K. Adisesha 9
5. VB.Net Program to concatenate two strings and display result using
Message Box.
Code:
Public Class Form1
Private Sub resultBtn_Click(sender As Object, e As EventArgs) Handles resultBtn.Click
Dim x As String
Dim y As String
x = firstText.Text
y = lastText.Text
MsgBox(firstText.Text + " " + lastText.Text, vbOKCancel)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnclear.Click
firstText.Clear()
lastText.Clear()
End Sub
End Class
VB.Net Programs
Prof. K. Adisesha 10
Output:
VB.Net Programs
Prof. K. Adisesha 11
6. Write a program to change the style of font based on the user’s
choice by using CHECK BOX BUTTON
Public Class Form1
Private Sub setStyle()
Dim style = FontStyle.Regular
If boldCheck.Checked Then
style = style Or FontStyle.Bold
End If
If italicsCheck.Checked Then
style = style Or FontStyle.Italic
End If
If underLineCheck.Checked Then
style = style Or FontStyle.Underline
End If
inputText.Font = New Font(inputText.Font, style)
End Sub
Private Sub boldCheck_CheckedChanged(sender As Object, e As EventArgs) Handles
boldCheck.CheckedChanged
setStyle()
End Sub
Private Sub italicsCheck_CheckedChanged(sender As Object, e As EventArgs) Handles
italicsCheck.CheckedChanged
VB.Net Programs
Prof. K. Adisesha 12
setStyle()
End Sub
Private Sub underLineCheck_CheckedChanged(sender As Object, e As EventArgs)
Handles underLineCheck.CheckedChanged
setStyle()
End Sub
End Class
Output:
VB.Net Programs
Prof. K. Adisesha 13
7. Write a program to generate a Student Enrolment Details form using
Combo box.
Code:
Public Class Form1
Private Sub dispBtn_Click(sender As Object, e As EventArgs) Handles dispBtn.Click
MsgBox("These are the following details entered: " + vbCrLf + " Name:" + nameText.Text + vbCrLf
+ "Course:" + courseCombo.Text + vbCrLf + "Semester:" + semCombo.Text + vbCrLf + "Marks:" +
marksText.Text, vbOKOnly)
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Close()
End Sub
End Class
VB.Net Programs
Prof. K. Adisesha 14
Output:
VB.Net Programs
Prof. K. Adisesha 15
8. Write a program to generate a Dynamic User login form using
Database.
Code:
Note: Follow the following steps:
➢ Provide MySQL password
➢ Create a Database and provide DB name in Inputbox.
➢ Login table will be created with the given Name in Inputbox
Imports System.Data.Odbc
Public Class Form1
Dim uname As String = InputBox("Enter the UserName of MySql:")
Dim pass As String = InputBox("Enter the password of MySql:")
Dim dB As String = InputBox("Enter the DataBase name")
Dim connectionString As String = "DRIVER={MySQL ODBC 8.0 Unicode
Driver};SERVER=localhost;DATABASE=" + dB + ";UID=" + uname + ";PASSWORD=" + pass
+ ";OPTION=3;"
Public conn As New OdbcConnection(connectionString)
Dim sqlTableCreate As String = "CREATE TABLE users(username varchar(25),password
varchar(25));"
Dim cmdCreate As New OdbcCommand(sqlTableCreate, conn)
VB.Net Programs
Prof. K. Adisesha 16
Sub Open()
cmdCreate.ExecuteNonQuery()
End Sub
Private Sub createBtn_Click(sender As Object, e As EventArgs) Handles createBtn.Click
Try
If unameText.Text = "" Or passText.Text = "" Then
MsgBox("Please Provide the values", vbExclamation)
Else
conn.Open()
Dim rows As Integer
Dim sqlInsert As String = "INSERT INTO users(username,password) values(" + "'"
+ unameText.Text + "','" + passText.Text + "')"
Dim cmd As New OdbcCommand(sqlInsert, conn)
rows = cmd.ExecuteNonQuery()
If rows > 0 Then
MsgBox("User Created!", vbOK)
End If
End If
conn.Close()
Catch ex As Exception
MsgBox("Database Error", vbExclamation)
End Try
End Sub
Private Sub loginBtn_Click(sender As Object, e As EventArgs) Handles loginBtn.Click
Try
conn.Open()
Dim sqlSelect As String = "SELECT username,password FROM users WHERE
username=" + "'" + unameText.Text + "' AND " + "password='" + passText.Text + "'"
Dim cmd As New OdbcCommand(sqlSelect, conn)
Dim sqlResult As OdbcDataReader
sqlResult = cmd.ExecuteReader()
If sqlResult.HasRows Then
MsgBox("User Successfully Logged In", vbOK)
conn.Close()
Else
MsgBox("No Match found", vbExclamation)
conn.Close()
End If
Catch ex As Exception
MsgBox("DataBase Error", vbCritical)
End Try
VB.Net Programs
Prof. K. Adisesha 17
End Sub
Private Sub clearBtn_Click(sender As Object, e As EventArgs) Handles clearBtn.Click
unameText.Clear()
passText.Clear()
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles
showPassCheck.CheckedChanged
If showPassCheck.CheckState = CheckState.Unchecked Then
passText.PasswordChar = "*"
ElseIf showPassCheck.CheckState = CheckState.Checked Then
passText.PasswordChar = ""
End If
End Sub
End Class
Output:
VB.Net Programs
Prof. K. Adisesha 18
9. Program to Implement MDI (Multiple Document Interface) Parent Form
Follow the following Steps
➢ To make a form as MDI Form set its IsMdiContainer property as true.
➢ To define a parent form to a child form set MdiParent property.
➢ To arrange the child forms, use LayoutMdi() method.
➢ To get reference of the current child form use ActiveMdiChild property.
➢ To get reference of a control from the child form use its Controls collection.
Output:
VB.Net Programs
Prof. K. Adisesha 19

More Related Content

What's hot (20)

PDF
Php array
Nikul Shah
 
PDF
OOP Assignment 03.pdf
ARSLANMEHMOOD47
 
PDF
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
PPT
Javascript arrays
Hassan Dar
 
PDF
Network programming Using Python
Karim Sonbol
 
PPT
Javascript
mussawir20
 
PPTX
Control structures in java
VINOTH R
 
PPTX
Asp.NET Validation controls
Guddu gupta
 
PPTX
Java swing
Apurbo Datta
 
PPTX
Event In JavaScript
ShahDhruv21
 
PPTX
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
PDF
Asp.net state management
priya Nithya
 
PPTX
Performance analysis(Time & Space Complexity)
swapnac12
 
DOCX
Web Technology Lab File
Kandarp Tiwari
 
PPTX
Threads in JAVA
Haldia Institute of Technology
 
PDF
JavaScript - Chapter 11 - Events
WebStackAcademy
 
PPTX
File handling in Python
Megha V
 
PPSX
Php and MySQL
Tiji Thomas
 
PPT
Class and object in C++
rprajat007
 
Php array
Nikul Shah
 
OOP Assignment 03.pdf
ARSLANMEHMOOD47
 
JavaScript - Chapter 12 - Document Object Model
WebStackAcademy
 
Javascript arrays
Hassan Dar
 
Network programming Using Python
Karim Sonbol
 
Javascript
mussawir20
 
Control structures in java
VINOTH R
 
Asp.NET Validation controls
Guddu gupta
 
Java swing
Apurbo Datta
 
Event In JavaScript
ShahDhruv21
 
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
Asp.net state management
priya Nithya
 
Performance analysis(Time & Space Complexity)
swapnac12
 
Web Technology Lab File
Kandarp Tiwari
 
JavaScript - Chapter 11 - Events
WebStackAcademy
 
File handling in Python
Megha V
 
Php and MySQL
Tiji Thomas
 
Class and object in C++
rprajat007
 

Similar to VB net lab.pdf (20)

DOCX
Docimp
KaivanShah30
 
PDF
VISUAL BASIC PRATICAL FILE MSC COMPUTER SCIENCE.pdf
BALWANSAINI1
 
PDF
Inventory management
Rajeev Sharan
 
PDF
LoginFormCode
rk5media
 
PDF
Membuat aplikasi penjualan buku sederhana
Yusman Kurniadi
 
DOCX
Ensayo Convergencia Informatica
miguel camelo
 
DOCX
.net progrmming part4
Dr.M.Karthika parthasarathy
 
DOCX
Puerto serialarduino
zadkiel_123
 
DOCX
Hems
090360116006
 
PPT
4.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.15
Rajes Wari
 
PDF
UtilityCostCalcCode
Michelle John
 
PDF
I can't get my code below to work with Option Strict On due to this part of t...
hwbloom115
 
PDF
Lecture 09 high level language
鍾誠 陳鍾誠
 
PDF
SISTEMA DE FACTURACION (Ejemplo desarrollado)
Darwin Durand
 
DOCX
Ete programs
Mayur Wankhede
 
PPTX
Updated Visual Basic 6 for beginners.pptx
SarveshDeodhar
 
DOCX
1. Determine the output displayed when the button is clicked. Priv.docx
corbing9ttj
 
DOCX
1. Determine the output displayed when the button is clicked.Priva.docx
corbing9ttj
 
PDF
Kajal Gaharwal , BCA Third Year
Dezyneecole
 
PPT
.Net Enterprise Services and their Implementations
Kashif Aleem
 
Docimp
KaivanShah30
 
VISUAL BASIC PRATICAL FILE MSC COMPUTER SCIENCE.pdf
BALWANSAINI1
 
Inventory management
Rajeev Sharan
 
LoginFormCode
rk5media
 
Membuat aplikasi penjualan buku sederhana
Yusman Kurniadi
 
Ensayo Convergencia Informatica
miguel camelo
 
.net progrmming part4
Dr.M.Karthika parthasarathy
 
Puerto serialarduino
zadkiel_123
 
4.7.14&amp;17.7.14&amp;23.6.15&amp;10.9.15
Rajes Wari
 
UtilityCostCalcCode
Michelle John
 
I can't get my code below to work with Option Strict On due to this part of t...
hwbloom115
 
Lecture 09 high level language
鍾誠 陳鍾誠
 
SISTEMA DE FACTURACION (Ejemplo desarrollado)
Darwin Durand
 
Ete programs
Mayur Wankhede
 
Updated Visual Basic 6 for beginners.pptx
SarveshDeodhar
 
1. Determine the output displayed when the button is clicked. Priv.docx
corbing9ttj
 
1. Determine the output displayed when the button is clicked.Priva.docx
corbing9ttj
 
Kajal Gaharwal , BCA Third Year
Dezyneecole
 
.Net Enterprise Services and their Implementations
Kashif Aleem
 
Ad

More from Prof. Dr. K. Adisesha (20)

PDF
MACHINE LEARNING Notes by Dr. K. Adisesha
Prof. Dr. K. Adisesha
 
PDF
Probabilistic and Stochastic Models Unit-3-Adi.pdf
Prof. Dr. K. Adisesha
 
PDF
Genetic Algorithm in Machine Learning PPT by-Adi
Prof. Dr. K. Adisesha
 
PDF
Unsupervised Machine Learning PPT Adi.pdf
Prof. Dr. K. Adisesha
 
PDF
Supervised Machine Learning PPT by K. Adisesha
Prof. Dr. K. Adisesha
 
PDF
Introduction to Machine Learning PPT by K. Adisesha
Prof. Dr. K. Adisesha
 
PPSX
Design and Analysis of Algorithms ppt by K. Adi
Prof. Dr. K. Adisesha
 
PPSX
Data Structure using C by Dr. K Adisesha .ppsx
Prof. Dr. K. Adisesha
 
PDF
Operating System-4 "File Management" by Adi.pdf
Prof. Dr. K. Adisesha
 
PDF
Operating System-3 "Memory Management" by Adi.pdf
Prof. Dr. K. Adisesha
 
PDF
Operating System Concepts Part-1 by_Adi.pdf
Prof. Dr. K. Adisesha
 
PDF
Operating System-2_Process Managementby_Adi.pdf
Prof. Dr. K. Adisesha
 
PDF
Software Engineering notes by K. Adisesha.pdf
Prof. Dr. K. Adisesha
 
PDF
Software Engineering-Unit 1 by Adisesha.pdf
Prof. Dr. K. Adisesha
 
PDF
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Prof. Dr. K. Adisesha
 
PDF
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
Prof. Dr. K. Adisesha
 
PDF
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
Prof. Dr. K. Adisesha
 
PDF
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
Prof. Dr. K. Adisesha
 
PDF
Computer Networks Notes by -Dr. K. Adisesha
Prof. Dr. K. Adisesha
 
PDF
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha
Prof. Dr. K. Adisesha
 
MACHINE LEARNING Notes by Dr. K. Adisesha
Prof. Dr. K. Adisesha
 
Probabilistic and Stochastic Models Unit-3-Adi.pdf
Prof. Dr. K. Adisesha
 
Genetic Algorithm in Machine Learning PPT by-Adi
Prof. Dr. K. Adisesha
 
Unsupervised Machine Learning PPT Adi.pdf
Prof. Dr. K. Adisesha
 
Supervised Machine Learning PPT by K. Adisesha
Prof. Dr. K. Adisesha
 
Introduction to Machine Learning PPT by K. Adisesha
Prof. Dr. K. Adisesha
 
Design and Analysis of Algorithms ppt by K. Adi
Prof. Dr. K. Adisesha
 
Data Structure using C by Dr. K Adisesha .ppsx
Prof. Dr. K. Adisesha
 
Operating System-4 "File Management" by Adi.pdf
Prof. Dr. K. Adisesha
 
Operating System-3 "Memory Management" by Adi.pdf
Prof. Dr. K. Adisesha
 
Operating System Concepts Part-1 by_Adi.pdf
Prof. Dr. K. Adisesha
 
Operating System-2_Process Managementby_Adi.pdf
Prof. Dr. K. Adisesha
 
Software Engineering notes by K. Adisesha.pdf
Prof. Dr. K. Adisesha
 
Software Engineering-Unit 1 by Adisesha.pdf
Prof. Dr. K. Adisesha
 
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Prof. Dr. K. Adisesha
 
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
Prof. Dr. K. Adisesha
 
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
Prof. Dr. K. Adisesha
 
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
Prof. Dr. K. Adisesha
 
Computer Networks Notes by -Dr. K. Adisesha
Prof. Dr. K. Adisesha
 
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha
Prof. Dr. K. Adisesha
 
Ad

Recently uploaded (20)

PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 

VB net lab.pdf

  • 1. VB.Net Programs Prof. K. Adisesha 1 C# & Dot Net Lab Programs Part- B 1. VB.net Program to count the number of Vowels in a string Public Class Form1 Private Sub resultBtn_Click(sender As Object, e As EventArgs) Handles resultBtn.Click Dim str1, str2 As String Dim vcount, i, str1len As Integer vcount = 0 str1 = stringText.Text str1len = Len(str1) str1 = LCase(str1) For i = 1 To str1len str2 = Mid(str1, i, 1) If str2 = "a" Or str2 = "e" Or str2 = "i" Or str2 = "o" Or str2 = "u" Then vcount = vcount + 1 End If Next i resultText.Text = vcount End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Close() End Sub End Class
  • 2. VB.Net Programs Prof. K. Adisesha 2 Output:
  • 3. VB.Net Programs Prof. K. Adisesha 3 2. VB.net Program to Check a given is Even or Odd Number or Overflow if number>10000 Code: Public Class Form1 Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles resultBtn.Click If valueText.Text Mod 2 = 0 Then resultText.Text = "EVEN" Else resultText.Text = "ODD" End If If valueText.Text > 10000 Then resultText.Text = "Overflow!!!" End If
  • 4. VB.Net Programs Prof. K. Adisesha 4 End Sub Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click valueText.Text = "" End Sub Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Close() End Sub End Class Output:
  • 5. VB.Net Programs Prof. K. Adisesha 5 3. VB.net Program to calculate the compound interest Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles resultBtn.Click Dim P As Integer Dim R As Integer Dim n As Integer P = principleText.Text R = rateText.Text n = timeText.Text compText.Text = P * (1 + (R / 100)) ^ n - 1 End Sub Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles btnExit.Click Close() End Sub
  • 6. VB.Net Programs Prof. K. Adisesha 6 Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click principleText.Text = "" rateText.Text = "" timeText.Text = "" End Sub End Class Output:
  • 7. VB.Net Programs Prof. K. Adisesha 7 4. VB.Net Program to Display the sum of Positive and negative numbers using input box Code: Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub resultBtn_Click(sender As Object, e As EventArgs) Handles resultBtn.Click Dim arr(), a, b, c, i As Integer a = CInt(limitText.Text) ReDim arr(a) For i = 0 To a - 1 Step 1 arr(i) = CInt(InputBox("Enter elements:")) If arr(i) > 0 Then b = b + arr(i) ElseIf arr(i) < 0 Then c = c + arr(i) End If Next positiveText.Text = b negativeText.Text = c End Sub
  • 8. VB.Net Programs Prof. K. Adisesha 8 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Close() End Sub End Class Output:
  • 9. VB.Net Programs Prof. K. Adisesha 9 5. VB.Net Program to concatenate two strings and display result using Message Box. Code: Public Class Form1 Private Sub resultBtn_Click(sender As Object, e As EventArgs) Handles resultBtn.Click Dim x As String Dim y As String x = firstText.Text y = lastText.Text MsgBox(firstText.Text + " " + lastText.Text, vbOKCancel) End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnExit.Click Close() End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnclear.Click firstText.Clear() lastText.Clear() End Sub End Class
  • 10. VB.Net Programs Prof. K. Adisesha 10 Output:
  • 11. VB.Net Programs Prof. K. Adisesha 11 6. Write a program to change the style of font based on the user’s choice by using CHECK BOX BUTTON Public Class Form1 Private Sub setStyle() Dim style = FontStyle.Regular If boldCheck.Checked Then style = style Or FontStyle.Bold End If If italicsCheck.Checked Then style = style Or FontStyle.Italic End If If underLineCheck.Checked Then style = style Or FontStyle.Underline End If inputText.Font = New Font(inputText.Font, style) End Sub Private Sub boldCheck_CheckedChanged(sender As Object, e As EventArgs) Handles boldCheck.CheckedChanged setStyle() End Sub Private Sub italicsCheck_CheckedChanged(sender As Object, e As EventArgs) Handles italicsCheck.CheckedChanged
  • 12. VB.Net Programs Prof. K. Adisesha 12 setStyle() End Sub Private Sub underLineCheck_CheckedChanged(sender As Object, e As EventArgs) Handles underLineCheck.CheckedChanged setStyle() End Sub End Class Output:
  • 13. VB.Net Programs Prof. K. Adisesha 13 7. Write a program to generate a Student Enrolment Details form using Combo box. Code: Public Class Form1 Private Sub dispBtn_Click(sender As Object, e As EventArgs) Handles dispBtn.Click MsgBox("These are the following details entered: " + vbCrLf + " Name:" + nameText.Text + vbCrLf + "Course:" + courseCombo.Text + vbCrLf + "Semester:" + semCombo.Text + vbCrLf + "Marks:" + marksText.Text, vbOKOnly) End Sub Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click Close() End Sub End Class
  • 14. VB.Net Programs Prof. K. Adisesha 14 Output:
  • 15. VB.Net Programs Prof. K. Adisesha 15 8. Write a program to generate a Dynamic User login form using Database. Code: Note: Follow the following steps: ➢ Provide MySQL password ➢ Create a Database and provide DB name in Inputbox. ➢ Login table will be created with the given Name in Inputbox Imports System.Data.Odbc Public Class Form1 Dim uname As String = InputBox("Enter the UserName of MySql:") Dim pass As String = InputBox("Enter the password of MySql:") Dim dB As String = InputBox("Enter the DataBase name") Dim connectionString As String = "DRIVER={MySQL ODBC 8.0 Unicode Driver};SERVER=localhost;DATABASE=" + dB + ";UID=" + uname + ";PASSWORD=" + pass + ";OPTION=3;" Public conn As New OdbcConnection(connectionString) Dim sqlTableCreate As String = "CREATE TABLE users(username varchar(25),password varchar(25));" Dim cmdCreate As New OdbcCommand(sqlTableCreate, conn)
  • 16. VB.Net Programs Prof. K. Adisesha 16 Sub Open() cmdCreate.ExecuteNonQuery() End Sub Private Sub createBtn_Click(sender As Object, e As EventArgs) Handles createBtn.Click Try If unameText.Text = "" Or passText.Text = "" Then MsgBox("Please Provide the values", vbExclamation) Else conn.Open() Dim rows As Integer Dim sqlInsert As String = "INSERT INTO users(username,password) values(" + "'" + unameText.Text + "','" + passText.Text + "')" Dim cmd As New OdbcCommand(sqlInsert, conn) rows = cmd.ExecuteNonQuery() If rows > 0 Then MsgBox("User Created!", vbOK) End If End If conn.Close() Catch ex As Exception MsgBox("Database Error", vbExclamation) End Try End Sub Private Sub loginBtn_Click(sender As Object, e As EventArgs) Handles loginBtn.Click Try conn.Open() Dim sqlSelect As String = "SELECT username,password FROM users WHERE username=" + "'" + unameText.Text + "' AND " + "password='" + passText.Text + "'" Dim cmd As New OdbcCommand(sqlSelect, conn) Dim sqlResult As OdbcDataReader sqlResult = cmd.ExecuteReader() If sqlResult.HasRows Then MsgBox("User Successfully Logged In", vbOK) conn.Close() Else MsgBox("No Match found", vbExclamation) conn.Close() End If Catch ex As Exception MsgBox("DataBase Error", vbCritical) End Try
  • 17. VB.Net Programs Prof. K. Adisesha 17 End Sub Private Sub clearBtn_Click(sender As Object, e As EventArgs) Handles clearBtn.Click unameText.Clear() passText.Clear() End Sub Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles showPassCheck.CheckedChanged If showPassCheck.CheckState = CheckState.Unchecked Then passText.PasswordChar = "*" ElseIf showPassCheck.CheckState = CheckState.Checked Then passText.PasswordChar = "" End If End Sub End Class Output:
  • 18. VB.Net Programs Prof. K. Adisesha 18 9. Program to Implement MDI (Multiple Document Interface) Parent Form Follow the following Steps ➢ To make a form as MDI Form set its IsMdiContainer property as true. ➢ To define a parent form to a child form set MdiParent property. ➢ To arrange the child forms, use LayoutMdi() method. ➢ To get reference of the current child form use ActiveMdiChild property. ➢ To get reference of a control from the child form use its Controls collection. Output: