VB-103-110
-
Upload
huidrom-sharat -
Category
Documents
-
view
221 -
download
0
Transcript of VB-103-110
-
7/30/2019 VB-103-110
1/7
Q103. What is the function of rptFunction control?
Q104. What is data report? Write the steps to create a data report
based on a query on a database?
Data reporting is key elements relating to an organization's performance in order
to improve different aspects. Data reporting measures performance, and
analyzes other key elements that can then be shared within the organization or
with the public.
Visual Basic 6 provides you with a data report designer to create your report.
The data report designer has its own set of controls which allow you to customize
your report seamlessly. The steps in creating the report in VB6 are listed below:
Step 1: Adding Data Report
Start Visual Basic as a Standard EXE project. From the Project menu in the VBE,
select Add Data Report in the dropdown menu. Now, you will be presented with
the data report environment. The data report environment contains 6 controls,
they are RptTextBox, RptLine, RptFunction, RptLabel, RptImage and RptShape.
You can customize your report here by adding a title to the page header using
the report label RptLabel. Simply drag and draw the RptLabel control on the data
report designer window and use the Caption property to change the text that
should be displayed. You can also add graphics to the report using the RptImage
control.
Step 2: Connecting the report to database using Data Environment Designer
Click the Project menu, then select Data Environment. from the drop-down
menu. The default data environment will appear. Now, to connect to the
database, right-click connection1 and select Microsoft Jet 4 OLE DB Provider
from the Data Link Properties dialog, then click next. Now, you need to connect
to the database by selecting a database file from your hard disk.
Step 3: Retrieving Information from the Database
In order to use the database in our report, we need to create query to retrieve
the information from the database. Here, we will use SQL command to create the
query. First of all, right click on MyConnection to add a command to the data
environment. The default command is Command1. In order to use SQL
command, right-click Command1 and we can see its properties dialog. At the
General tab, select SQL statement and key in the following SQL statement:
SELECT [field name1, field name2]
FROM Table1 ORDER BY []
-
7/30/2019 VB-103-110
2/7
This command is to select all the field1 and field2 from the table1 in the
database. The command ORDER BY [..] is to arrange the list in ascending order
according to the [..].
Now, we need to customize a few properties of our data report so that it can
connect to the database. The first property to set is the DataSource, set it toDataEnvironment. Next, we need to set the DataMember property to Command1.
To add data to our report, we need to drag the fields from Command1 in
DataEnvironment into DataReport. Visual Basic 6 will automatically draw a
RptTextBox, along with a RptLabel control for each field on the report. We can
customize the look of the labels as well as the TextBoxes from the properties
window of DataReport.
Q105. What is ADODC and difference with ADODB?
The Data control comes embedded into VB, just like the text box. It allows us toquickly and easily create a program for creating and using databases. The ADO
Data Control uses ADO to quickly create connection between data bound
controls and data providers. Data-bound controls are any controls that feature a
DataSource property. Data providers can be any source written to OLEDB
specification. We can also easily create our own data provider using Visual
Basics class module. We can add an ADO data control to a form like any other
control.
Sl.No. ADODC ADODB
1 ADODC is an ActiveX control. ADODB is a ActiveX DLL.
2 It is suitable for small project. It is suitable for big software.
3 It is just for making connection easily and to navigate through the data.
ADODB is much more like transaction handling and more command over
connection and recordset object.
Q106. Explain different string functions in VB.
Sl. No Function Syntax Description
1 Len----Len(string)-------Returns a Long containing the length of the
specified string.
Example: lngLen = Len("Visual Basic") ' lngLen = 12
2 Mid$ (or Mid)----Mid$(string, start[, length])------Returns a substring
containing a specified number of characters from a string.
Example: strSubstr = Mid$("Visual Basic", 3, 4) ' strSubstr = "sual"
-
7/30/2019 VB-103-110
3/7
3 Left$ (or Left)-----Left$(string, length)-----Returns a substring containing a
specified number of characters from the beginning (left side) of a string.
Example: strSubstr = Left$("Visual Basic", 3) ' strSubstr = "Vis"
4 UCase$ (or UCase)------UCase$(string)------Converts all lowercase letters ina string to uppercase. Any existing uppercase letters and non-alpha characters
remain unchanged.
Example: strNew = UCase$("Visual Basic") ' strNew = "VISUAL BASIC"
5 Instr------InStr([start,] string1, string2 [, compare])-----Returns a Long
specifying the position of one string within another. The search starts either at
the first character position or at the position specified by the start argument, and
proceeds forward toward the end of the string (stopping when either string2 is
found or when the end of the string1 is reached).
Examples: lngPos = Instr("Visual Basic", "a")
lngPos = 5
lngPos = Instr(6, "Visual Basic", "a")
lngPos = 9 (starting at position 6)
lngPos = Instr("Visual Basic", "A")
lngPos = 0 (case-sensitive search)
6 Space$ (or Space)------Space$(number)--------Returns a string containing
the specified number of blank spaces.
Examples: strTest = Space$(5) ' strTest = " "
7 String$ (or String)-------String$(number, character)-------Returns a string
containing a repeating character string of the length specified.
Examples: strTest = String$(5, "a")
' strTest = "aaaaa"
strTest = String$(5, 97)
' strTest = "aaaaa" (97 is the ASCII code for "a")
8 Replace$ (or Replace)-------Replace$(expression, find, replacewith[, start[,
count[, compare]]])------Returns a string in which a specified substring has been
replaced with another substring a specified number of times.
Examples: strNewDate = Replace$("08/31/2001", "/", "-")
strNewDate = "08-31-2001"
-
7/30/2019 VB-103-110
4/7
9 StrReverse$ (or StrReverse)------StrReverse$(string)-------Returns a string
in which the character order of a specified string is reversed.
Examples: strTest = StrReverse$("Visual Basic") strTest = "cisaBlausiV"
10 LTrim$ (or LTrim) LTrim$(string) Removes leading blank spacesfrom a string.
Examples: strTest = LTrim$(" Visual Basic ")
strTest = "Visual Basic "
11 RTrim$ (or RTrim) RTrim$(string) Removes trailing blank spaces from
a string.
Examples: strTest = RTrim$("Visual Basic") ' strTest = "Visual Basic"
12 Chr$ (or Chr)------Chr$(charcode)-------Returns a string containing thecharacter associated with the specified character code.
Examples: strChar = Chr$(65) ' strChar = "A"
13 Asc------Asc(string)------Returns an Integer representing the ASCII character
code corresponding to the first letter in a string.
Examples: intCode = Asc("*") ' intCode = 42
intCode = Asc("ABC") ' intCode = 65
Q107. Explain how ADO itself connect to a database.
There are various ways to access a database in VB6 such as DAO or ADO. ADO
stands for ActiveX Data Objects, while DAO is Data Access Object. To access a
database via ADO, you need to follow several steps: creating an ADO connection
to a database, opening the database connection, creating an ADO record set,
opening the record set, obtaining data from the record set and closing the record
set. VB6 also provides an ADO data control, which saves developers a lot of time
while developing database applications. With the ADO data control tool, you can
easily deploy database connection within your VB applications.
Q108. Describe ADO object model.
-
7/30/2019 VB-103-110
5/7
ADO is a set of objects that allow programmers to code te logic from languages
like VB6. ADO provides two objects for managing connections with data sources
(Connection and Command), two objects for managing the data returned froma data source (Field and Recordset) and three secondary objects
(Parameters, Properties, and Errors) for managing information about ADO.
ADO provides a quick, easy way to access data from a variety of development
environments.
Command Object
It defines a specific command to execute against a data source. The Command
object represents a SQL statement or stored procedure that software executes
against the data source. Use of Command objects is optional -- data can beextracted directly from a Connection object, if desired.
Connection Object
It represents an open connection to a data source. The Connection object sets
up a link between your program and the data source. This object contains all of
the necessary configuration information and acts as a gateway for all of the
other ADO objects. The Connection object is mandatory -- all implementations of
ADO must support it.
Recordset Object
-
7/30/2019 VB-103-110
6/7
It represents the entire set of records from a database table or the results of an
executed command. Each command execution results in a Recordset containing
the results of the query. This object is a mandatory part of ADO.
Field Object
It represents a column of data with a common data type. Each Recordset object
is composed of a number ofField objects that represent individual columns in
the Recordset. This object is a mandatory feature of ADO.
Parameter Object
It represents a parameter or argument associated with a Command object
based on a parameterized query or stored procedure.Command objects may
have an associated collection ofParameter objects that provide additional
information to the data source when executing the command. The Parameter
collection is optional.
Error Object
It provides specific details about each ADO error. The Error object represents an
error encountered by the ADO objects, especially on the data provider.
Property Object
It represents a dynamic characteristic of an ADO object that is defined by the
provider. This object is not currently supported on UNIX.
Q109. Explain if-then-else statement.
To effectively control the VB program flow, we shall use If...Then...Else statement
together with the conditional operators and logical operators.
The general format for the if...then...else statement is
If conditions ThenVB expressionsElse
VB expressionsEnd If
* any If..Then..Else statement must end with End If. Sometime it is not necessary
to use Else.
Example:
Private Sub OK_Click()
firstnum=Val(usernum1.Text
secondnum=Val(usernum2.Text)
If total=firstnum+secondnum And Val(sum.Text)0 Then
-
7/30/2019 VB-103-110
7/7
correct.Visible = True
wrong.Visible = False
Else
correct.Visible = False
wrong.Visible = True
End IfEnd Sub
Q110. Explain looping statements in VB6.
Do Loop
a) Do While condition
Block of one or more VB statements
Loop
b) Do
Block of one or more VB statements
Loop While condition
c) Do Until condition
Block of one or more VB statements
Loop
d) Do
Block of one or more VB statements
Loop Until condition
e) For....Next Loop
The format is:
For counter=startNumber to endNumber (Step increment)
One or more VB statements
Next