Pages

I am the Director, Department of Education Administration and Development at the National Institute of Education, Sri Lanka.
My main activities are development of school curricula, development of Educational Software and training of teachers on ICT for the Sri Lankan schools system. Content

Friday, December 14, 2007

Software Development - Programming in Visual Basic


I have written a book titled “Software Development - Programming in Visual Basic” in Sinhala.

• 91 Sample Visual Basic Programs
• Start from beginning level
• Guiding to be an expert in programming

Contents of the Book

ISBN : 978-955-50090-0-3
Published : 2007
Reprint : 2007

Publisher :

D. Anura Jayalal
7/3A,
Pirivena Road,
Mount Lavinia
Sri Lanka.

To order :

Telephone : (Land) 0094-011-3172800, (Mobile)0094-071-6418204
Email : dajayalal@yahoo.com


2 comments:

Anonymous said...

Dear Sir,

I bought Programming in Visual Basic Book written by you and now I am doing exercises of data bases. But I have a problem that I cannot find records by any field in it. If there a method of setting Find Record Button and cording it, please send me an e-mail mentioned how to write a code for find record button.

Yours,
A learner

D. Anura Jayalal said...

Dear Ajith

This is the answer for your question.

I am happy to hear that you are following my book of “Programming in Visual Basic”. I think you are asking how you can search a record in a database. The Program No. 87 in the book explains record searching. See the code in the button of Search Record and the code in the form of SearchRecord. It explains how can you change the SQL statement at runtime. In addition to that you can learn about SQL statements in the chapter 16 (pages 211 to 214 ).

There is another method to search a record. This method is not explained in the book because this is suitable only for a small database. Let us think you have a sample database named MyDB with a table of TB which have columns “Code” (Data Type = Text, Field Size=4) and “Name” (Data Type = Text, Field Size=30). Save the database in the folder of “D:\sample”. Add several records to the table as follows.

TB
Code Name
0001 Saman
0002 Nihala
0003 Raweendra
0004 Dissanayake

You have to create an data environment named DEName for the table of TB (see the page 187 of the book). There should be two text boxes named Text1 and Text2 and one button named SearchB in the form.

Then you can create a code for a search button and others as follows.

Private Sub Form_Load()
Text2.Locked = True
End Sub

Private Sub SearchB_Click()
Dim Found As Boolean
Dim MySQL As String
Dim ConStr As String
ConStr = "DSN=MS Access Database;DBQ=D:\sample\MyDB.mdb;DefaultDir=D:\sample;DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;UID=admin;"

MySQL = "SELECT * FROM TB"
If DEName.rsCM.State = 1 Then
DEName.rsCM.Close
End If
DEName.rsCM.Open MySQL, ConStr, adOpenDynamic, adLockOptimistic, adCmdText


Found = False
DEName.rsCM.MoveFirst
Do While (Not DEName.rsCM.EOF) And (Not Found)
Found = (DEName.rsCM.Fields("Code") = Trim(Text1))
If Not Found Then
DEName.rsCM.MoveNext
End If
Loop
If Found Then
Text2 = DEName.rsCM.Fields("Name")
Else
MsgBox ("No record found.")
End If
End Sub

Do not type contents in the line ConStr = " ... This connection string can be copied from the data environment (and it should be in the same line).