Upload
deswal2020
View
218
Download
0
Embed Size (px)
Citation preview
8/12/2019 Windows 8 lesson 21-37
1/72
Lesson 21: Creating Multimedia Applications-Part III
In lesson 19, we have created an audio player. Now, by making further modifications, you can transform thaudio player into a picture viewer. This viewer will be created in such a way that it could search for all types
graphics files in your drives and displays them in a picture frame.
Similar to the previous proect, in this proect, you need to insert a ComboBox, a DriveListBox, a
DirListBox, a extBoxand a !ileListBoxinto your form. I Shall briefly e!plain again the function of eachthe above controls.
"ombo#o!$ to display and enable selection of different type of files.
%rive&ist#o!$ to allow selection selection of different drives available on your '".
%ir&ist#o! $ To display directories
Te!t#o! $ To display selected files
(ile&ist#o!$ To display files that are available
)elevant codes must be written to coordinate all the above controls so that the application can work proper
The program should flow in the following logical way*
Step 1* +ser chooses the type of files he wants to play.
Step*+ser selects the drive that might contains the relevant graphic files.
Step -*+ser looks into directories and subdirectories for the files specified in step1. The files should be
displayed in the (ile&ist#o!.
Step * +ser selects the files from the (ile&ist#o! and click the Show button.
Step /* +ser clicks on 0!it button to end the application.
"e Code
'rivate Sub (orm&oad23
4To center the player
&eft 5 2Screen.6idth $ 6idth3 7 Top 5 2Screen.8eight $ 8eight37
"ombo1.Te!t 5 :ll graphic files
"ombo1.:ddItem :ll graphic files"ombo1.:ddItem :ll files
0nd Sub
'rivate Sub (ile1"lick23
If "ombo1.&istInde! 5 ; Then(ile1.'attern 5 2? 7 Thenfilenam 5 (ile1.'ath @ 7 @ (ile1.(ileName
0lsefilenam 5 (ile1.'ath @ (ile1.(ileName
0nd IfTe!t1.Te!t 5 filenam
8/12/2019 Windows 8 lesson 21-37
2/72
'rivate Sub "ombo1"hange23
If &istInde! 5 ; Then(ile1.'attern 5 2? 7 Then
filenam 5 (ile1.'ath @ 7 @ (ile1.(ileName0lse
filenam 5 (ile1.'ath @ (ile1.(ileName
0nd If
4To load the picture into the picture bo!picture1.'icture 5 &oad'icture2filenam3
0nd Sub
>>8ome ??< Next Lesson>
Lesson 22: Creating Multimedia Applications-Part I#
A Multimedia Pla$er
n lesson 1A, we have created an audio player. Now, by making more modifications, you can transform the aud
ayer into a multimedia player. This player will be able to search for all types of movie files and audio files. yourives and play them.
n this proect, you need to insert a ComboBox, a DriveListBox, a DirListBox, a extBox,a !ileListBox a
icture box2for playing movie3 into your form. I Shall briefly discuss the function of each of the above contro
esides, you must also insert Microso%t Multimedia Control&MMControl3 into your form , you may make itsible or invisible. In my program, I choose to make it invisible so that I could use the command buttons creat
ontrol the player.
"ombo#o!$ to display and enable selection of different type of files.
http://www.vbtutor.net/lesson20.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson22.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson22.htmlhttp://www.vbtutor.net/lesson20.html8/12/2019 Windows 8 lesson 21-37
3/72
%rive&ist#o!$ to allow selection selection of different drives available on your '".
%ir&ist#o! $ To display directories
Te!t#o! $ To display selected files
(ile&ist#o!$ To display files that are available
elevant codes must be written to coordinate all the above controls so that the application can work properly. T
rogram should flow in the following logical way*
tep 1* +ser chooses the type of files he wants to play.
tep*+ser selects the drive that might contains the relevant audio files.
tep -*+ser looks into directories and subdirectories for the files specified in step1. The files should be displaye
he !ileListBox.
tep * +ser selects the files from the !ileListBoxand clicks the Pla$button.
tep /* +ser clicks on the 'topbutton to stop playing and 0!it button to end the application.
8/12/2019 Windows 8 lesson 21-37
4/72
"e Code
rivate Sub (orm&oad23
eft 5 2Screen.6idth $ 6idth3 7
op 5 2Screen.8eight $ 8eight3 7
ombo1.Te!t 5
8/12/2019 Windows 8 lesson 21-37
5/72
rivate Sub "ombo1"hange23
&istInde! 5 ; Then
le1.'attern 5 2>8ome ??< Next Lesson>
Lesson 2(: Creating database applications in #B-Part
Disual basic allows us to manage databases created with different database programs such as BS :ccess,
%base, 'arado! and etc. In this lesson, we are not dealing with how to create database files but we will see
how we can access database files in the D# environment.
In the following e!ample, we will create a simple database application which enable one to browse custome
names. To create this application, insert the data control into the new form. 'lace the data control
http://www.vbtutor.net/lesson21.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson23.htmlhttp://www.vbtutor.net/lesson21.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson23.html8/12/2019 Windows 8 lesson 21-37
6/72
somewhere at the bottom of the form. Name the data control as datanavigator. To be able to use the data
control, we need to connect it to any database. 6e can create a database file using any database applicatio
but I suggest we use the database files that come with D#A. &et select N6IN%.B%# as our database file. T
connect the data control to this database, double$click the %atabaseName property in the properties windo
and select the above file, i.e N6IN%.B%#. Ne!t, double$click on the )ecordSource property to select the
customers table from the database. Eou can also change the caption of the data control to anything but I u
"lick to browse "ustomers here. :fter that, we will place a label and change its caption to "ustomer Nam
&ast but not least, insert another label and name it as cusname and leave the label empty as customers4
names will appear here when we click the arrows on the data control. 6e need to bind this label to the dat
control for the application to work. To do this, open the label4s %ataSource and select datanavigator that w
appear automatically. Cne more thing that we need to do is to bind the label to the correct field so that dat
this field will appear on this label. To do this, open the %ata(ield property and select "ontactName. Now, p
(/ and run the program. Eou should be able to browse all the customers4 names by clicking the arrows on t
data control.
"e )untime Inter%ace Eou can also add other fields using e!actly the same
method. (or e!ample, you can add adress, "ity andtelephone number to the database browser.
8/12/2019 Windows 8 lesson 21-37
7/72
>>8ome ??< Next Lesson>
Lesson 2*: Creating database applications in #B-Par
II
In &esson 19, you have learned how to create a simple database application using data control. In this less
you will work on the same application but use some slightly more advance commands. The data control
support some methods that are useful in manipulating the database, for e!ample, to move the pointer to acertain location. The following are some of the commands that you can use to move the pointer around*
data+navigator,)ecord'et,Move!irst 4 Bove to the first record
data+navigator,)ecord'et,MoveLast 4 Bove to the last record
data+navigator,)ecord'et,Moveext 4 Bove to the ne!t record
data+navigator,)ecord'et,Previous 4 Bove to the first record
Eou can also add, save and delete records using the following commands*
data+navigator,)ecord'et,Adde. 4 :dds a new record
data+navigator,)ecord'et,/pdate 4 +pdates and saves the new record
data+navigator,)ecord'et,Delete 4 %eletes a current record
8/12/2019 Windows 8 lesson 21-37
8/72
'rivate Sub "ommand"lick23
dta#ooks.)ecordset.Bove&ast0nd Sub)un the application and you shall obtain the interface below and you will be able to browse the database usthe four command buttons.
>>8ome ??< Next Lesson>
Lesson 20: Creating #B database applications usingAD control
In &esson and &esson -, we have learned how to build D# database applications using data control.
8owever, data control is not a very fle!ible tool as it could only work with limited kinds of data and must
work strictly in the Disual #asic environment. To overcome these limitations, we can use a much more
powerful data control in Disual #asic, known as :%C control. :%C stands for :ctiveF data obects. :s :%C:ctiveF$based, it can work in different platforms 2different computer systems3 and different programming
languages. #esides, it can access many different kinds of data such as data displayed in the Internet
browsers, email te!t and even graphics other than the usual relational and non relational database
information.
http://www.vbtutor.net/lesson23.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson25.htmlhttp://www.vbtutor.net/lesson23.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson25.html8/12/2019 Windows 8 lesson 21-37
9/72
To be able to use :%C data control, you need to insert it into the toolbo!. To do this, simply press "trl@T to
open the components dialog bo! and select Bicrosoft :ctiveF %ata "ontrol A. :fter this, you can proceed to
build your :%C$based D# database applications.
The following e!ample will illustrate how to build a relatively powerful database application using :%C data
control. (irst of all, name the new form as %rmBooitleand change its caption to Boo itles- AD
Application. Secondly, insert the :%C data control and name it as adoBoos and change its caption to
boo. Ne!t, insert the necessary labels, te!t bo!es and command buttons. The runtime interface of this
program is shown in the diagram below, it allows adding and deletion as well as updating and browsing of
data.
The properties of all the controls are listed as follow*
(orm Name frm#ookTitle
(orm "aption #ook Titles $:%C:pplication
:%C Name ado#ooks
&abel1 Name lbl:pp
&abel1 "aption #ook Titles
&abel Name lblTitle
&abel "aption Title *
&abel- Name lblEear&abel- "aption Eear 'ublished*
&abel Name lblIS#N
&abel "aption IS#N*
&abe/ Name lbl'ubI%
&abel/ "aption 'ublisher4s I%*
&abelA Name lblSubect
8/12/2019 Windows 8 lesson 21-37
10/72
&abelA "aption Subect *
Te!t#o!1 Name t!title
Te!t#o!1 %ata(ield Title
Te!t#o!1 %ataSource ado#ooks
Te!t#o! Name t!t'ub
Te!t#o! %ata(ield Eear 'ublished
Te!t#o! %ataSource ado#ooks
Te!t#o!- Name t!tIS#N
Te!t#o!- %ata(ield IS#N
Te!t#o!- %ataSource ado#ooks
Te!t#o! Name t!t'ubI%
Te!t#o! %ata(ield 'ubI%
Te!t#o! %ataSource ado#ooks
Te!t#o!/ Name t!tSubect
Te!t#o!/ %ata(ield Subect
Te!t#o!/ %ataSource ado#ooks
"ommand #utton1 Name cmdSave
"ommand #utton1 "aption GSave
"ommand #utton Name cmd:dd
"ommand #utton "aption G:dd
"ommand #utton- Name cmd%elete
"ommand #utton- "aption G%elete
"ommand #utton Name cmd"ancel
"ommand #utton "aption G"ancel
"ommand #utton/ Name cmd'rev
"ommand #utton/ "aption G>
"ommand #uttonA Name cmdNe!t
"ommand #uttonA "aption G?
"ommand #uttonH Name cmd0!it
"ommand #uttonH "aption 0G!it
To be able to access and manage a database, you need to connect the :%C data control to a database file.
are going to use BIBLI,MDBthat comes with D#A. To connect :%C to this database file , follow the step
below*
a3 "lick on the :%C control on the form and open up the properties window.
b3 "lick on the "onnectionString property, the following dialog bo! will appear.
8/12/2019 Windows 8 lesson 21-37
11/72
when the dialog bo! appear, select the +se Connection 'tring4s Cption. Ne!t, click build and at the Data
Lin dialog box, double$"lick the option labeled Microso%t 3et (,01 L4 DB provider,
:fter that, click the Ne!t button to select the file BIBL,MDB,Eou can click on Te!t "onnection to ensure
proper connection of the database file. "lick C to finish the connection.
8/12/2019 Windows 8 lesson 21-37
12/72
(inally, click on the )ecordSource property and set the command t$peto adCmd ableand able name
itles. Now you are ready to use the database file.
Now, you need to write code for all the command buttons. :fter which, you can make the :%C control
invisible.
(or the 'ave button, the program codes are as follow*
'rivate Sub cmdSave"lick23
ado#ooks.)ecordset.(ields2Title3 5 t!tTitle.Te!t
ado#ooks.)ecordset.(ields2Eear 'ublished3 5 t!t'ub.Te!t
ado#ooks.)ecordset.(ields2IS#N3 5 t!tIS#N.Te!t
ado#ooks.)ecordset.(ields2'ubI%3 5 t!t'ubI%.Te!t
ado#ooks.)ecordset.(ields2Subect3 5 t!tSubect.Te!t
ado#ooks.)ecordset.+pdate
0nd Sub
(or the Add button, the program codes are as follow*
'rivate Sub cmd:dd"lick23
8/12/2019 Windows 8 lesson 21-37
13/72
8/12/2019 Windows 8 lesson 21-37
14/72
(or the Ne!t2?3 button, the program codes are
'rivate Sub cmdNe!t"lick23
If Not ado#ooks.)ecordset.0C( Then
ado#ooks.)ecordset.BoveNe!t
If ado#ooks.)ecordset.0C( Then
ado#ooks.)ecordset.Bove'revious
0nd If
0nd If
0nd Sub
"lick here to view a related sample program
>>8ome ?? < Next Lesson>
In this sample, you will create a ADO database application to manage your home library. First of all, create a
database in MS Access and name home_ibrary. In this database, create a table with the following field names!
"itle#
Author#
$ublisher#
%ear#
&ategory#
and sa'e the table as boo(title.mdb
Design the Interface as follow#
http://www.vbtutor.net/L21_sample.htmhttp://www.vbtutor.net/lesson24.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson26.htmlhttp://www.vbtutor.net/L21_sample.htmhttp://www.vbtutor.net/lesson24.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson26.html8/12/2019 Windows 8 lesson 21-37
15/72
)ey in the codes as follows#
$ri'ate Sub cmd&ancel_&lic(*+
tt"itle."et - ttAuthor."et -
tt$ublisher."et -
tt%ear."et -
tt&ategory."et - /nd Sub
$ri'ate Sub cmdDelete_&lic(*+
&onfirm - Msg0o*Are you sure you want to delete this record1, 'b%es2o, Deletion &onfirmation+If &onfirm - 'b%es "hen
adoibrary.3ecordset.DeleteMsg0o 3ecord Deleted4, , Message
/lse
Msg0o 3ecord 2ot Deleted4, , Message
/nd If
/nd Sub
$ri'ate Sub cmd/it_&lic(*+/nd/nd Sub
$ri'ate Sub cmd2ew_&lic(*+adoibrary.3ecordset.Add2ew
/nd Sub
8/12/2019 Windows 8 lesson 21-37
16/72
$ri'ate Sub cmd2et_&lic(*+
If 2ot adoibrary.3ecordset./OF "henadoibrary.3ecordset.Mo'e2et
If adoibrary.3ecordset./OF "hen
adoibrary.3ecordset.Mo'e$re'ious/nd If
/nd If
/nd Sub
$ri'ate Sub cmd$re'ious_&lic(*+
If 2ot adoibrary.3ecordset.0OF "henadoibrary.3ecordset.Mo'e$re'ious
If adoibrary.3ecordset.0OF "hen
adoibrary.3ecordset.Mo'e2et
/nd If/nd If
/nd Sub
$ri'ate Sub cmdSa'e_&lic(*+
adoibrary.3ecordset.Fields*"itle+ - tt"itle."et
adoibrary.3ecordset.Fields*Author+ - ttAuthor."etadoibrary.3ecordset.5pdate
/nd Sub60ac( to lesson 789
Lesson 25: /sing Microso%t Data6rid Control 5,7
In the previous chapter, we use te!tbo!es to display data by connecting them to a database via Bicrosoft :
data "ontrol A.;. The te!tbo! is not the only control that can display data from a database, many other
controls in Disual #asic can display data. Cne of the them is the %ataLrid control. %ataLrid control can be
used to display the entire table of a recordset of a database. It allows users to view and edit the data.
%ataLrid control is the not the default item in the Disual #asic control toolbo!, you have add it from the D#
components. To add the %ataLrid control, click on the proect in the menu bar and select components whe
dialog bo! that displays all the available D#A components. Select Bicrosoft %ataLrid "ontrol A.; by clicking
the checkbo! beside this item. #efore you e!it the dialog bo!, you also need to select the Bicrosoft :%C da
control so that you are able to access the database. &astly, click on the C button to e!it the dialog bo!. N
you should be able to see that the %ataLrid control and the :%C data control are added to the toolbo!. Th
ne!t step is to drag the %ataLrid control and the :%C data control into the form.
The components dialog bo! is shown below*
http://www.vbtutor.net/lesson21.htmlhttp://www.vbtutor.net/lesson21.html8/12/2019 Windows 8 lesson 21-37
17/72
8/12/2019 Windows 8 lesson 21-37
18/72
#efore you proceed , you need to create a database file using Bicrosoft :ccess. 8ere I created a file to stor
my the information of my books and I name the table book. :fter you have created the table, enter a few
records such as mine. The table is shown below*
8/12/2019 Windows 8 lesson 21-37
19/72
Now you need to connect the database to the :%C data control. To do that, right click on the :%C data
control and select the :%C%" properties, the following dialog bo! will appear.
Ne!t click on the #uild button and the %ata &ink 'roperties dialog bo! will appear 2as shown below3. In this
dialog bo!, select the database file you have created, in my case, the file name is books.mdb. 'ress test
connection to see whether the connection is successful. If the connection is successful, click C to return to
the :%C%" property pages dialog bo!. :t the :%C%" property pages dialog bo!, click on the )ecordsource
tab and select $ad"mdTable under command type and select book as the table name, then click C.
8/12/2019 Windows 8 lesson 21-37
20/72
(inally you need to display the data in the %ataLrid control. To accomplish this, go to the properties window
and set the %ataSource property of the %ataLrid to :dodc1. Eou can also permit the user to add and edit y
records by setting the :llow+pdate property to True. If you set this property to false, the user cannot edit trecords. Now run the program and the output window is shown below*
8/12/2019 Windows 8 lesson 21-37
21/72
>>8ome ??< Next Lesson>
Lesson 28: /sing '9L ueries in #isual Basic 5
In the previous chapter, we have learned to use %ataLrid "ontrol to display data from a database in Disual
#asic A environment. 8owever, it does not allow users to search for and select the information they want t
see. In order to search for certain information, we need to use SM& uery. SM& stands for Structures Muery&anguage. +sing SM& keywords, we are able to select specific information to be displayed based on certain
criteria. The most basic SM& keyword is S0&0"T, it is used together with the keyword ()CB to select
information from one or more tables from a database. The synta! is*
'4L4C %ieldname1;%ieldname2;,,,,,;%ieldname !)M ableame
fieldname1, fieldname,......fieldnameN are headings of the columns from a table of a database. Eou can
select any number of fieldname in the uery. If you wish to select all the information, you can use the
following synta!*
'4L4C < !)M ableame
In order to illustrate the usage of SM& ueries, lets create a new database in Bicrosoft :ccess with the
following filenames ID; itle; Aut"or; =ear; I'B; Publis"er; Price and save the table as booand the
database as boos,mdbin a designated folder.
http://www.vbtutor.net/lesson25.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson27.htmlhttp://www.vbtutor.net/lesson25.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson27.html8/12/2019 Windows 8 lesson 21-37
22/72
Ne!t, we will start Disual #asic and insert an :%C control, a %ataLrid and three command buttons. Name t
three command buttons as cmdAut"or;cmditle andcmdAll. "hange their captions to Displa$
Aut"or,Displa$ Boo itleand Displa$ Allrespectively. Eou can also change the caption of the form to
#ooks.The design interface is shown below*
Now you need to connect the database to the :%C data control. 'lease refer to lesson 12b3 for the detail
8owever, you need to make one change. :t the :%C%" property pages dialog bo!, click on the )ecordsour
tab and select 1-adCmdext under command type and under "ommand Te!t2SM&3 key in '4L4C < !)
boo,
http://www.vbtutor.net/lesson21(b).htmlhttp://www.vbtutor.net/lesson21(b).html8/12/2019 Windows 8 lesson 21-37
23/72
Ne!t, click on the command buttton cmd:uthor and key in the following statements*
'rivate Sub cmd:uthor"lick23
:dodc1.)ecordSource 5 S0&0"T :uthor ()CB book
:dodc1.)efresh
:dodc1."aption 5 :dodc1.)ecordSource
0nd Sub
and for the command button cmdTitle, key in
'rivate Sub cmdTitle"lick23
:dodc1.)ecordSource 5 S0&0"T Title ()CB book
:dodc1.)efresh
:dodc1."aption 5 :dodc1.)ecordSource
0nd Sub
(inally for the command button cmd:ll, key in
'rivate Sub cmd:ll"lick23
8/12/2019 Windows 8 lesson 21-37
24/72
:dodc1.)ecordSource 5 S0&0"T < ()CB book
:dodc1.)efresh
:dodc1."aption 5 :dodc1.)ecordSource
0nd Sub
Now, run the program and when you click on the %isplay :uthor button, only the names of authors will be
displayed, as shown below*
and when you click on the %isplay #ook Title button, ony the book titles will be displayed, as show below*
8/12/2019 Windows 8 lesson 21-37
25/72
&astly, click on the %isplay :ll button and all the information will be displayed.
>>8ome ??< Next Lesson>
http://www.vbtutor.net/lesson26.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson28.htmlhttp://www.vbtutor.net/lesson26.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson28.html8/12/2019 Windows 8 lesson 21-37
26/72
Lesson 2>: More '9L ?e$.ords
In the previous chapter, we have learned to use the basic SM& keywords S0&0"T and ()CB to
manipulate database in Disual #asic A environment. In this lesson, you will learn to use more SM& keyword
Cne of the more important SM& keywords is 680)0. This keyword allow the user to search for data that fu
certain criteria. The Synta! is as follows*
'4L4C %ieldname1;%ieldname2;,,,,,;%ieldname !)M ableame
@4)4 Criteria
The criteria can be specified using operators such as 5, ?,>, >5, ?5, >? and &ike.
+sing the database books.mdb created in the previous chapter, we will show you a few e!amples. (irst of a
start a new proect and insert a %ataLrid control and an :%C control into the form. . :t the :%C%" proper
pages dialog bo!, click on the )ecordsource tab and select 1-adCmdext under command type and unde
"ommand Te!t2SM&3 key in '4L4C < !)M boo, Ne!t, insert one te!tbo! and put it on top of the
%ataLrid control, this will be the place where the user can enter SM& uery te!t. Insert one command butt
and change the caption to Muery. The design interface is shown below*
4xample 21d1: 9uer$ based on Aut"or
)un the program and key in the following SM& uery
statement
S0&0"T Title, :uthor ()CB book 680)0
:uthor54&iew Doon iong4
4xample 21d2:9uer$ based on $ear
)un the program and key in the following SM& uery
statement*
S0&0"T < ()CB book 680)0 Eear?;;/
8/12/2019 Windows 8 lesson 21-37
27/72
6here you click on the uery button, the %ataLrid
will display the author name &iew Doon iong. asshown below*
6here you click on the uery button, the %ataLrid wi
display all the books that were published after the yea;;/.
Eou can also try following ueries*
S0&0"T < ()CB book 680)0 'rice>5O; S0&0"T < ()CB book 680)0 Eear5;;O
S0&0"T < ()CB book 680)0 :uthor>?4&iew Doon iong4
Eou may also search for data that contain certain characters by pattern matching. It involves using the Li
operator and the symbol. (or e!ample, if you want to search for a author name that begins with alphab
P, you can use the following uery statement
S0&0"T < ()CB book 680)0 :uthor &ike 4PQ4
6here you click on the uery command button, the records where authors4 name start with the alphabet P
be displayed, as shown below*
8/12/2019 Windows 8 lesson 21-37
28/72
Ne!t, if you wish to rank order the data, either in ascending or descending order, you can use the )D4)
B$ ; A'C &%or ascending and D4'C&DescendingSM& keywords.
The general formats are
'4L4C %ieldname1; %ieldname2,,,,,!)M table )D4) B= %ieldname A'C
'4L4C %ieldname1; %ieldname2,,,,,!)M table )D4) B= %ieldname D4'C
4xample 21d(:
The following uery statement will rank the recordsaccording to :uthor in ascending order.
S0&0"T Title, :uthor ()CB bookC)%0) #E :uthor :S"
4xample 21d*
The following uery statement will rank the recordaccording to price in descending order.
S0&0"T Title, 'rice ()CB book C)%0) #E 'rice%0S"
8/12/2019 Windows 8 lesson 21-37
29/72
>>8ome ??< Next Lesson>
Lesson 2: Creating Advanced #B database applicatio
using AD control
In previous lessons, you have learned how to design database applications using data control and :%C
control. 8owever, those applications are very simple and plain . In this lesson, you will learn how to create more advanced database application using :%C control. The application you are going to create is known a
an electronic library. This electronic library will be able to accept the user registration as well as handlinglogin command that reuire the user4s password, thus enhancing the security aspect of the database.
#asically, the application will constitute a welcome menu, a registration menu, a &ogin menu and the maindatabase menu. The seuence of the menus are illustrated as follow*
http://www.vbtutor.net/lesson27.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson29.htmlhttp://www.vbtutor.net/lesson27.htmlhttp://www.vbtutor.net/vb.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson29.html8/12/2019 Windows 8 lesson 21-37
30/72
2,1 "e @elcome Menu
(irst of all, you need to design the 6elcome menu. Eou can follow the e!ample as follow*
In this form, you need to insert three command buttons and set their properties as follow*
(orm name mainmenu
command button 1 Name cmd)egister
command button 1 "aption )egister
command button Name cmd&ogin
command button "aption &ogin
command button - Name cmd"ancel
command button - "aption "ancel
8/12/2019 Windows 8 lesson 21-37
31/72
The code is as follows*
'rivate Sub cmd"ancel"lick23
0nd
0nd Sub
'rivate Sub cmd&ogin"lick23
mainmenu.8ide
&oginform.Show
0nd Sub
'rivate Sub cmd)egister"lick23
mainmenu.8ide
)egister.Show
0nd Sub
2,2 "e )egistration !orm
If a new user click the )egister button, the registration form will appear. :n e!ample is illustrated as follow
This registration forms consist of two te!t bo!es , three command buttons and an :%C control. Their
properties are set as follow*
(orm name )egister
te!tbo! 1 name t!tName
te!tbo! name t!tpassword
8/12/2019 Windows 8 lesson 21-37
32/72
te!tbo! 'assword"har >8ome ??>Ne!t &esson?
Lesson (5: Compiling and Distributing =our
Programs
(5,1 Compiling $our #isual Basic Program
Once your ha'e completed a :0 program, you can compile the program to run as a standalone windows applicat
without ha'ing to launch the :isual 0asic ID/.
8/12/2019 Windows 8 lesson 21-37
61/72
compile. (or e!ample, you can enter the title of the program , the program4s version and your company
name. "licking on the compile tab will let you decide the kind of code you wish to compile. The default opt
is native code and it is the best option because it normally runs faster. It reuires fewer files to run, particu
the D# %&& files. Cnce you have done that, you can click the C button to compile the program. Now you
program can run as a standalone application. Eou can start your program without launching the Disual #as
I%0.
!igure (5,1 !igure (5,2
!igure (5,( !igure (5,*
8/12/2019 Windows 8 lesson 21-37
62/72
(5,2 Distributing =ourPrograms
:fter successfully created a D# program, you might
want to market your product, either online oroffline. This means that you need to create a
package that can be distributed to your potential
customers. The package created can be distributedusing "% )CB, diskette or the Internet. The
package will allow the user to install the programto install in the computer with the standard setup
routine.
To create the distributable package, you can usethe 'ackage and %evelopment 6iard that camewith Disual #asic A. The main purpose of this
wiard is to create a setup program that can beused to install the application. Cff course, it also
does many other obs like compiling yourapplication and compresses the files for easy
8/12/2019 Windows 8 lesson 21-37
63/72
distribution.
6hen you start the 'ackage and %evelopment
6iard, you will be presented with the followingdialog bo!*
(irst of all, you need to select the proect you want
to package. 8ere I have selected the starwar.vbpproect. Ne!t, you need to select one of the three
options. 8ere, I suggest you select the first optionto let the wiard create the installation package
for you to distribute it using "% )CB or theInternet.
Cnce you click the package option, you will see thefollowing dialog bo! where you are asked to choose
a packaging script*
:fter you click ne!t, you will see the following dialog bo
where you will be asked to choose a packaging type.Normally we choose the Standard Setup 'ackage.
The ne!t dialog bo! that shows up will ask you where to
store the package, as shown below*
The ne!t dialog bo! will show you the files that will beincluded in the package.
6hen you click the (inish button, the package will becreated and ready for distribution. 8ere is the packaged
files for the starwar program for download at
Setup.e!e
S0T+'.&ST
starwar/.":#
Eou must download all the three files into a folder andthen run the setup program.
http://www.vbtutor.net/StarWar/setup.exehttp://www.vbtutor.net/StarWar/SETUP.LSThttp://www.vbtutor.net/StarWar/starwar5.CABhttp://www.vbtutor.net/StarWar/setup.exehttp://www.vbtutor.net/StarWar/SETUP.LSThttp://www.vbtutor.net/StarWar/starwar5.CAB8/12/2019 Windows 8 lesson 21-37
64/72
.....continue on the right
>'revious &esson?>>8ome?? >>Ne! &esson??
Lesson (8: Creating Menus %or =our Applications
Benu bar is the standard feature of most windows applications. The main purpose of the menus is for easy
navigation and control of an application. Some of the most common menu items are (ile, 0dit, Diew, Tools
8elp and more. 0ach item on the main menu bar also provide a list of options or in the form of a pull$dow
menu. 6hen you create a Disual #asic A program, you need not include as many menu items as a full fledg
6indows application such as Bicrosoft 6ords. 6hat you need is to include those menu items that can impr
the ease of using your program by the user, and not to confuse the user with unnecessary items. :dding m
bar is relatively easy to accomplish in Disual #asic. There are two ways to add menus to your application,
way is to use the Disual #asic4s :pplication 6iard and the other way is to use the menu editor.
(8,1 Adding Menu Bar /sing #isual BasicJs Application @iKard
The easiest way to add menu bar to your application is by using Disual #asic4s :pplication 6iard. This wia
allows the user to insert fully customied standard windows menus into his or her application. To start usin
Disual #asic4s :pplication 6iard, you click on the :pplication 6iard icon at the Disual #asic new proect
dialog bo!, as shown below*
http://www.vbtutor.net/lesson35.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson37.htmlhttp://www.vbtutor.net/lesson35.htmlhttp://www.vbtutor.net/vbtutor.htmlhttp://www.vbtutor.net/lesson37.html8/12/2019 Windows 8 lesson 21-37
65/72
!igure (8,1: e. Proect @indo.
6hen you click on the D# :pplication wiard, the introduction dialog bo! will appear, as shown in (igure -H
:s you are not loading any default setting, ust click on the Ne!t button. :fter clicking the Ne!t button, the
interface type dialog bo! will be displayed, as shown in (igure -H.-. There are three choices of interface fo
your proect, as we currently not creating a Bultiple %ocument Interface 2B%I3, we choose Single %ocumen
Interface 2S%I3. Eou can also type the proect name in the te!tbo! below, here I am using By(irstBenu. :f
clicking the Ne!t button, you will be presented with a list of menus and submenus that you would like to ad
them to your application. "heck to select a menu item and uncheck to unselect a menu item. &et say we
choose all the menus and click ne!t, then you will get an interface will (ile, 0dit, Diew and 8elp menus. suc
as that shown in (igure -H./
8/12/2019 Windows 8 lesson 21-37
66/72
!igure (8,2 !igure (8,(
8/12/2019 Windows 8 lesson 21-37
67/72
!igure (8,*
!igure (8,0
6hen you click on any menu item, a list of drop$downsubmenu items will be displayed. (or e!ample, if you click
on the (ile menu, the list of submenu items such as New,Cpen, Save, Save :s and more will be displayed, as shown
in (igure -H.A
The full code is as follows*
'rivate Sub mnu(ileCpen"lick23%im s(ile :s String
6ith dlg"ommon%ialog.%ialogTitle 5 Cpen
."ancel0rror 5 (alse4To%o* set the flags and attributes of the comm
dialog control.(ilter 5 #itmaps2
8/12/2019 Windows 8 lesson 21-37
68/72
!igure (8,5
"licking on any of the dropped down menu item will show
the code associated with it, and this is where you canmodify the code to suit your programming needs. (or
e!ample, clicking on the item Cpen will reveal the followingcode*
0nd 6ith
4To%o* add code to process the opened file
0nd Sub
6hen you run the program and click on the (imenu and then the submenu Cpen, the follow
Cpen dialog bo! will be displayed, where you clook for graphic files of various formats to load
into the image bo!.
!igure (8,>
(or e!ample, selecting the peg file will allow y
to choose the images of peg format.
8/12/2019 Windows 8 lesson 21-37
69/72
!igure (8,8
Now, I will show you how to modify the code in order toopen a graphic file and display it in an image bo!. (or this
program, you have to insert a Image bo! into the form.Ne!t add the following lines so that the user can open
graphic files of different formats.
.(ilter 5 #itmaps2
8/12/2019 Windows 8 lesson 21-37
70/72
8/12/2019 Windows 8 lesson 21-37
71/72
!igure (8,11
Eou can then add in other menu items on the menu bar by
following the same procedure, as shown in the diagrambelow*
Save, Save :s and 0!it.
!igure (8,1*
Now click the C button and go back to yourform. Eou can see the dropped down submenu
when you click on the item (ile, as shown.
!igure (8,10
(inally, you can enter the code by clicking on a
of the submenu items. Eou can enter code sucas that shown in section -H.1
8/12/2019 Windows 8 lesson 21-37
72/72