VB Prac
VB Prac
NET Course
number1 = 3
number2 = 5
Textbox1.Text = answer
Exercise B
FirstName ="Bill"
LastName = "Gates"
Textbox1.Text = FullName
Exercise C
Dim FirstName As String
Dim MiddleName As String
Dim LastName As String
Dim FullName As String
FirstName ="Bill"
MiddleName = "Henry"
LastName = "Gates"
FullName = FirstName & " " & MiddleName & " " & LastName
Textbox1.Text = FullName
Exercise D
FirstName = txtFirstName.Text
LastName = txtLastName.Text
txtWholeName.Text = WholeName
Exercise E
txtVariables.Text = ButtonContents
Exercise G
agerange = Val(textbox1.Text)
Case 20 To 29
Case 30 To 39
MessageBox.Show(“In Thirties ”)
Case Else
End Select
number_in_textbox = Val(TextBox1.Text)
Else
End If
Item One, Item Two, Item Three below can be replaced by whatever items you have in your
Combo Box list.
MyVariable = ComboBox1.Text
Select Case MyVariable
MessageBox.Show("You like " & MyVariable & ", I see - good choice")
End Select
Exercise H
startNumber = Val(TextBox1.Text)
endNumber = Val(TextBox2.Text)
MessageBox.Show("Empty textbox")
Exit Sub
End If
answer = answer + i
Next i
MessageBox.Show(answer)
Exercise I
Dim message As String = ""
Dim counter As Integer = 0
End If
End If
End If
End If
End If
Case 0
Case 2
Case 3
Case 4
Case 5
End Select
Exercise J
letter = strText.Substring(1)
to this:
letter = strText.Substring(i)
By using the loop variable i you advanced the counter for Substring.
Exercise K
For i = 0 To TextLength - 1
OneCharacter = FirstName.Chars(i)
If IsNumeric(OneCharacter) Then
End If
Next
Exercise L
FirstName = txtChars.Text
TextLength = FirstName.Length
For i = 0 To TextLength - 1
OneCharacter = FirstName.Chars(i)
If IsNumeric(OneCharacter) Then
numbercount = numbercount + 1
End If
Next
Exercise M
Checking for a valid email address is quite tricky. In the code below, the Sub is just checking if
the email address has an @ sign. Notice that the Sub uses two paramaters, one to pass in the
email address and one to pass in the @ sign. You can then reuse this code to pass in, say, an
email address and the characters ".com"
'===================================
' BUTTON CODE
'===================================
Dim email As String
Dim chars_to_check As Char
email = txtEmail.Text
chars_to_check = "@"
TestEmail1(email, chars_to_check)
'===================================
' SUBROUTINE
'===================================
Private Sub TestEmail1( eMail As String, CheckChars As String)
If position = 0 Then
End If
End Sub
Exercise N
CheckTextBox = Trim(TextBox1.Text)
CheckTextBox = StrConv(CheckTextBox, VbStrConv.ProperCase)
TextBox1.Text = CheckTextBox
End Sub
Exercise O
Here are the Set and Get properties that change the height and width. (As was mentioned in the
text, however, the name of the Class (ConvertPostcode) is not a very good name for what this
does - changing the height and width of an image! Plus, picture boxes already have a height and
width property)
Get
Return intHeight
End Get
intHeight = HeightValue
End Set
End Property
Get
Return intWidth
End Get
intWidth = WidthValue
End Set
End Property
And here is the code for the button that uses the two properties:
Dim objAlterPicPox As ConvertPostcode
Dim NewHeight As Integer
Dim NewWidth As Integer
objAlterPicPox.ChangeHeight = Val(txtHeight.Text)
NewHeight = objAlterPicPox.ChangeHeight
PictureBox1.Height = NewHeight
objAlterPicPox.ChangeWidth = Val(txtWidth.Text)
NewWidth = objAlterPicPox.ChangeWidth
PictureBox1.Width = NewWidth
objAlterPicPox = Nothing
Join Date
Sep 2006
Location
WindowFromPoint
Posts
4,081
Code:
This is also called as Base Class Library and it is common for all types of applications i.e.
the way you access the Library Classes and Methods in VB.NET will be the same in C#,
and it is common for all other languages in .NET.
The following are different types of applications that can make use of .net class library.
1. Windows Application.
2. Console Application
3. Web Application.
4. XML Web Services.
5. Windows Services.
In short, developers just need to import the BCL in their language code and use its
predefined methods and properties to implement common and complex functions like
reading and writing to file, graphic rendering, database interaction, and XML document
manipulation.
a variable is a storage area of the computer's memory. It is a temporary location in memory used
to hold data.
First, we start with the Dim word, indicating to Visual Basic that we want to set up a
variable
Then we give the variable a name (number1)
Next, we "tell" VB that what is going inside the variable is a number (As Integer)
Two more variable are set up in the same way, number2 and answer
Dim number1 As Integer
Dim number2 As Integer
Dim answer As Integer
d. INITIALIZING A VARIABLE
To perform an operation, SQL requires only few lines of code compared to other languages. SQL
statements include select which is used to access fields, tables and range of records in a database,
inserts for adding new data, and deletes for removing data. When a query is processed the result
will be returned in a Recordset.
Data Definition Language is the language used to define the organization and storage of data.
Some of the DDL statements are,
The Create Table statement is used for creating a table with the given table name and field types.
Syntax
CREATE TABLE tablename (field1 type [(size)] [NOT NULL] [index1] [, field2
type [(size)] [NOT NULL] [index2] [, ...]] [, CONSTRAINT constraintname
[, ...]]) ;
Example
Create table tabStudent
(varStud_id Varchar2(12) NOT NULL,
varLast_Name Varchar2(12) NULL,
varFirst_Name Varchar2(30) NOT NULL,
varSS_No Varchar2(12) NOT NULL );
This statement will create a table with name tabStudent with the fields
varStud_id, varLast_Name, varFirst_Name and varSS_No, in which the field
varLast_Name can be NULL.
ALTER TABLE Statement
The Alter Table statement is used for adding a new column to existing
database or changing the width of an existing column and specifying a
default value for an existing column.
Syntax
ALTER TABLE tablename {ADD {COLUMN field type[(size)] [NOT NULL]
[CONSTRAINT index] [CONSTRAINT multifieldindex} ] ;
Example
ALTER TABLE tabStudent MODIFY (varStud_id Varchar2(12) NOT NULL);
DROP TABLE statement
The Drop Table statement is used for deleting a table from the database.
Syntax
DROP {TABLE table | INDEX index ON table} ;
Example
DROP tabStudent;
The arguments within square brackets are optional.
Data Manipulation Language is the language which is used to manipulate data in a database.
SELECT statement
The SELECT statement is the most commonly used SQL statement. It is used to retrieve a group
of records from the database and place them in a recordset or dynaset for use by the application
program.
Syntax
SELECT fields FROM tablenames WHERE condition [sort option] [Group Option].
Example
The statement given below will retrieve all fields from the table, tabABC,
The Insert into statement is used to insert new records into a table.
Syntax
INSERT INTO tablename [(field1[, field2[, ...]])]
VALUES (value1[, value2[, ...])
Example
Insert Into tabStudent
(tabStud_id, varLast_Name, varFirst_Name, varSS_No)
values ('1001','Philip','George','X10101');
UPDATE statement
The Update statement updates the values in a table.
Syntax
UPDATE table
SET new value
WHERE criteria;
Example
Update tabStudent
Set varStud_id='1010'
where student_id=14;
DELETE FROM Statement
The Delete From statement removes the specified records from the database.
Syntax
Delete From table_name
[Where condition];
Example
Delete From tabStudent
where varStud_id='1010';
In some cases two tables will have fields with same name. In this case, the table name and a
period should be added with the field name within your SQL instruction in order to specifically
identify the field name. If you want to retrieve some fields in one table and all fields from
another, you can use the asterisk field selection character with the name of the second table only.
Each table used in the earlier part of the SQL instruction should be specified in the FROM clause
of the SELECT statement. Relationships between the tables is specified in the WHERE clause by
using a JOIN condition. The WHERE clause is used more often than the "JOIN" instruction in
SQL statements. The complete SQL statement is as follows:
SELECT tabEmp.[Firstname], tabEmp.[Lastname], tabDep.* FROM tabEmp, tabDep WHERE tabEmp.varDepid =
tabDep.varDepid;
In the above statement two tables are tabEmp and tabDep, related using the field, varDepid and the
relation is specified with the JOIN condition, tabEmp.varDepid = tabDep.varDepid. The result of the
query is the first and last name from tabEmp table and all related data from tabDep table are selected.
WHERE condition
In the condition there are different logical statements. The various types of
logical statements are,
ORDER BY CLAUSE - Clauses can be used to specify the records that are retrieved be sorted in a specific
order. ORDER BY CLAUSE can be used for this purpose in the SELECT statement to get the rows in the
recordset in a specific order. The records in a dynaset can be sorted using the SORT order in the ORDER
BY clause. Multiple fields can be specified in the SORT method.
Example:
SELECT * FROM tabEmp ORDER BY intAge, varName Desc;
The above query will select the records in descending order with respect to intAge and varName
from the table tabEmp.
UNION of R and S
the union of two relations is a relation that includes all the tuples that are either in R or in S or in
both R and S. Duplicate tuples are eliminated.
INTERSECTION of R and S
the intersection of R and S is a relation that includes all tuples that are both in R and S.
DIFFERENCE of R and S
the difference of R and S is the relation that contains all the tuples that are in R but that are not
in S.
For set operations to function correctly the relations R and S must be union compatible. Two
relations are union compatible if
the domain of each attribute in column order is the same in both R and S.
UNION Example
INTERSECTION Example
DIFFERENCE Example
The Cartesian Product is also an operator which works on two sets. It is sometimes called the CROSS
PRODUCT or CROSS JOIN.
It combines the tuples of one relation with all the tuples of the other relation.
CARTESIAN PRODUCT example
JOIN Example