0% found this document useful (0 votes)
40 views

VB Assignment2 Solutions

The document contains code snippets for solving various VB.NET programming questions. It includes examples of calculating sums, determining even/odd numbers, finding maximum values, checking for leap years, and more. The code uses concepts like if/else statements, loops, variables, and selection structures.

Uploaded by

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

VB Assignment2 Solutions

The document contains code snippets for solving various VB.NET programming questions. It includes examples of calculating sums, determining even/odd numbers, finding maximum values, checking for leap years, and more. The code uses concepts like if/else statements, loops, variables, and selection structures.

Uploaded by

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

Author:Rounak Adhikary

Section:CSE 2A Roll:44
Assignment 2:(Do only the Questions Done here,rest were done before,i.e,previous
H.W's)
Question 3
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button1.Click
Dim n1, n2, ph, ad As String
n1 = TextBox1.Text
n2 = TextBox2.Text
ph = TextBox3.Text
ad = TextBox4.Text
MsgBox("***Welcome " + n1 + " " + n2 + "***" & vbNewLine & "Your Profile
Information: " & vbNewLine & "Ph.No : " + ph + " " & vbNewLine & "Address : " +
ad)
End Sub
End Class
Question 5
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button1.Click
Dim d As System.DateTime
Label1.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")
End Sub
End Class
Question 6
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button1.Click
Dim a As Integer
a = Val(TextBox1.Text)
If a Mod 2 = 0 Then
MsgBox("Number " + a.ToString + " is Even!")
Else
MsgBox("Number " + a.ToString + " is Odd!")
End If
End Sub
End Class
Question 8
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button1.Click
Dim a, b, c, max As Integer
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
c = Val(TextBox3.Text)
If (a > max) Then

max = a
End If
If (b > max) Then
max = b
End If
If (c > max) Then
max = c
End If
MsgBox("The Maximum no. of the three is : " + max.ToString)
End Sub
End Class
Question 9
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button1.Click
Dim a As Integer
a = Val(TextBox1.Text)
If (a Mod 400 = 0) Then
Label2.Text = "Is a Leap Year!"
ElseIf (a Mod 4 = 0 And a Mod 100 <> 0) Then
Label2.Text = "Is a Leap Year!"
Else
Label2.Text = "Is Not a Leap Year!"
End If
End Sub
End Class
Question 10
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button1.Click
Dim a, b As Double
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
Label1.Text = Math.Sqrt(a).ToString
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button2.Click
Dim a, b As Double
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
Label1.Text = Math.Pow(a, b).ToString
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button3.Click
Dim a, b As Double
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
Label1.Text = Math.Sin(a).ToString
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button4.Click

Dim a, b As Double
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
Label1.Text = Math.Cos(a).ToString
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button5.Click
Dim a, b As Double
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
Label1.Text = Math.Tan(a).ToString
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button6.Click
Dim a, b As Double
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
Label1.Text = Math.Exp(a).ToString
End Sub
End Class
Question 11
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button1.Click
Dim a As Integer
a = Val(TextBox1.Text)
Select Case a
Case 0 To 59
Label3.Text = "F"
Case 60 To 69
Label3.Text = "E"
Case 70 To 79
Label3.Text = "D"
Case 80 To 89
Label3.Text = "B"
Case 90 To 99
Label3.Text = "A"
Case 100
Label3.Text = "A+"
End Select
End Sub
End Class
Question 12
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button1.Click
Dim a As Char
a = TextBox1.Text
Select Case a
Case "r", "R"
Label3.Text = "Red"

Case "g", "G"


Label3.Text = "Green"
Case "b", "B"
Label3.Text = "Blue"
Case Else
Label3.Text = "Black"
End Select
End Sub
End Class
Question 13
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button1.Click
Dim n1, n2, i, sum As Integer
sum = 0
n1 = Val(TextBox1.Text)
n2 = Val(TextBox2.Text)
If n1 < n2 Then
For i = n1 To n2
sum = sum + i
Next
Label3.Text = sum.ToString
Else
Label3.Text = "Invalid Range!"
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button2.Click
Dim n1, n2, i, sum As Integer
sum = 0
n1 = Val(TextBox1.Text)
n2 = Val(TextBox2.Text)
If n1 < n2 Then
For i = n1 To n2
If i Mod 2 = 0 Then
sum = sum + i
End If
Next
Label3.Text = sum.ToString
Else
Label3.Text = "Invalid Range!"
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.E
ventArgs) Handles Button3.Click
Dim n1, n2, i, sum As Integer
sum = 0
n1 = Val(TextBox1.Text)
n2 = Val(TextBox2.Text)
If n1 < n2 Then
For i = n1 To n2
If i Mod 2 <> 0 Then
sum = sum + i
End If

Next
Label3.Text = sum.ToString
Else
Label3.Text = "Invalid Range!"
End If
End Sub
End Class
********THE END*******

You might also like