0% found this document useful (0 votes)
21 views16 pages

Prince

Uploaded by

Raj Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views16 pages

Prince

Uploaded by

Raj Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Sanepara Prince Div - d Rooll no -37

1. VB.Net program to calculate the sum of all elements of an integer array.


Public Class sum_01
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim arr(5) As Integer
Dim ans As Integer
arr(0) = 1
arr(1) = 2
arr(2) = 3

For i = 0 To arr.Count - 1
ans += arr(i)
Next
' MsgBox("answer:" & ans)

Label1.Text = "answer :" & ans


End Sub
End Class

P a g e 1 | 16
Sanepara Prince Div - d Rooll no -37
2. VB.Net program to find the largest element from the array of integers.
Public Class largest_02
Private Sub btnprint_Click(sender As Object, e As EventArgs) Handles btnprint.Click
Dim arr(5) As Integer
Dim large As Integer = 0

arr(0) = 1
arr(1) = 2
arr(2) = 30
arr(3) = 4
arr(4) = 5

For i = 0 To arr.Count - 1

If (large < arr(i)) Then


large = arr(i)
End If
Next
Label1.Text = "Largest Number :" & large & vbCrLf
End Sub
End Class

P a g e 2 | 16
Sanepara Prince Div - d Rooll no -37

3. VB.Net program to find the EVEN numbers from the array of integers.
Public Class Even_03
Private Sub btnprint_Click(sender As Object, e As EventArgs) Handles btnprint.Click

Dim arr() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}


Dim evenN As New List(Of Integer)

For i As Integer = 0 To arr.Length - 1


If arr(i) Mod 2 = 0 Then
evenN.Add(arr(i))
End If
Next
Dim result As String = "The EVEN numbers in the array : " & String.Join(", ", evenN)
Label1.Text = result
End Sub
End Class

P a g e 3 | 16
Sanepara Prince Div - d Rooll no -37

4. VB.Net program to find the second largest elements from the array of integers.
Public Class Second_largest_04
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim arr(5) As Integer
Dim first As Integer
Dim second As Integer
arr(0) = 1
arr(1) = 2
arr(2) = 30
arr(3) = 4
arr(4) = 7

For i = 0 To arr.Count - 1
If (first < arr(i)) Then
second = first
first = arr(i)
ElseIf (second < arr(i)) Then
second = arr(i)

P a g e 4 | 16
Sanepara Prince Div - d Rooll no -37
End If
Next

If (second <> 0) Then


Label1.Text = "Second largest element in array is: " & second & vbCrLf
Else
Label1.Text = "No second largest element found in the array." & vbCrLf
End If
End Sub
End Class

5. VB.Net program to demonstrate the DivideByZeroException

Public Class Exception_05


Private Sub btnprint_Click(sender As Object, e As EventArgs) Handles btnprint.Click
Try
Dim n1, n2, ans As Integer
n1 = TextBox1.Text
P a g e 5 | 16
Sanepara Prince Div - d Rooll no -37
n2 = TextBox2.Text
ans = n1 / n2
TextBox3.Text = ans.ToString
Catch ex As Exception
MsgBox(ex.ToString)
Finally
MsgBox("Fially Complete", MsgBoxStyle.Information, "message")
End Try
End Sub
End Class

6. VB.Net program to Program to change background color


Public Class background_color_06

Private Sub btnclick_Click(sender As Object, e As EventArgs) Handles btnclick.Click


BackColor = Color.Aqua

End Sub

P a g e 6 | 16
Sanepara Prince Div - d Rooll no -37
End Class

7. VB.Net program to load image in PictureBox on button click.


Public Class PictureBox_07
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'PictureBox1.Image =
Image.FromFile("C:\Users\Admin\OneDrive\Pictures\Phone\photos\IMG_20231221_174854
_387.jpg")
PictureBox1.ImageLocation =
"C:\Users\Admin\OneDrive\Pictures\Phone\photos\IMG_20231221_174854_387.jpg"
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


PictureBox1.ImageLocation =
"C:\Users\Admin\OneDrive\Pictures\Phone\photos\IMG20230910163454.jpg"
End Sub

P a g e 7 | 16
Sanepara Prince Div - d Rooll no -37
End Class

8. VB.Net program to display multiple selected CheckBox values in MessageBox


after click on button.
Public Class multiple_selected_CheckBox_08
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Fruits As New List(Of String)

If CheckBox1.Checked Then
Fruits.Add("apple")
End If

If CheckBox2.Checked Then
Fruits.Add("orange")
End If

P a g e 8 | 16
Sanepara Prince Div - d Rooll no -37
If CheckBox3.Checked Then
Fruits.Add("Guava")
End If

If Fruits.Count > 0 Then


Dim message As String = "selected Fruits is : " & String.Join(" and ", Fruits)
MessageBox.Show(message, "Selected Fruits", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
MessageBox.Show("Please select at least one fruit.", "No Fruits Selected",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
End Class

9. VB.Net program to add item from textbox to ComboBox.


Public Class textbox_to_ComboBox_09
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ComboBox1.Items.Add(TextBox1.Text)

P a g e 9 | 16
Sanepara Prince Div - d Rooll no -37
BackColor = Color.Green
End Sub
End Class

10.VB.Net program to add item from ComboBox to ListBox and sort ListBox
items.
Public Class ComboBox_to_ListBox_10
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ComboBox1.Items.Add(TextBox1.Text)
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


ListBox1.Items.Add(ComboBox1.SelectedItem)
ListBox1.Sorted = True
BackColor = Color.Green
End Sub

P a g e 10 | 16
Sanepara Prince Div - d Rooll no -37
End Class

11.VB.Net program to change BackColor of form by clicking on RadioButton.


Public Class change_BackColor_11
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox1.CheckedChanged
BackColor = Color.Red
ForeColor = Color.Black
End Sub

Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles


CheckBox2.CheckedChanged
BackColor = Color.Green
ForeColor = Color.Blue
End Sub

P a g e 11 | 16
Sanepara Prince Div - d Rooll no -37
Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox3.CheckedChanged
BackColor = Color.Blue
ForeColor = Color.Red

End Sub
End Class

12.VB.Net program to add Node in TreeView by click on button using InputBox.


Public Class TreeView_12
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim nodeText As String = InputBox("Enter Node name")
If TreeView1.SelectedNode Is Nothing Then

TreeView1.Nodes.Add(nodeText)
Else

TreeView1.SelectedNode.Nodes.Add(nodeText)
End If
P a g e 12 | 16
Sanepara Prince Div - d Rooll no -37
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


Dim nodeText As String = InputBox("Enter Root Node name")
TreeView1.Nodes.Add(nodeText)
End Sub
End Class

13.VB.Net program to create a link that open Google in default browser using
LinkLabel.
Public Class LinkLabel_13
Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs)
Handles LinkLabel1.LinkClicked
Process.Start("https://www.google.com/")
'ProcessStartInfo.WorkingDirectory

End Sub
P a g e 13 | 16
Sanepara Prince Div - d Rooll no -37
End Class

14. VB.Net program to set custom mask for contact number (Data Format-91-
1234567896) in MaskedTextBox.
Public Class Maskestextbox_14
Private Sub MaskedTextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles
MaskedTextBox1.KeyPress
If Not Char.IsControl(e.KeyChar) Then
If MaskedTextBox1.Text.Length = 0 Then
MaskedTextBox1.Text = "91-"
MaskedTextBox1.SelectionStart = MaskedTextBox1.Text.Length
ElseIf MaskedTextBox1.Text.Length = 3 Then
MaskedTextBox1.Text += "-"
MaskedTextBox1.SelectionStart = MaskedTextBox1.Text.Length
ElseIf MaskedTextBox1.Text.Length = 8 Then
MaskedTextBox1.Text += "-"
MaskedTextBox1.SelectionStart = MaskedTextBox1.Text.Length
End If

P a g e 14 | 16
Sanepara Prince Div - d Rooll no -37
End If
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Label2.Text = MaskedTextBox1.Text
End Sub
End Class

15. VB.Net program to display multiple selected CheckListBox items in label.


Imports System.Reflection.Emit

Public Class multiple_selected_CheckListBox_15


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim selectedItems As String = ""
For Each item As Object In CheckedListBox1.CheckedItems
selectedItems += item.ToString() + ", "
Next
If selectedItems.Length > 0 Then
P a g e 15 | 16
Sanepara Prince Div - d Rooll no -37
selectedItems = selectedItems.Substring(0, selectedItems.Length - 2)
End If
Label1.Text = "Selected Item Is :" & selectedItems

End Sub
End Class

P a g e 16 | 16

You might also like