Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Wednesday, June 29, 2011

VB-26 : Create a database structure for a university



==================================================================================
Before going to do any Database Program ,Click here
 to  understand Database Concepts thoroughly.


That is , Creating Database within VB Platform


==================================================================================

(A) Creating a database :

(Refer 
Linking to Database)  
Creating a database using Access(97) and creating a table.

Steps For crating Database in Access : 
  1. Open Access, select Blank Database, then OK
  2. Give a name (say db1) , then click Create
  3. Select create table in Design View from the dialog window, and OK
  4. Now we will get a window showing three fields a s Field Name,Data Type and Description
  5. In that window, fill the information as 
    Field
    Data bType
    id
    Text
    Name
    Text


    DOB
    Date/Time
    Address
    Text
    Pin
    Number

  6. Right Click on id , then select Primary Kay from the drop down list ..to make the id field a primary key(Because id has to unique and non null value)
  7. Click on Close button
  8. Then a dialog box will appear telling you to give a table name for the created table(Give a name for the table,say, Student Master)
So.now what you get is a database named db1.mdb , with a table named Student Master with no records in it.
Now fill in the recorde in the table and close the window.
==============================================
(B) Providing a front end through VB to link with the DataBase :


Open VB three times.(Activate three instances in VB)
  1. Standard  EXE  (As we normally doing)
  2. ActiveX  DLL
  3. ActiveX  EXE
Note :
  • When the Save button in the form of Standard  EXE is pressed, all the details entered should be verified and then passed on to the ActiveX  DLL program.ActiveX  DLL program is one ,which will implement all the business rules in the project.
  • ActiveX DLL program is going to check all the business rules and then pass the data to ActiveX EXE program
  • ActiveX EXE program is one,which is going to access the database and write the data provided by the ActiveX DLL in the database.This process will be loaded on the server.
----------------------------------------------------------------
1 ) Standard EXE


Create a Standard EXE program,containing a form to accept the student details from the user.


Draw the form as 

Insert 5 Labels, 5 TextBoxes, and one Command Button.



Change the captions of the components a s follows : Label1 to Student ID,

 , Label2 to Name, Label3 to DOB , Label4 to Address, Label5 to Pin . And delete the captions of all the TextBoxes, and change the caption of Command Button to Save as shown above:  


Name the project as ClientEnd and form as StudentEntryForm . This project will be loaded in the client machine.

----------------------------------------------------------------
2 ) ActiveX DLL


Now,again invoke the second instances of VB and choose ActiveX DLL as the project type.
We can see that there is a class module present by default.Click on the name property of the  class module and type studentclass in the place of class1. In the same way,again click on the project window and rename the project to Businessrules.


Tools--> Add Procedure :

  1. Now include some properties into the class studentclass , by clicking the Tools--> add procedure option.
  2. Select type as property , and scope as public.
  3. In the place of name, type studid , then press OK.

Now , we will get a code window as : 

Public Property Get Studid() As Variant
End Property

Public Property Let Studid(ByVal vNewValue As Variant)
End Property
Repeat the above given 3 steps, for all the fields in the table studentmaster . That is , for studid,Name,DOB,Address,and Pin.
And, you will get the following code in the code window.
Code NO : 1


Public Property Get Studid() As Variant
End Property

Public Property Let Studid(ByVal vNewValue As Variant)
End Property

Public Property Get studname() As Variant
End Property

Public Property Let studname (ByVal vNewValue As Variant)
End Property

Public Property Get studdob() As Variant
End Property

Public Property Let studdob (ByVal vNewValue As Variant)
End Property

Public Property Get studadd() As Variant
End Property

Public Property Let studadd (ByVal vNewValue As Variant)
End Property

Public Property Get studpin() As Variant
End Property

Public Property Let studpin (ByVal vNewValue As Variant)
End Property

Now create five private data members(variables) for the class as shown below :
Code NO : 2

Private sid As String
Private sname As String
Private sdob As Date
Private sadd As String
Private spin As Integer
Now,insert the code in the property procedure as shown below :
Code NO : 3

Public Property Get studid() As String
studid = sid
End Property

Public Property Let studid(ByVal vNewValue As String)
sid = vNewValue
End Property
Public Property Get studname() As String
studname = sname
End Property

Public Property Let studname(ByVal vNewValue As String)
sname = vNewValue
End Property
Public Property Get studadd() As String
studadd = sadd
End Property

Public Property Let studadd(ByVal vNewValue As String)
sadd = vNewValue
End Property
Public Property Get studpin() As String
studpin = spin
End Property

Public Property Let studpin(ByVal vNewValue As String)
spin = vNewValue
End Property
Public Property Get studdob() As String
studdob = sdob
End Property

Public Property Let studdob(ByVal vNewValue As String)
sdob = vNewValue
End Property

----------------------------------------------------------------
3 ) ActiveX EXX
Now,again invoke third instance of VB and choose ActiveX EXE as the project type.
You can see that , again there is a default class module with class1 as default class in it. Change the name of the project to backend and class to backendclass .


Create private data members(variables) for backend class by writing the following code in the code window of the class backendclass.
Code NO : 1

Private bsid As String
Private bsname As String
Private bsdob As Date
Private bsadd As String
Private bspin As Integer

Enter the following code to add the procedures in the class backendclass.
Code NO : 2

Private Sub class_initialize()
set db=open database("Give path of db1.mdb")
End Sub

Public Property Get stid() As String
stid = bsid
End Property

Public Property Let stid(ByVal vNewValue As String)
bsid = vNewValue
End Property
Public Property Get stname() As String
stname = bsname
End Property

Public Property Let stname(ByVal vNewValue As String)
bsname = vNewValue
End Property
Public Property Get stadd() As String
stadd = bsadd
End Property

Public Property Let stadd(ByVal vNewValue As String)
bsadd = vNewValue
End Property
Public Property Get stpin() As Integer
stpin = bspin
End Property

Public Property Let stpin(ByVal vNewValue As String)
bspin = vNewValue
End Property
Public Property Get studdob() As Date
stdob = bsdob
End Property

Public Property Let stdob(ByVal vNewValue As Date)
bsdob = vNewValue
End Property

Enter the following commands in the class declaration to establish a connection with the database.
Code NO : 3

Dim db as Database
Dim rs as Recordset
Private Sub class_initialize()
set db=open database("Give path of db1.mdb")
End Sub

================================================
(Not complete......)
Back to Home   &  VB

Tuesday, June 28, 2011

VB-25 : Linking to Database

How to create database & tables ??  SQL-create Database & Table

==================================================================================
Before going to do any Database Program ,Click here
 to  understand Database Concepts thoroughly.


That is , Creating Database within VB Platform


==================================================================================


(A) Creating a database :


Creating a database using Access(97) and creating a table.

Steps For crating Database in Access : 
  1. Open Access, select Blank Database, then OK
  2. Give a name (say db1) , then click Create
  3. Select create table in Design View from the dialog window, and OK
  4. Now we will get a window showing three fields a s Field Name,Data Type and Description
  5. In that window, fill the information as 
    Field
    Data Type
    Width
    Roll Number
    Text
    5
    Name
    Text
    50
    Age
    Numeric
    2
    Sex
    Text
    1
  6. Right Click on Roll Number , then select Primary Kay from the drop down list ..to make the Roll Number field a primary key(Because roll number has to unique and non null value)
  7. Click on Close button
  8. Then a dialog box will appear telling you to give a table name for the created table(Give a name for the table,say, Student Master)
So.now what you get is a database named db1.mdb , with a table named Student Master with no records in it.
Now fill in the recorde in the table and close the window.
==============================================
(B) Providing a front end through VB to link with the DataBase :
Open VB
  1. Insert 4 Labels, 4 TextBoxes, and one DataControl . 
  2. Change the captions of the components a s follows : Label1 to RollNo , Label2 to Name, Label3 to Age , Label4 to Sex. And delete the captions of all the TextBoxes, and change the caption of data control to Student Master File as shown above :      
  3. From the databasename property ,choose the path where you saved the database file  (here,db1.mdb)  , by pressing the ellipse button (....) .
  4. Now, we have to select the tablewhich you will be linking your form to. To do this , click on the RecordSource property of the Data Control , and you will get all the tables listed,  which are a part of the data base to which this data control is linked with.(Since only one table was created in the database, only one table is shown in the list).
  5. Select all the textboxes and change the DataSource property to Data1, since all the text boxes have to be linked with the database that is linked with data control Data1
  6. Select the text1 text box and change the DataField property.When you click on the data field property, it will show you a drop down list.All you have to do is to , choose the field with which you want this text box to be linked with.So choose RollNo from the list.
  7. Like above, change the data field property of Text2 to Name, Text3 to Age and text4 to Sex.
  8. Now , every control in the form1 is linked with some or the other component to import the data from the data base db1.mdb which we created in MS-Access.
  9. Save the project
  10. Now, click on the start button to run the application, use navigation buttons to navigate the records in the database.
=========================================================================
Back to Home   &  VB

Monday, June 27, 2011

VB-24 : Copies files from one location to other

Create an application,that copies a file from one location to any other location by simulating windows explorer(That is,implementing drag and drop feature).


Steps:

  1. Start VB
  2. Click DriveListBox control on the form(Note that, by default,its name is Drive1).Now stretch the form length
  3. Add another component DirListBox (by default,its name is Dir1).
  4. Repeat steps (2) and (3) and we get the controls with the names  Drive2 and Dir2
  5. Note that now there is two DriveListBox and two DirListBox.
  6. Insert a FileListBox  (by default,its name is File1).
  7. Now,our aim is to implement the copy operation,when we drag a file from File1 and drop it in  Dir2 . So ,to do this  the following steps are needed ..,after writing the code..


Attaching Code to the Object :




Private Sub Dir1_Change()
File1.Path = Dir1
End Sub
Private Sub Dir2_DragDrop(Source As Control, X As Single, Y As Single)
Dim st As String
st = "\" And Source.Path And st 'dir2.Path and st
Source.Drag 0
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1
End Sub
Private Sub Drive2_Change()
Dir2.Path = Drive2
End Sub
Private Sub File1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
File1.DragIcon = LoadPicture("c:\program files\microsoft visual studio\vfp98\-tools\filer\filer.ico")
If Button = 1 Then
File1.drag1
End If
End Sub



=========================================================================
Back to Home   &  VB

VB-23 : Simple Animation using ActiveX

Program for implementing a small animation clip in an application :


Steps:


  1. Start VB
  2. Project --> Components (Ctrl T)
  3. Add a component file comct232.ocx to the project from control tab in the window.(Select "Microsoft windows common controls-2.5.0(SP2))
  4. Apply-OK
  5. We will get two new controls in the tool box(up-down control and animation control)
  6. Now, add the animation control in our form
  7. Add two command buttons in our form and set their caption property as Play and Stop
  8. Again , Project --> Components (Ctrl T)
  9. Add a component file comdlg32.ocx to the project from control tab in the window.(Select "Microsoft common dialog controls-6.0(SP6))
  10. Apply-OK
  11. Now, add this new control in our form.
Now run the program and you will get the following screen.


(The other two controls Animation and CommonDialog will not appear on the screen while running)


Attaching Code to the Object :



Private Sub Command1_Click()
CommonDialog1.Filter = "*.AVI"
CommonDialog1.ShowOpen
Animation1.Open CommonDialog1.FileName
Animation1.Play
End Sub
Private Sub Command2_Click()
Animation1.Stop
End Sub


Output :


When you press PLAY , a screen will appear ,open any file with AVI format.And you will get the same loaded form with a new running animation file which you have choosen.
To stop animation,you can press STOP button.


(Refer this Video explaining a simple animation)
=========================================================================
Back to Home   &  VB

Sunday, June 5, 2011

VB-22 : Moving items between listbox/Combobox (Through Program)



Add items to the textbox.Then move themt, to another list/combo box.

A)   Property :

       
Listbox  : NAME-List1,LIST-(Blank)
Listbox  : NAME-List2,LIST-(Blank)
Textbox : NAME-Text1,Text- (Blank)
CommandButton-NAME- Command3,Caption-Add
CommandButton-NAME- Command1,Caption- è
CommandButton-NAME- Command2,Caption- ç





B)   Attaching Code to the Object :

        
Private Sub Command1_Click()
List2.AddItem List1.List(List1.ListIndex)
List1.RemoveItem List1.ListIndex
End Sub

Private Sub Command2_Click()
List1.AddItem List2.List(List2.ListIndex)
List2.RemoveItem List2.ListIndex
End Sub

Private Sub Command3_Click()
List1.AddItem Text1.Text
End Sub





=========================================================================
Back to Home   &  VB

VB-21 : Selecting items from a listbox/Combobox (Through Program)



Our selected item will store in the list index of combo box.
     
A)   Property :
ComboBox : NAME- Combo1,TEXT-(Blank)
Textbox : NAME-Text1,Text- (Blank)
CommandButton-NAME- Command1,Caption-Add
CommandButton-NAME- Command3,Caption-Select






     B)   Attaching Code to the Object :
  
    
Private Sub Command1_Click()
Combo1.AddItem Text1.Text
End Sub

Private Sub Command3_Click()
st = Combo1.List(Combo1.ListIndex)

MsgBox (st)
End Sub




=========================================================================
Back to Home   &  VB