0% found this document useful (0 votes)
33 views46 pages

VB.Net Programming Exercises Guide

Uploaded by

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

VB.Net Programming Exercises Guide

Uploaded by

Isha Rani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PRACTICAL FILE

Dot Net

(ADVANCED EDUCATIONAL INSTITUTION 70 K.M., DELHI-MATHURA


ROAD, V.P.O.-AURANGABAD, TEHSIL-HODAL, [Link], HARYANA-
121105)

Submitted To:
Submitted By:
Name:
Class:
Roll no.:
Batch:
INDEX
SR. NAME OF PROGRAMS Date SIGNATURE
NO
.
1. Write a program for how to print simple text.
2. Write a program to show a message box with text
inside.
3. Write a program to perform Arithmetic operation.
4. Write a program to calculate simple interest.
5. Write a program to calculate area of some
mathematical figure.
6. Write a program to draw pattern.

7. Working with:
Message Boxes; Dialog Boxes; Menus; Toolbars
8. Write a program to store student information in
database.
9. Working with Web Forms server controls; label;
dropdown list box; Button; AdRotator; Textbox;
Checkbox etc.
10. Write a program to make an admission form.
11. Write a program to convert different types of
variables into string
12. Write a program to implement concept of
delegates
on Array List
13. Write a program to implement concept of Jagged
Array
14. Write a program to implement calculator

15. Write a program to demonstrate the join ()


method
of string class
16. Write a program to create a user-defined function
to add two integers
1. Write a program for how to print simple text.

INPUT:

Module Module1

Sub Main()
[Link]("Hello World")
[Link]()
End Sub

End Module
OUTPUT:
2: Write a program to show a message box with text inside.

INPUT:
OUTPUT:
3: Write a program to perform Arithmetic operation.

INPUT:
OUTPUT:

Line 1 - Value of c is
31 Line 2 - Value of c
is 11 Line 3 - Value of
c is 210 Line 4 - Value
of d is 2.1 Line 5 -
Value of c is 2 Line 6 -
Value of c is 1 Line 7 -
Value of c is 100
4: Write a program to calculate simple interest.

INPUT:

Imports System

Public Class Interest

Public Shared Sub simpleInterest(ByVal principle As


Double,
ByVal time As Double,
ByVal rate As Double)

[Link]("Principal : {0}", principle)


[Link]("Time : {0}", time)
[Link]("Rate : {0}", rate)

Dim amount As Double = (principle * time * rate) / 100


[Link]("Simple Interest : {0} "&vbLf,
amount)
End Sub
Public Shared Sub Main(ByVal args As String())

simpleInterest(1500, 3, 7.3)
simpleInterest(170.4, 7, 3.4)
End Sub
End Class
OUTPUT:
5: Write a Program to calculate area of some mathematical
figure.
INPUT:

'[Link] program to calculate the area of the rectangle.

Module Module1

Sub Main()

Dim length As Single = 0.0F


Dim breadth As Single = 0.0F
Dim area As Single = 0.0F

[Link]("Enter the length of rectangle: ")


length = [Link]([Link]())

[Link]("Enter the breadth of rectangle: ")


breadth = [Link]([Link]())

area = length * breadth

[Link]("Area of ractangle: {0}", area)

End Sub

End Module
OUTPUT:
6: Write a program to draw pattern.
INPUT:

Imports System
Module
Module1 Sub
Main()
Dim a, b, num As Integer ' initialize the local
variable [Link](" Enter the number of
rows: ")
num = [Link]() ' take an input from
the user For a = 1 To num
For b = 1 To a
[Link]("* ") ' print the
star Next
[Link]("") ' jump to new line
Next
[Link](" Press any key to exit...")
[Link]()
End Sub
End Module
OUTPUT:
7:Working with:
Message Boxes; Dialog Boxes; Menus; Toolbars

Message Box:
Input:
Output:
Dialog Box:

Input:
Output:
Menus:

Input:
Output:
Toolbar:
Input:
Output:
8:Write a program to store student information in database.
Output:
9:Working with Web Forms server controls; label; dropdown list
box; Button; Textbox; Checkbox

Label and Textbox:


Input:

<%@ Page Language="C#" AutoEventWireup="true"


CodeBehin d="[Link]"
Inherits="[Link]" %>
<!DOCTYPE html>
<html xmlns="[Link]
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1
{ width:
100%;
}
.auto-style2
{ margin-left:
0px; }
.auto-
style3 {
width:
121px; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h4>Provide the Following Details:</h4>
<table class="auto-style1">
<tr>
<td class="auto-style3">
<asp:Label ID="Label1" runat="server" Text="User
Name"></asp:Label></td>
<td>
<asp:TextBox ID="TextBox1" runat="server" CssClass="autostyle2">
</asp:TextBox></td>
</tr>
<tr>
<td class="auto-style3">
<asp:Label ID="Label2" runat="server" Text="Upload a
File"></asp:Label></td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>

Output:
Button:
Input:

Output:
Code Behind:

Output:
Checkbox:
Input:

Output:
Code behind:

Output:
DropDown List:
Input:

Output:
Code Behind:

Output:
10. Write a program to make an admission form.
<table align="center" class="style1" style="border: thin solid #008080">

<tr>

<td colspan="3"

style="border-bottom: thin solid #008080; font-weight: 700; text-align: center;">

Admission Form</td>

</tr>

<tr>

<td class="style5">

&nbsp;</td>

<td class="style4">

&nbsp;</td>

<td>

&nbsp;</td>

</tr>

<tr>

<td class="style6">

FirstName :

</td>

<td class="style4">

<asp:TextBox ID="txtfname" runat="server" Width="120px"></asp:TextBox>

</td>

<td>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"

ControlToValidate="txtfname" ErrorMessage="!!" ForeColor="Red"

SetFocusOnError="True"></asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td class="style6">

LastName :
</td>

<td class="style4">

<asp:TextBox ID="txtlname" runat="server" Width="120px"></asp:TextBox>

</td>

<td>

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"

ControlToValidate="txtlname" ErrorMessage="!!" ForeColor="Red"

SetFocusOnError="True"></asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td class="style6">

City :

</td>

<td class="style4">

<asp:TextBox ID="txtcity" runat="server" Width="120px"></asp:TextBox>

</td>

<td>

<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"

ControlToValidate="txtcity" ErrorMessage="!!" ForeColor="Red"

SetFocusOnError="True"></asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td class="style6">

Email :

</td>

<td class="style4">

<asp:TextBox ID="txtemail" runat="server" Width="120px"></asp:TextBox>

</td>

<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"

ControlToValidate="txtemail" ErrorMessage="!!" ForeColor="Red"

SetFocusOnError="True"></asp:RequiredFieldValidator>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1"

runat="server" ControlToValidate="txtemail" ErrorMessage="invalid email"

ForeColor="Red"

ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></
asp:RegularExpressionValidator>

</td>

</tr>

<tr>

<td class="style6">

Password&nbsp; :</td>

<td class="style4">

<asp:TextBox ID="txtpassword" runat="server" Width="120px"


TextMode="Password"></asp:TextBox>

</td>

<td>

<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"

ControlToValidate="txtpassword" ErrorMessage="!!" ForeColor="Red"

SetFocusOnError="True"></asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td class="style5">

&nbsp;</td>

<td class="style4">

<asp:Button ID="btnregistration" runat="server" Text="Register"

onclick="btnregistration_Click" />

</td>

<td>

&nbsp;</td>

</tr>
<tr>

<td class="style5">

&nbsp;</td>

<td class="style2" colspan="2">

<asp:Label ID="lblmsg" runat="server"></asp:Label>

</td>

</tr>

<tr>

<td colspan="3">

&nbsp;<asp:GridView ID="GridView1" runat="server">

</asp:GridView>

</td>

</tr>

</table>

The C# code for register button click :

protected void btnregistration_Click(object sender, EventArgs e)

[Link] = "";

SqlConnection SQLConn = new SqlConnection("Data Source=.\\SQLExpress; Initial Catalog=Blog;


Integrated Security=True");

SqlDataAdapter SQLAdapter = new SqlDataAdapter("insert into UserMst values('" +


[Link] + "','" + [Link] +
"','"+[Link]+"','"+[Link]+"','"+[Link]+"')", SQLConn);

DataTable DT = new DataTable();

[Link](DT);

SqlDataAdapter SQLAAdapter = new SqlDataAdapter("select * from UserMst", SQLConn);

DataTable DTT = new DataTable();


[Link](DTT);

[Link] = DTT;

[Link]();

[Link] = "Registration Done!!";

[Link] = "";

[Link] = "";

[Link] = "";

[Link] = "";

[Link]();

OUTPUT:
11. Write a program to convert different types of variables
into string.
Module Module1
Sub Main()
Dim a As Double = 123456.789
Dim b As Integer = 123
Dim c As Byte = 123
Dim d As Boolean = False

Dim str As String

str = [Link]()
[Link](str)

str = [Link]()
[Link](str)

str = [Link]()
[Link](str)

str = [Link]()
[Link](str)

[Link]()
End Sub

End Module

OUTPUT:
12. Write a program to implement concept of delegates on
Array List:

using System;
using [Link];
using [Link];
using [Link];
namespace Delegates_demo
{
public delegate int Mydelegate(int x,int y);
class sample
{
public static int rectangle(int a, int b)
{
return a * b;
}
}
class Program
{
static void Main(string[] args)
{
[Link]("My simple Delegate Program");

Mydelegate mdl = new Mydelegate([Link]);

[Link]("The Area of rectangle is {0}", mdl(4, 5));

[Link]();
}
}
}

OUTPUT:
13. Write a program to implement concept of Jagged Array:
using System;

class GFG {

public static void Main()


{

int[][] jagged_arr = new int[4][];

jagged_arr[0] = new int[] {1, 2, 3, 4};


jagged_arr[1] = new int[] {11, 34, 67};
jagged_arr[2] = new int[] {89, 23};
jagged_arr[3] = new int[] {0, 45, 78, 53, 99};

for (int n = 0; n < jagged_arr.Length; n++) {

[Link]("Row({0}): ", n);

for (int k = 0; k < jagged_arr[n].Length; k++)

{ [Link]("{0} ", jagged_arr[n][k]);


}
[Link]();
}
}
}

OUTPUT:
14. Write a program to implement calculator
using System;

using [Link];

using [Link];

namespace calculator_c_sharp

class Program

static void Main(string[] args)

string value;

do

int res;

[Link]("Enter first number:");

int num1 = Convert.ToInt32([Link]());

[Link]("Enter second number:");

int num2 = Convert.ToInt32([Link]());

[Link]("Enter symbol(/,+,-,*):");

string symbol = [Link]();

switch (symbol)

case "+":

res = num1 + num2;

[Link]("Addition:" + res);

break;

case "-":

res = num1 - num2;

[Link]("Subtraction:" + res);

break;
case "*":

res = num1 * num2;

[Link]("Multiplication:" + res);

break;

case "/":

res = num1 / num2;

[Link]("Division:" + res);

break;

default:

[Link]("Wrong

input"); break;

[Link]();

[Link]("Do you want to continue(y/n):");

value = [Link]();

while (value=="y" || value=="Y");

OUTPUT:
15. Write a program to demonstrate the join()method of
string class:

using System;
public class Demo {
public static void Main(string[] args) {
string[] strArr = {"AB", "BC", "CD", "DE", "EF", "FG", "GH", "IJ" };
[Link]("String Array...");
foreach(string s in strArr) {
[Link](s);
}
string str = [Link]("*", strArr);
[Link]("Result (after joining) = " + str);
}
}

OUTPUT:
16. Write a program to create a user-defined function to add
two integers:
using System;

class AddTwoNumbers {

//defining function

static int sumOfTwoNumber(int x, int y)

{ return x+y;

static void Main() {

try{

//declare two variables

int a = 0;

int b = 0;

[Link]("Enter first number: ");

a = Convert.ToInt32([Link]());

[Link]("Enter second number: ");

b =

Convert.ToInt32([Link]()); int

sum = sumOfTwoNumber(a,b);

[Link]("Addition of " + a + " and " + b + " is = " + sum);

catch(Exception ex)

{ [Link]("Error: " + [Link]());

OUTPUT:

You might also like