0% found this document useful (0 votes)
3 views12 pages

Visual Basic Lab Manual

This document is a laboratory manual for Event Driven Programming using Visual C# and VB.Net, designed for second-year Information Systems students at Mizan-Tepi University. It provides guidance on creating console applications, understanding data types, and implementing user input, along with practical exercises to reinforce learning. The manual emphasizes the importance of practice and offers examples of code structures, operators, and control statements.

Uploaded by

tolahussein36
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)
3 views12 pages

Visual Basic Lab Manual

This document is a laboratory manual for Event Driven Programming using Visual C# and VB.Net, designed for second-year Information Systems students at Mizan-Tepi University. It provides guidance on creating console applications, understanding data types, and implementing user input, along with practical exercises to reinforce learning. The manual emphasizes the importance of practice and offers examples of code structures, operators, and control statements.

Uploaded by

tolahussein36
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

Mizan-Tepi University

School of computing and informatics


Department of information systems
Event Driven Programming Lab Manual

Using Visual C# programming IDE


Prepared for 2nd year IS students
Visual Basic Lab manual
Hello guys, ladies and gentlemen this is the event driven programming language laboratory manual
which was prepared for you which helps as a guidance. Everybody must try more than five additional
program code for each sample given below.

Never and forever stop trying and typing!!!!


If you fail, you are planned to fail!!!!!

A [Link] program
A [Link] program basically consists of the following parts −

 Namespace declaration

 A class or module

 One or more procedures

 Variables

 The Main procedure

 Statements & Expressions

 Comments

C# can be used in a window-based, web-based, or console application. To start with, we


will create a console application to work with C#. Open Visual Studio (2010, 2013 or later)
installed on your local machine. Click on File -> New Project... from the top menu, as shown
below.

1
Create a New Project in Visual Studio 2017

From the New Project popup, shown below, select Visual C# in the
left side panel and select the Console App in the right-side panel.

Name of the
project

Select Visual C# Console App Template

In the name section, give any appropriate project name, a location where you want to
create all the project files, and the name of the project solution. Click OK to create the
console project. [Link] will be created as default a C# file in Visual Studio where you
can write your C# code in Program class, as shown below. (The .cs is a file extension for
C# file.)

2
C# Console Program
Every console application starts from the Main () method of the Program class.
The following example displays see the code screenshot given below.

Reference of .Net framework


Namespaces

Namespaces Name
Class Name
Main method

Method to display
value on console
Indicates the end of
any statement

WriteLine or write is a method of the Console class defined in the System namespace. This
statement causes the message "this is my first event driven programming labaoratory class"
to be displayed on the screen.

The last line [Link]() is for the [Link] Users. This will prevent the screen from
running and closing quickly when the program is launched from Visual Studio .NET.

3
Output of the above program

Compile & Execute [Link] Program


If you are using Visual [Link] IDE, take the following steps −
 Start Visual Studio.
 On the menu bar, choose File → New → Project.
 Choose Visual Basic from templates
 Choose Console Application.
 Specify a name and location for your project using the Browse button, and then
choose the OK button.
 The new project appears in Solution Explorer.
 Write code in the Code Editor.
 Click the Run button or the F5 key to run the project.

Data types refer to an extensive system used for declaring variables or functions
of different types. The type of a variable determines how much space it occupies
in storage and how the bit pattern stored is interpreted.

A variable is nothing but a name given to a storage area that our programs can
manipulate. Each variable in [Link] has a specific type, which determines the
size and layout of the variable's memory; the range of values that can be stored
within that memory; and the set of operations that can be applied to the
variable.

We have already discussed various data types. The basic value types provided
in [Link] can be categorized as –

4
Type Example

Integral types SByte, Byte, Short, UShort, Integer, UInteger, Long, ULong and
Char

Floating point types Single and Double

Decimal types Decimal

Boolean types True or False values, as assigned

Date types Date

variable
Variable
initialization

Data types

Output

Let's see the datatype

The value x=32767

The value y=-2147483648


Explicit conv
The value w=35455
Variable declaration
The value z=3.5
implicit conv The value a=234.432

I am Information Systems student

The value d=True

The value i=234


Lvalues and Rvalues The value k=234

There are two kinds of expressions −

5
 lvalue − An expression that is an lvalue may appear as either the left-hand or right-
hand side of an assignment.
 rvalue − An expression that is an rvalue may appear on the right- but not left-hand
side of an assignment.
Variables are lvalues and so may appear on the left-hand side of an assignment. Numeric
literals are rvalues and so may not be assigned and can not appear on the left-hand side.
Following is a valid statement −
Dim g As Integer = 20
But following is not a valid statement and would generate compile-time error −
20 = g

Accepting Input from User


In this section I’ll show you how to accept input from user rather than assigning constant
value by using ReadLine() function.

Output
Accepting user input
enter the value of x
34
enter the value of d
34
enter the value of s
information systems
The value of s =
information systems
The value of x = 34
The value of d = 34

ReadLine() always read any user input as


string, so you need to convert this string into
appropriate data type format

6
Practical Exercise 1

1. write a program that prints or displays the information’s which are written in your
university identity card.

N.B: your information must keep the spacing, punctuation and others things

2. modify the above question through accepting the input from user and display the
entered input for the user.

3. check the program given below whether it have an error or not. If then identify the
type of error, and corresponding line number and re-write the correct program. For
example, assume namespace error module as line number 4

4. namespace error
5. {
6. class Program
7. {
8. static void Main(string[] args)
9. {
10. int x, y;
11. short a = 32768;
12. double 5b = 567;
13. [Link]("The value of x: " + x);
14. [Link]("the summation of x and y: " + (x+y));
15. [Link]();
16. }
17. }
18. }

Applying math(arithmetic) and Logical operators in VB


As you have learned in C++ programming language also uses different arithmetic operators
to perform different operations as well as logical operators.

Arithmetic Conditional Logic operators


Symbols Descriptions Symbols Descriptions Symbols Descriptions
/ Division <> (!=) Not equal && And
* Multiplication >= Greater than or || Or
equal to
+ Addition <= Less than or
equal to
- Subtraction == equal
% Reminder < Less than
> Greater than

7
using System;
using [Link];
using [Link];
using [Link];

namespace error
{
class Program
{
static void Main(string[] args)
{
int x, y;
char w;
double z=0;
[Link]("enter the value of x");
x = Convert.ToInt32([Link]());
[Link]("enter the value of x");
y = Convert.ToInt32([Link]());
[Link]("enter the symbol of any arithmetic operator");
w = [Link]([Link]());
if (w == '/' && y! =0)
{
z = x / y;
[Link]("the result is= "+ z);
}
Output
else if (w == '*') enter the value of x
{
z = x * y; 4
[Link]("the result is= " + z);
} enter the value of y
else if (w == '+')
{ 2
z = x+y;
[Link]("the result is= " + z); enter the symbol of any
}
else if (w == '-') arithmetic operator
{
z = x-y;
/
[Link]("the result is= " + z);
the result is= 2
}
else if (w =='%')
{
z = x % y;
[Link]("the result is= " + z);
}
else
{
[Link]("Please enter the correct arithmetic operator");
}
[Link]();
}
}
}

8
Output

enter username
yes
enter the password
yes1234
WElCOME yes
Please enter the correct
username or password

Output
Nested If statement

Nested if statement means defining or using another if statement inside the if


statement. The inner if statement always depend on the outer if statement. For
instance, the first if statement don’t fulfill the given condition it directly goes to the
else part of the outer if statement which means it doesn’t check inner if statement.
For example, if the age value is 17 and if a person has license what will be the output???

9
using System;
using [Link];
using [Link];
using [Link];

namespace switchcase
{
class Program
{
static void Main(string[] args)
{
int x;
[Link]("enter any number start from 1 to 7");
x = Convert.ToInt32([Link]());
switch(x)
{ Output
case 1:
[Link]("the day is Monday");
break;
case 2:
[Link]("the day is Tuesday");
break;
case 3: enter any number start from 1 to 7
[Link]("the day is Wednesday");
break; 4
case 4:
the day is Thursday
[Link]("the day is Thursday");
break;
case 5:
[Link]("the day is Friday");
break;
case 6:
[Link]("the day is Saturday");
break;
case 7:
[Link]("the day is Sunday");
break;
default:
[Link]("No morethan 7 days in this world");
break;
}
[Link]();
}
}
}

Practical exercise 2

1. Write a program that compare two numbers and print out the largest number using
if then else statement. Remember you have to assign the static value for two integer
variables which is called variable initialization.

2. Write a program that accept the student mark from 100% from user and displays the
student grade in letter format based on the institution grade scaling standard. In this

10
case, I need you to refer the MTU grading scale format and use any appropriate
conditional statement.

3. Write a program that accept three floating point numbers from user and display the
smallest one through comparing those numbers using nested if statement.

N.B: don’t copy from this lab manual and lecturer PowerPoint or docx.

Loop statement

11

You might also like