Beruflich Dokumente
Kultur Dokumente
Net
and ASP.Net
1
Practical No. 01
Enumeration : Enumeration is a related set of constants. They are used when
working with many constants of the same type. It's declared with the Enum keyword.
Output of above code is the image below:
Imports System.Console
Module Module1
Enum Seasons
Summer = 1
Winter = 2
Spring = 3
Autumn = 4
End Enum
Sub Main()
Write("Summer is the" & Seasons.Summer & "season")
End Sub
End Module
2
Practical No. 02
If....Else statement
If conditional expression is one of the most useful control structures which allows us
to execute a expression if a condition is true and execute a different expression if it is
False. The syntax looks like this:
If condition Then
[statements]
Else If condition Then
[statements]
-
-
Else
[statements]
End If
If the condition is true, the statements following the Then keyword will be executed,
else, the statements following the ElseIf will be checked and if true, will be executed,
else, the statements in the else part will be executed.
Imports System.Console
Module Module1
Sub Main()
Dim i As Integer
WriteLine("Enter an integer, 1 or 2 or 3")
i = Val(ReadLine())
'ReadLine() method is used to read from console
If i = 1 Then
WriteLine("One")
ElseIf i = 2 Then
WriteLine("Two")
ElseIf i = 3 Then
WriteLine("Three")
Else
WriteLine("Number not 1,2,3")
End If
End Sub
End Module
3
Practical No. 03
Select....Case Statement
The Select Case statement executes one of several groups of statements depending
on the value of an expression. If your code has the capability to handle different
values of a particular variable then you can use a Select Case statement. You use
Select Case to test an expression, determine which of the given cases it matches and
execute the code in that matched case.
Imports System.Console
Module Module1
Sub Main()
Dim keyIn As Integer
WriteLine("Enter a number between 1 and 4")
keyIn = Val(ReadLine())
End Sub
End Module
4
Practical No. 04
For Loop
The For loop is the most popular loop. For loops enable us to execute a series of
expressions multiple numbers of times. The For loop in VB .NET needs a loop index
which counts the number of loop iterations as the loop executes. The syntax for the
For loop looks like this:
The index variable is set to start automatically when the loop starts. Each time in the
loop, index is incremented by step and when index equals end, the loop ends.
Module Module1
Sub Main()
Dim d As Integer
For d = 0 To 2
System.Console.WriteLine("In the For Loop")
Next d
End Sub
End Module
5
Practical No. 05
Arrays
Arrays are programming constructs that store data and allow us to access them by
numeric index or subscript. Arrays helps us create shorter and simpler code in many
situations. Arrays in Visual Basic .NET inherit from the Array class in the System
namespace. All arrays in VB as zero based, meaning, the index of the first element is
zero and they are numbered sequentially.
Imports System.Console
Module Module1
Sub Main()
Dim sport(5) As String
'declaring an array
sport(0) = "Soccer"
sport(1) = "Cricket"
sport(2) = "Rugby"
sport(3) = "Aussie Rules"
sport(4) = "BasketBall"
sport(5) = "Hockey"
'storing values in the array
WriteLine("Name of the Sport in the third location" & " " & sport(2))
'displaying value from array
End Sub
End Module
6
Practical No. 06
Classes and Objects
Classes are types and Objects are instances of the Class. Classes and Objects are
very much related to each other. Without objects you can't use a class. In Visual
Basic we create a class with the Class statement and end it with End Class. The
Syntax for a Class looks as follows:
----- Variables
-----Methods
-----Properties
-----Events
End Class
The above syntax created a class named Test. To create a object for this class we use
the new keyword and that looks like this: Dim obj as new Test(). The following
code shows how to create a Class and access the class with an Object. Open a
Console Application and place the following code in it.
Module Module1
Imports System.Console
Sub Main()
Dim obj As New Test()
'creating a object obj for Test class
obj.disp()
'calling the disp method using obj
Read()
End Sub
End Module
7
Practical No. 07
Inheritance
A key feature of OOP is reusability. It's always time saving and useful if we can reuse
something that already exists rather than trying to create the same thing again and
again. Reusing the class that is tested, debugged and used many times can save us
time and effort of developing and testing it again. Once a class has been written and
tested, it can be used by other programs to suit the program's requirement. This is
done by creating a new class from an existing class. The process of deriving a new
class from an existing class is called Inheritance. The old class is called the base class
and the new class is called derived class. The derived class inherits some or
everything of the base class. In Visual Basic we use the Inherits keyword to inherit
one class from other. The general form of deriving a new class from an existing class
looks as follows:
Using Inheritance we can use the variables, methods, properties, etc, from the base
class and add more functionality to it in the derived class. The following code
demonstrates the process of Inheritance in Visual Basic.
8
Imports System.Console
Module Module1
Sub Main()
Dim ss As New Two()
WriteLine(ss.sum())
Read()
End Sub
End Module
End Class
End Class
9
Practical No. 08
Math Functions
Visual Basic provides support for handling Mathematical calculations. Math functions
are stored in System.Math namespace. We need to import this namespace when we
work with Math functions. The functions built into Math class helps us calculate the
Trigonometry values, Square roots, logarithm values, etc.
Imports System.Console
Imports System.Math
Module Module1
Sub Main()
WriteLine("Sine 90 is" & " " & Sin(90))
'display Sine90 value
WriteLine("Square root of 81 is " & " " & Sqrt(81))
'displays square root of 81
WriteLine("Log value of 12 is" & " " & Log(12))
'displays the logarithm value of 12
Read()
End Sub
End Module
10
Practical No. 09
TextBox Control
Windows users should be familiar with textboxes. This control looks like a box and
accepts input from the user. The TextBox is based on the TextBoxBase class which is
based on the Control class. TextBoxes are used to accept input from the user or used
to display text. By default we can enter up to 2048 characters in a TextBox but if the
Multiline property is set to True we can enter up to 32KB of text. The image below
displays a Textbox. The default event of the TextBox is the TextChanged Event.
RichTextBox
RichTextBoxes are similar to TextBoxes but they provide some advanced features
over the standard TextBox. RichTextBox allows formatting the text, say adding
colors, displaying particular font types and so on. The RichTextBox, like the TextBox
is based on the TextBoxBase class which is based on the Control class. These
RichTextBoxes came into existence because many word processors these days allow
us to save text in a rich text format. With RichTextBoxes we can also create our own
word processors. We have two options when accessing text in a RichTextBox, text
and rtf (rich text format). Text holds text in normal text and rtf holds text in rich text
format. Image of a RichTextBox is shown below.
6. Label
Labels are those controls that are used to display text in other parts of the
application. They are based on the Control class. The default event of Label is the
Click event. Notable property of the label control is the text property which is used to
set the text for the label.
Label1.Text = "Label"
11
CheckBox
CheckBoxes are those controls which gives us an option to select, say, Yes/No or
True/False. A checkbox is clicked to select and clicked again to deselect some option.
When a checkbox is selected a check (a tick mark) appears indicating a selection.
The CheckBox control is based on the TextBoxBase class which is based on the
Control class. The default event of the CheckBox is the CheckedChange
event. Below is the image of a Checkbox.
RadioButton
12
Below is the image of a RadioButton.
13
Database and
Information System
14
Practical No. 01
SQL Syntax
SQL Result
Company Country
Island Trading UK
Galería del gastrónomo Spain
Laughing Bacchus Wine Cellars Canada
Paris spécialités France
Simons bistro Denmark
Wolski Zajazd Poland
SQL WHERE
Table: Customers
If we want to select all customers from our database table, having last name
'Smith' we need to use the following SQL syntax:
15
SELECT *
FROM Customers
WHERE LastName = 'Smith'
In this simple SQL query we used the "=" (Equal) operator in our WHERE
criteria:
LastName = 'Smith'
But we can use any of the following comparison operators in conjunction with
the SQL WHERE clause:
SELECT *
FROM Customers
WHERE LastName <> 'Smith'
SELECT *
FROM Customers
WHERE DOB > '1/1/1970'
SELECT *
FROM Customers
WHERE DOB >= '1/1/1970'
16
< (Less than)
SELECT *
FROM Customers
WHERE DOB < '1/1/1970'
SELECT *
FROM Customers
WHERE DOB =< '1/1/1970'
SELECT *
FROM Customers
WHERE Phone LIKE '626%'
17
Practical No. 02
SQL UPDATE
UPDATE Table1
SET Column1 = Value1, Column2 = Value2
WHERE Some_Column = Some_Value
The SQL UPDATE clause changes the data in already existing database
row(s) and usually we need to add a conditional SQL WHERE clause to our
SQL UPDATE statement in order to specify which row(s) we intend to
update.
UPDATE Customers
SET DOB = '5/10/1974'
WHERE LastName = 'Goldfish' AND FirstName = 'Steven'
We can update several database table rows at once, by using the SQL WHERE
clause in our UPDATE statement. For example if we want to change the
phone number for all customers with last name Smith (we have 2 in our
example Customers table), we need to use the following SQL UPDATE
statement:
18
UPDATE Customers
SET Phone = '626 555-5555'
WHERE LastName = 'Smith'
19
Practical No. 03
SQL DELETE
The SQL DELETE command has the following generic SQL syntax:
If you skip the SQL WHERE clause when executing SQL DELETE
expression, then all the data in the specified table will be
deleted. The following SQL statement will delete all the data
from our Customers table and we’ll end up with completely empty
table:
The SQL query above will delete all database rows having LastName
'Smith' and will leave the Customers table in the following
state:
20
Practical No. 04
SQL JOIN
The SQL JOIN clause is used whenever we have to select data from 2 or
more tables.
To be able to use SQL JOIN clause to extract data from 2 (or more) tables,
we need a relationship between certain columns in these tables.
We are going to illustrate our SQL JOIN example with the following 2 tables:
Customers:
Sales:
As you can see those 2 tables have common field called CustomerID and
thanks to that we can extract information from both tables by matching their
CustomerID columns.
21
SELECT Customers.FirstName, Customers.LastName,
SUM(Sales.SaleAmount) AS SalesPerCustomer
FROM Customers, Sales
WHERE Customers.CustomerID = Sales.CustomerID
GROUP BY Customers.FirstName, Customers.LastName
The SQL expression above will select all distinct customers (their first and last
names) and the total respective amount of dollars they have spent.
The SQL JOIN condition has been specified after the SQL WHERE clause and
says that the 2 tables have to be matched by their respective CustomerID
columns.
The SQL statement above can be re-written using the SQL JOIN clause like
this:
There are 2 types of SQL JOINS – INNER JOINS and OUTER JOINS. If you
don't put INNER or OUTER keywords in front of the SQL JOIN keyword, then
INNER JOIN is used. In short "INNER JOIN" = "JOIN" (note that different
databases have different syntax for their JOIN clauses).
The INNER JOIN will select all rows from both tables as long as there is a
match between the columns we are matching on. In case we have a customer
in the Customers table, which still hasn't made any orders (there are no
entries for this customer in the Sales table), this customer will not be listed in
the result of our SQL query above.
22
CustomerID Date SaleAmount
2 5/6/2004 $100.22
1 5/6/2004 $99.95
Even though Paula and James are listed as customers in the Customers table
they won't be displayed because they haven't purchased anything yet.
But what if you want to display all the customers and their sales, no matter if
they have ordered something or not? We’ll do that with the help of SQL
OUTER JOIN clause.
The second type of SQL JOIN is called SQL OUTER JOIN and it has 2 sub-
types called LEFT OUTER JOIN and RIGHT OUTER JOIN.
The LEFT OUTER JOIN or simply LEFT JOIN (you can omit the OUTER
keyword in most databases), selects all the rows from the first table listed
after the FROM clause, no matter if they have matches in the second table.
23
CustomerID Date SaleAmount
2 5/6/2004 $100.22
1 5/6/2004 $99.95
As you can see we have selected everything from the Customers (first table).
For all rows from Customers, which don’t have a match in the Sales (second
table), the SalesPerCustomer column has amount NULL (NULL means a
column contains nothing).
The RIGHT OUTER JOIN or just RIGHT JOIN behaves exactly as SQL LEFT
JOIN, except that it returns all rows from the second table (the right table in
our SQL JOIN statement).
24
Practical No. 05
SQL AND & OR
The SQL AND clause is used when you want to specify more than one
condition in your SQL WHERE clause, and at the same time you want all
conditions to be true.
For example if you want to select all customers with FirstName "John" and
LastName "Smith", you will use the following SQL expression:
The following row in our Customer table, satisfies the second of the
conditions (LastName = 'Smith'), but not the first one (FirstName = 'John'),
and that's why it's not returned by our SQL query:
The SQL OR statement is used in similar fashion and the major difference
compared to the SQL AND is that OR clause will return all rows satisfying any
of the conditions listed in the WHERE clause.
25
The result of this query will be the following:
You can combine AND and OR clauses anyway you want and you can use
parentheses to define your logical expressions.
Here is an example of such a SQL query, selecting all customers with
LastName 'Brown' and FirstName either 'James' or 'Paula':
26
Practical No. 06
SQL ORDER BY
The SQL ORDER BY clause comes in handy when you want to sort your SQL
result sets by some column(s). For example if you want to select all the
persons from the already familiar Customers table and order the result by
date of birth, you will use the following statement:
As you can see the rows are sorted in ascending order by the DOB column,
but what if you want to sort them in descending order? To do that you will
have to add the DESC SQL keyword after your SQL ORDER BY clause:
The result of the SQL query above will look like this:
If you don't specify how to order your rows, alphabetically or reverse, than
the result set is ordered alphabetically, hence the following to SQL
expressions produce the same result:
27
SELECT * FROM Customers
ORDER BY DOB
You can sort your result set by more than one column by specifying those
columns in the SQL ORDER BY list. The following SQL expression will order
by DOB and LastName:
28
Networking with Red
Hat Linux &
Wireless
Communication
29
Basic Linux Commands:
Comman
Example Description
d
cat Sends file contents to standard output. This is a
way to list the contents of short files to the
screen. It works well with piping.
cat .bashrc Sends the contents of the ".bashrc" file to the
screen.
cd Change directory
cd /home Change the current working directory to /home.
The '/' indicates relative to root, and no matter
what directory you are in when you execute
this command, the directory will be changed to
"/home".
cd httpd Change the current working directory to httpd,
relative to the current location which is
"/home". The full path of the new working
directory is "/home/httpd".
cd .. Move to the parent directory of the current
directory. This command will make the current
working directory "/home.
cd ~ Move to the user's home directory which is
"/home/username". The '~' indicates the users
home directory.
cp Copy files
cp myfile yourfile Copy the files "myfile" to the file "yourfile" in
the current working directory. This command
will create the file "yourfile" if it doesn't exist. It
will normally overwrite it without warning if it
exists.
cp -i myfile yourfile With the "-i" option, if the file "yourfile" exists,
you will be prompted before it is overwritten.
cp -i /data/myfile . Copy the file "/data/myfile" to the current
working directory and name it "myfile". Prompt
before overwriting the file.
cp -dpr srcdir Copy all files from the directory "srcdir" to the
destdir directory "destdir" preserving links (-p option),
file attributes (-p option), and copy recursively
(-r option). With these options, a directory and
all it contents can be copied to another
directory.
31
shutdown -h now Shuts the system down to halt immediately.
shutdown -r now Shuts the system down immediately and the
system reboots.
whereis Show where the binary, source and manual
page files are for a command
whereis ls Locates binaries and manual pages for the ls
command.
32
Practical No. 01
Cal
1. Name
cal - displays a calendar and the date of easter
2. Synopsis
cal [-3jmy] [[month] year]
4. Examples
cal without any options displays current month in current year:
$ cal
33
Cal is also able to predict vary distant future, not sure if any of us will ever
need it, but here is month Jun for year 10001, so make sure that you do not
miss your appointment !:
$ cal 6 10001
34
Practical No. 02
cd:
1. Name
cd - change directory
3. Examples
In unix systems there two most frequently used commands, one is "ls" and
the other is "cd". Command "cd" allows us to navigate through file system. To
navigate to /etc/ directory simply enter:
$ cd /etc
4. Relative Path
5. Absolute Path
35
Practical No. 03
Touch
1. Name
touch - change file timestamps
2. Synopsis
touch [OPTION]... FILE...
4. Examples
touch command enables us to change access and modification time for a
given files. Also touch command can be use to create files. Lets create file
named touchfile.txt:
$ touch touchfile.txt
now we can use touch command to change access and modification time to
current time:
$ touch touchfile.txt
36
Or if we want to change just access time we use -a option
$ touch -a touchfile.txt
Now lets say that we would like to change access and modification time back
to 29 January 2005 13:45.45
$ touch -t 200501291345.45 touchfile.txt
37
Practical No. 04
Tail
1. Name
tail - output the last part of files
2. Synopsis
tail [OPTION]... [FILE]...
4. Examples
Lets create sample file. This file will contain names of all directories in /var/.
We can also number each line for better overview.
for f in $( ls /var/ ); do echo $f; done | nl > file1
To use tail command on byte level we can use -c option. This option will make
tail command to display last 4 bytes (4 characters) if a given file:
tail -c 4 file1
If you wonder why we can see only 3 characters, use od command to see
where the 4th byte is:
tail -c 4 file1 | od -a
Another very useful option for tail command is -f. This option will continuously
display a file as it is dynamically edited by another process. This option is
very useful for watching log files.
tail -f /var/log/syslog
39
Practical No. 05
Time
1. Name
time - run programs and summarize system resource usage
2. Synopsis
time [ -apqvV ] [ -f FORMAT ] [ -o FILE ]
[ --append ] [ --verbose ] [ --quiet ] [ --portability ]
[ --format=FORMAT ] [ --output=FILE ] [ --version ]
[ --help ] COMMAND [ ARGS ]
3. Examples
Measure time for running program time itself:
$ time
40
Practical No. 06
pwd
1. Name
pwd - print name of current/working directory
2. Synopsis
pwd [OPTION]
3. Examples
Pwd linux command prints name of current/working directory.
pwd
Alternative to the pwd command could be dirs which prints the same output:
dirs -l
41