Visual Basic Notes

          Visual Basic Introduction

Front End Tools
1.Visual Basic
2.Power Builder
3.Visual C++
4.Java
5.Developer  2000
6.Microsoft Access

Back End Tools
1.Microsoft Access
2.Oracle
3.SQL Server.
4.Visual Foxpro

Three Editons of VB

1.Learning Edition
2.Professional Edition
3.Enterprise Edition


VB is a member in Microsft Visual Studio products. Other products are
Visual C++, Visual Foxpro, Visual InterDev, etc.


Visual Basic:
    The application ( file) created using VB is called a project.
The project contains many forms,modules,class modules and reports, etc.
    The extension of the project is .vbp
    The extension of the form is 1.frm
    The extension of the module is .bas
    The extension of the Class module is .cls
    The extension of the Data Environment is .dsr (Designer)
    The extension of the Data Report is .dsr (Designer)

Note :
    After creating an application i.e VB project. It can be converted
into an executable file. The extension is .exe . To run the exe file, we
don't need Visual Basic. The Windows platform itself is enough to run
the application.



Windows Network:
    Any network operating system consists of a Server part, client partand communication across them through the cable arrangements.
The Windows network consists of
    Windows NT Server as Server operating System,
    Windows NT Workstation as Client operating System.

Normally the Back End Software is installed in The Server and all the
client nodes containing the front end tools i.e GUI for end-user to
access the back end through the front end.


Screen Elements in Visual Basic.
1.Title Bar
2.Menu Bar
3. Tool Bar
    Standard ToolBar
    

4.Tool Box
    It contains various GUI components i.e tools for designing the
forms.
5.Properties Window(F4)
    It contains properties of every object placed in the form.
6.Project Explorer (Ctrl+R)
    It is used to explore-search-navigate through the Project items
i.e. forms,modules and reports.

7.Object Window or Design Window ( Shift+F7)
    The componets are placed-designed in the form here.
8.Code Window (F7)
    This windows consists of coding that are executed when running an
application.
9.Form Layout Window
    It is used to locate-place the form i.e where should be the form in the
window at the run time.




VBCONTROLS
-------------------
1.FORM
-----------
Properties
-----------
    Name          Caption        Backcolor
    Borderstyle    Left        Top
    Width        Height        WindowState
    KeyPreview    Icon        Picture
    
Methods
---------
    Print    Printform  --- To print in printer.
    Circle    Line    Move,    Cls etc

Events
-------
    Load    Activate     Click     DblClick
    MouseUp        MouseDown    MouseMove
    Keypress    KeyUp        KeyDown
    Deactivate
    Unload
    DragDrop----- Occurs when an object is dropped over the form.
    DragOver----- Occurs when an object is dragged over the form.
    
CODING
-----------
Private Sub Form_Activate()
Me.Circle (1000, 1000), 1000
Me.Move 1000, 1000
Me.Cls
Me.Line (1, 1)-(2000, 2000)
Me.Print "hello"
me.printform
End Sub

Private Sub Form_Click()
MsgBox "Mouse Clicked"
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Form1.Width = Form1.Width + 100
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
Form1.Print KeyAscii
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then
End
End If
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then ' KeyPreview property set to true
End
End If
End Sub


Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then
Else
KeyAscii = 0
End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Me.Print KeyCode
End Sub

Private Sub Form_Load()
MsgBox "Form Load()"
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form1.BackColor = vbRed
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Circle (X, Y), 500
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Form1.BackColor = vbBlue
End Sub
----------------------------------------------------------------------------------------------------------------------------------------

2.LABEL
------------
Properties
-----------
    Name    Caption    Autosize    DataSource    DataField
    Wordwrap    Backcolor    Borderstyle    Left    Top
    Width    Height    Alignment        Visible    MousePointer

----------------------------------------------------------------------------------------------------------------------------------------

3.TEXTBOX
---------------
PROPERTIES
------------------
    Name    Text
    Font    Backcolor
    Forecolor    Maxlength
    Enabled    Locked
    Multiline    Visible

EVENTS
-----------
    Change,    KeyPress,    KeyDown,    KeyUp,GotfocusLostfocus,

Coding
----------

Private Sub Text1_Change()
text3.Text = Val(Text1.Text) + Val(text2.Text)
End Sub


Private Sub Text3_LostFocus()
Text4.Text = Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text)
End Sub

Private Sub Text4_GotFocus()
Text4.Text = Val(Text1.Text) + Val(Text2.Text) + Val(Text3.Text)
End Sub

Private Sub Text1_Change()
If Text1.Text = "" Then
Command1.Enabled = False
Else
Command1.Enabled = True
End If
End Sub

Data Validation:  ----- To accept nmbers only.
----------------------
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then
Else
KeyAscii = 0
End If
End Sub
----------------------------------------------------------------------------------------------------------------------------------------

01-AUG-2001

Private Sub Command1_Click()
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
End Sub

Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Command1.Enabled = False
End Sub

Private Sub Text1_Change()
If Text1.Text = "" Or Text2.Text = "" Then
Command1.Enabled = False
Else
Command1.Enabled = True
End If
End Sub

Private Sub Text2_Change()
If Text1.Text = "" Or Text2.Text = "" Then
Command1.Enabled = False
Else
Command1.Enabled = True
End If
End Sub
'--------------------------------------------------




4.COMMANDBUTTON  
---------------

PROPERTIES
------------------
    Name
    Caption
    Cancel     -- When set to true,    Click event is executed when Escape key is pressed.
    Default -- When set to true,    Click event is executed when Enter key is pressed.
    Enabled
    Backcolor
    Style -- 0Standard,1Graphical
    
EVENTS
-----------
    Click
    DblClick
    
CODING
-----------

Private Sub Command1_Click()
MsgBox "Command1 is Clicked"
text3=val(text1)+val(Text2)
End Sub


Private Sub Command2_Click()
End
End Sub

--------------------------------------------------------------------------------------------------------------------------------------------------
5.FRAME                ----------------- It is used to group the controls.
---------
PROPERTIES
------------------
    Name
    Caption
EVENTS
-----------
    DragDrop
    DragOver

----------------------------------------------------------------------------------------------------------------------------------------

6.PICTUREBOX --------------------- It is used to place the image.
------------------
PROPERTIES
------------------
    Name
    Align
    AutoSize
    Picture
    Left,Top,Width,Height
    MousePointer ----Cross,I-Beam.etc.
EVENTS
-----------
    Click
    DragDrop
    DragOver

----------------------------------------------------------------------------------------------------------------------------------------

7.IMAGE    --------------------- It is used to place the image.
------------------
PROPERTIES
------------------
    Name
    Align
    Picture
    Left,Top,Width,Height
    MousePointer ----Cross,I-Beam.etc.
    STRETCH-----TRUE/FALSE  ------ Full image will be displayed in given size.
EVENTS
-----------
    Click
    DragDrop  ------------ Occurs when an object is dragged and dropped above this control.
    DragOver ------------Occurs when an object is dragged over this control.
----------------------------------------------------------------------------------------------------------------------------------------

8.TIMER         ----------------- Used to execute particular code at predefined intervals.
--------
PROPERTIES
--------------------
INTERVAL     ---------- In milliseconds.
EVENTS
-----------
TIMER  -------------------- Event to be done at given interval.


CODING
----------





Private Sub Timer1_Timer()

Do
Picture1.Left = Picture1.Left + 1
Loop While Picture1.Left <= 10000

Do
Picture1.Top = Picture1.Top + 1
Loop While Picture1.Top <= 7000

Do
Picture1.Left = Picture1.Left - 1
Loop While Picture1.Left > 0

Do
Picture1.Top = Picture1.Top - 1
Loop While Picture1.Top > 0
End Sub

----------------------------------------------------------------------------------------------------------------------------------------




9.CHECKBOX
-------------------

PROPERTIES
------------------
    Name
    Value  -------------     0 Unchecked
            1 Checked
            2 Grayed
EVENTS
-----------
    CLICK
CODING
----------
Private Sub Check1_Click()
If Check1.Value = vbChecked Then
Text1.FontBold = True
Else
Text1.FontBold = False
End If
End Sub

Private Sub Check2_Click()
If Check2.Value = vbChecked Then
Text1.FontItalic = True
Else
Text1.FontItalic = False
End If

End Sub

Private Sub Check3_Click()
If Check3.Value = vbChecked Then
Text1.FontUnderline = True
Else
Text1.FontUnderline = False
End If

End Sub



10.OPTIONBUTTON   (RADIOBUTTON)
--------------------------------------------------
PROPERTIES
------------------
    Name
    Style ------------    0 Standard
            1 Graphical
    Value ----------- True/False


Events

Private Sub Option1_Click()
If Option1.Value = True Then
Text1.ForeColor = vbRed
End If
End Sub

Private Sub Option2_Click()
If Option2.Value = True Then
Text1.ForeColor = vbGreen
End If

End Sub

Private Sub Option3_Click()
If Option3.Value = True Then
Text1.ForeColor = vbBlue
End If
End Sub


11.LISTBOX
------------
PROPERTIES
------------
1.NAME
2.LIST
3.STYLE   ----  0 STANDARD
        1 CHECKED
4.SORTED
5.LIST
6.LISTCOUNT
7.Multiselect.  -     0 none
         1 simple
        2 extended     
METHODS
-------
1.ADDITEM  itemname
2.REMOVEITEM index
3.CLEAR
4.SELECTED

EVENTS
------
1.CLICK

-----------------------

CODING
------
Private Sub List2_Click()
For I = 0 To List2.ListCount - 1
If List2.Selected(I) = True Then
Text2.Text = List2.List(I)
Exit Sub
End If
Next
End Sub

Private Sub Command1_Click()
List2.AddItem Text2.Text
End Sub

Private Sub Command2_Click()
List2.Clear
End Sub

Private Sub Command3_Click()
For I = 0 To List2.ListCount - 1
If List2.Selected(I) = True Then
List2.RemoveItem I
Exit Sub
End If
Next I
End Sub


****************************************

Private Sub Command1_Click()
For i = 0 To List1.ListCount - 1
If List1.Selected(i) = True Then
List2.AddItem List1.List(i)
List1.RemoveItem i
Exit Sub
End If
Next
End Sub

Private Sub Command2_Click()
For i = 0 To List1.ListCount - 1

List2.AddItem List1.List(i)

Next
List1.Clear
End Sub

Private Sub Command3_Click()
For i = 0 To List2.ListCount - 1
If List2.Selected(i) = True Then
List1.AddItem List2.List(i)
List2.RemoveItem i
Exit Sub
End If
Next

End Sub

Private Sub Command4_Click()
For i = 0 To List2.ListCount - 1
List1.AddItem List2.List(i)
Next
List2.Clear

End Sub



12.Combobox:

Same as Listbox
-----------------
Property:
style -     0 Dropdown Combo  ------- We can additionally type the text in the textbox provided
    1 Simple combo
    2 Dropdown list  ------ We cannot type in the textbox provided.

Private Sub Combo1_Click()
If Combo1.Text = "red" Then
Text1.ForeColor = vbRed
End If
If Combo1.Text = "green" Then
Text1.ForeColor = vbGreen
End If
If Combo1.Text = "blue" Then
Text1.ForeColor = vbBlue
End If
End Sub

Private Sub Combo1_Click()
Text1.FontSize = Val(Combo1.Text)
End Sub

Private Sub Combo2_Click()
If Combo2.Text = "BOLD" Then
Text1.FontBold = True
Else
Text1.FontBold = False
End If
If Combo2.Text = "ITALIC" Then
Text1.FontItalic = True
Else
Text1.FontItalic = False
End If
If Combo2.Text = "BOLDITALIC" Then
Text1.FontBold = True
Text1.FontItalic = True
End If
If Combo2.Text = "REGULAR" Then
Text1.FontBold = False
Text1.FontItalic = False

End If

End Sub


TO BRING SREEN FONTS TO A LIST BOX :

Private Sub Form_Load()
For I = 0 To Screen.FontCount - 1
List1.AddItem Screen.Fonts(I)
Next
End Sub


Private Sub List1_Click()
Text1.FontName = List1.Text
End Sub




************************************************************************************
13.Line
-------

Property :
1.bordercolor
2.borderstyle
3.borderwidth


14.Shape
--------
Properties:
1.Shape
2.bodercolor
3.borderstyle
4.borderwidth
5.Fillcolor
6.FillStyle

Private Sub Timer1_Timer()
Static i
i = i + 1
If i = 6 Then
i = 0
End If
Shape1.Shape = i
Shape1.FillStyle = i
End Sub


15.DriveListbox,    16.DirListbox,    17.FileListbox
--------------------------------------------------------------------------------
Coding

Private Sub Combo1_Click()
File1.FileName = Combo1.Text
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
File1.Path = Dir1.Path
End Sub

Private Sub File1_Click()
Label2.Caption = File1.FileName
End Sub  
********************************************************************-----
18.Horizontal Scroll bar and 19.Vertical Scroll bar
---------------------------------------------------------------

PROPERTIES:
1.Value
2.Max
3.Min
4.SmallChange
5.LargeChange

EVENTS:
1.Change
2.Scroll.
************


Private Sub HScroll1_Change()
Text1.Text = HScroll1.Value
Me.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub

Private Sub HScroll2_Change()
Text2.Text = HScroll2.Value
Me.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub

Private Sub HScroll3_Change()
Text3.Text = HScroll3.Value
Me.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub

Private Sub HScroll1_Scroll()
Text1.Text = HScroll1.Value
Me.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub

Private Sub HScroll2_Scroll()
Text2.Text = HScroll2.Value
Me.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
End Sub

Private Sub HScroll3_Scroll()
Text3.Text = HScroll3.Value
Me.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)  
End Sub



+++++++++++++++++++++++++++++++++++++++++
------------------------------------------


Private Sub VScroll1_Change()
List1.Selected(VScroll1.Value - 1) = True
End Sub

Private Sub VScroll1_Scroll()
List1.Selected(VScroll1.Value - 1) = True
End Sub

Private Sub List1_Click()
For i = 0 To List1.ListCount - 1
If List1.Selected(i) = True Then
VScroll1.Value = i + 1
Exit Sub
End If
Next i
End Sub
*****************************





20.OLE - Object Linking and Embedding

Object linking and embedding: The technology that enables you to create applications that contain components from various other applications.


1.Drag a OLE control in the form.
2.Select the path of the file.
3.Check the link checkbox.
4.Click Ok.
5.Run the form.
6.Double click the OLE control.
7.Modify the content.
8.See the content is modified in the original source.


InputBox()

It is used to get input from user.


MsgBox()

It is used to display a message or value of a variable,etc.


Control statements:
-------------------


Control Statements are used to execute one or more statements if a condition
is satisfied.



Types:
------

if  ...then ... endif
if ...then ...  else ... endif
if ...then ... elseif ... then ... endif

select  case < value >

case constant1:

.......
.......

case constant2:

.......
.......

end select



Looping statements:
-------------------


It is used to execute one or more statements for a number of times.
Types:
While ... Wend
Do ...  Loop While < condition >
Do ... Loop Until < condition >
For <variablename> = <Initial value> To <Final value> Step <Increment value>
....
....
....
Next <variablename>
****************************************


Private Sub Command1_Click()
a = InputBox("Enter A ")
b = InputBox("Enter B")
If Val(a) > Val(b) Then
MsgBox "A is big"
Else
MsgBox "B is big"
End If
End Sub

Private Sub Command2_Click()
a = InputBox("Enter A:")
Select Case a
Case 10:
MsgBox "Ten"
Case 20:
MsgBox "Twenty"
Case 30:
MsgBox "Thirty"
Case 40:
MsgBox "Forty"
End Select
End Sub



Example:   while     do-while   do-until   for   loops.
Private Sub Command1_Click()
Dim i As Integer
i = 100
While i <= 100
Me.Print i
i = i + 1
Wend
End Sub

Private Sub Command2_Click()
i = 1
Do
Me.Print i
i = i + 1
Loop Until i > 10
End Sub

Private Sub Command3_Click()
For i = 10 To 1 Step -1
Me.Print i
Next i
End Sub



Constant :
    Any quantity whose value does not change during the program
execution is called constant.

Variable:
    Any quantity whose value can change during the program
execution is called variable.


Data types:
---------------
    It is used totell what type of data that a variable can store.

Integer
String
Currency
Single
Double
Date
Variant
Byte
Boolean

Declaration of a variable:

Dim s As Single
Dim d As Double
Dim i As Integer
Dim d As Date
Dim v As Variant
Dim b As Byte
Dim bb As Boolean

Assigni
ng values to a variable:

d=100
s="india"
dob=date


Declaring an Array:

An array is a collection of variables of same data type under a single name.
Each element of an array has a unique identifying index number.
Types :
Single -Dimensional array.
Multi-Dimensional array.



Declaration of an array variable:

dim mark(5) as integer






Private Sub Command1_Click()
Dim i(5) As Integer
i(5) = 8922
Text1.Text = i(5)
End Sub

Private Sub Form_Load()
Dim i(3 To 5) As Integer
i(0) = 89
Text1.Text = i(6)
End Sub
***********************************************************

MENU

A list of available commands in an application window.

Menu Editor:

Menu Editor is used to create menus.

To display the menu editor:

Tools-> Menu Editor.  (  Ctrl+E)
******************************************************


Private Sub MNUADD_Click()
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
End Sub

Private Sub MNUDIVIDE_Click()
Text3.Text = Val(Text1.Text) / Val(Text2.Text)

End Sub

Private Sub MNUEXIT_Click()
End
End Sub

Private Sub MNUMUL_Click()
Text3.Text = Val(Text1.Text) * Val(Text2.Text)

End Sub

Private Sub MNUSUB_Click()
Text3.Text = Val(Text1.Text) - Val(Text2.Text)
End Sub


****************************************************
Chapter 2:
Connecting to Backend MS-Access
1.Using Data Control.
2.Using DAO.
3.Microsoft DataBoundGrid Control.(DBGrid)
4.Microsoft DataBoundList Control.(DBList & DBCombo).


1.Data Control

Data control is used to connect the front end (Visual Basic) to the Back end such as MS-Access,Oracle,etc and manipulate the database tables such as insert,delete the records,etc.



To create database in MS-ACCESS
Add-Ins menu -> Visual Data Manager -> File -> New ->
 MicrosoftAccess->Version 7.0 MDB.

1.Type the name of the database window.
2.Create the table with required fields using database window.
3.By right clicking the table, manipulate the table such as adding the records, etc.

In the form:

1.Drag a Datacontrol (Data1).
2.Set the property,
    Database name. --- DATABASE PATH
    RecordSource.  --- TABLE NAME
3.Drag the text box.
4.Set the propery
    DataSource  --- DATA1
    Data field. ---- FIELD
5.Save the project and Run the form.


Coding:
-------
Private Sub Command1_Click()
Data1.Recordset.MoveFirst
End Sub
Private Sub Command2_Click()
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
Data1.Recordset.MoveFirst
End If
End Sub
Private Sub Command3_Click()
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
End If
End Sub
Private Sub Command4_Click()
Data1.Recordset.MoveLast
End Sub


Private Sub Command5_Click()
Data1.Recordset.AddNew
End Sub

Private Sub Command6_Click()
Data1.Recordset.Edit
End Sub

Private Sub Command7_Click()
Data1.Recordset.Update
End Sub

Private Sub Command8_Click()
Data1.Recordset.Delete
End Sub
Private Sub Command9_Click()
Dim NO As Integer
NO = Val(InputBox("Enter the rollno?"))
Data1.Recordset.FindFirst "rno=" & NO
If Data1.Recordset.NoMatch Then
MsgBox "Record not found"
End If
End Sub
/********************/



--------------------------------
' To search namewise
Dim n As String
n = (InputBox("Enter the name?"))
Data1.Recordset.FindFirst "name='" + n + "'"
If Data1.Recordset.NoMatch Then
MsgBox "Record not found"
End If
' To search numberwise
Dim NO As Integer
NO = Val(InputBox("Enter the rollno?"))
Data1.Recordset.FindFirst "rno=" & NO
If Data1.Recordset.NoMatch Then
MsgBox "Record not found"
End If
----------------
*****************************************************************************************
777777777777777777777777777777777

Connecting MS-Access using DAO
-----------------------------------------------------------
2.DAO  -- Data Access Object

It is used to connect to the backend without using  Data control.
The object library is Microsoft DAO3.50 Object Library
File ----------DAO350.dll
***********
Dim db As Database
Dim rs As Recordset

Private Sub Command1_Click()
rs.MoveFirst
SHOWDATA
End Sub

Private Sub Command2_Click()
rs.MovePrevious
If rs.BOF Then
rs.MoveFirst
End If
SHOWDATA
End Sub

Private Sub Command3_Click()
rs.MoveNext
If rs.EOF Then
rs.MoveLast
End If
SHOWDATA

End Sub

Private Sub Command4_Click()
rs.MoveLast
SHOWDATA
End Sub
Private Sub Command5_Click()
rs.AddNew
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub
Private Sub Command6_Click()
rs.Edit
End Sub
Private Sub Command7_Click()
rs.Fields(0) = Text1.Text
rs.Fields(1) = Text2.Text
rs.Update
MsgBox "Record Saved"
End Sub
Private Sub Command8_Click()
rs.Delete
MsgBox "Record Deleted"
End Sub
Private Sub Form_Activate()
Set db = OpenDatabase("C:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB")
Set rs = db.OpenRecordset("select * from customers")
SHOWDATA
End Sub


Public Sub SHOWDATA()
Text1.Text = rs.Fields(0)
Text2.Text = rs.Fields(1)
End Sub

????????????????????????????????????????






3.Microsoft DataBoundGrid Control.(DBGrid)

1.Drag a Data control
    1.Set DataBaseName and Recordsource.
    2.In Project menu-> Components . Select Microsoft DataBoundGrid Control  5.0
    3.Drag a DBGrid control DBGrid1.
    4.Set the property DataSource -- Data1.
    5.Run the form

Prperties:
AllowAddnew
AllowArrows
AllowDelete
AllowUpdate

4 .Microsoft DataBoundList Control.(DBGrid)
a) DBLIST1 & DBCombo1
    1.Drag a Data control
    1.Set DataBaseName and Recordsource.
    2.In Project menu-> Components . Select Microsoft DataBoundList Control  5.0
    3.Drag a DBlist control DBlist1
    4.Set the property DataSource -- Data1. , RowSource--Data1, ListField--Fieldname
    5.Drag a DBCombo control DBCombo1
    6.Set the property DataSource -- Data1. , RowSource--Data1, ListField--Fieldname
    7.Run the form

Private Sub DBList1_Click()
Data1.Recordset.FindFirst "rollno=" & Val(DBList1.Text)
End Sub





******************************************************************************

*=*




Creating Function and Procedure:(*)

To create a procedure:

In Tools menu -> Add Procedure, type the procedure name,
Type   ---- sub
Scope ---- public , and click Ok.

Type the coding in the procedure.

Call the procedure wherever required.

Functions are same as procedure, except that it returns a value.

Coding:

Public Sub showdate()
MsgBox Date
MsgBox Time
End Sub
Public Function addition(ByVal i As Integer, ByVal j As Integer)
addition = i + j
End Function
******************************************
Private Sub mnuadd_Click()
Text3.Text = addition(Val(Text1.Text), Val(Text2.Text))
End Sub


String Functions:(*)

Len(string)  --- Finds the length
left(string,n)--- Returns n characters from left
right(string,n)---Returns n characters from right
mid(string,m,n) ---- Returns n characters starting from m.
ucase(string)----Converts to upper case.
lcase(string)----Converts to lower case.
strcomp(string1,string2) ----Compares two strings
strreverse(string) ----- Reverses the string
asc(string)  -- Returns ASCII value of first character
chr(int)-- Character of given code.
trim(string) --- Trims the leading and trailing edges.
instr(startposition,string1,string2)
   It used to search the string2 in string1, searching starts from the startposition. It returns
the position of string2 in number.




Numeric Functions:(*)

cos(number)
exp(number)
hex(number)
int(number)
isnumeric(expression)





Private Sub Command1_Click()
Dim S As String
Debug.Print Len(Text3.Text)
Debug.Print StrComp("INDIA", "INPIA")
S = StrReverse("INDIA")
Debug.Print S
Debug.Print Left("INDIA", 3)
Debug.Print Right("INDIA", 3)
Debug.Print Mid("INDIA", 3, 2)
Debug.Print InStr(4, "INDIA", "ND")
Debug.Print Chr(65)
Debug.Print Asc("INDIA")
For I = 1 To 100
Print Chr(I)
Next
End Sub
Private Sub Command2_Click()
Text1.Text = Trim(Text1.Text)
End Sub
Private Sub Text1_Change()
Text1.Text = UCase(Text1.Text)
End Sub
Private Sub Text2_Change()
Text2.Text = LCase(Text2.Text)
End Sub
****


Private Sub Command1_Click()
Debug.Print Cos(0)
Debug.Print Exp(10)
Debug.Print Int(10.8)
Debug.Print Sqr(9)
Debug.Print Val("90")
Debug.Print IsNumeric("67")
Debug.Print Hex(15)
Debug.Print Round(105.6789, 2)

End Sub
888888888888888888888888888888888888888888888
'Private Sub Command1_Click()
'Dim S As String
'Debug.Print Len(Text3.Text)
'Debug.Print StrComp("INDIA", "INPIA")
'S = StrReverse("INDIA")
'Debug.Print S
'Debug.Print Left("INDIA", 3)
'Debug.Print Right("INDIA", 3)
'Debug.Print Mid("INDIA", 3, 2)
'Debug.Print InStr(4, "INDIA", "ND")
'Debug.Print Chr(65)
'Debug.Print Asc("INDIA")
'For I = 1 To 100
'Print Chr(I)
'Next
'End Sub
'Private Sub Command2_Click()
'Text1.Text = Trim(Text1.Text)
'End Sub
'Private Sub Text1_Change()
'Text1.Text = UCase(Text1.Text)
'End Sub
'Private Sub Text2_Change()
'Text2.Text = LCase(Text2.Text)
'End Sub
'
'
'Number functions
'Debug.Print Cos(0)
'Debug.Print Exp(10)
'Debug.Print Int(10.8)
'Debug.Print Sqr(9)
'Debug.Print Val("90")
'Debug.Print IsNumeric("67")
'Debug.Print Hex(15)
'Debug.Print Round(105.6789, 2)
'
'Date functions
'Debug.Print Date
'Debug.Print Year(Date)
'Debug.Print Month(Date)
'Debug.Print Day(Date)
'Debug.Print IsDate("1/1/2001") ' returns true or false
'
'Color functions
'Qbcolor(int) ' range 0 to 15
'rgb(red as Integer ,green as Integer ,blue as Integer )
'
'Private Sub Timer1_Timer()
'Me.BackColor = QBColor(Rnd * 15)
'End Sub


OCX controls:
---------------------
Ole Based Customized Controls.

1.Microsoft CommonDialog Control 6.0
2.Microsoft DataBoundGrid control 5.0
3.Microsoft DataBoundList controls 6.0
4.Microsoft ADODC control 6.0 (OLEDB)
5.Microsoft DataGrid control 6.0
6.Microsoft Dataist controls 6.0
7.Microsoft Calendar control 8.0
8.Microsoft FlexGrid Control 6.0
9.Microsoft RichTextBox control 6.0
10.Microsoft windows Common controls 6.0
    a) Tabstrip
    b) Toolbar
    c) ImageList
    d) Statusbar
    e) TreeView
    f) ListView
    g) Progressbar
    h) Slider
10.Microsoft Animation control.
11.Microsoft Chart control 6.0


ANIMATION CONTROL( *)
Projects -> Components -> Microsoft Windows Common  Controls-2   5.0

Private Sub Command1_Click()
Animation1.Open "C:\WINNT\CLOCK.AVI"

End Sub

Private Sub Command2_Click()
' Animation1.Play  repeatcount, startingframe,ending frame
Animation1.Play  2, 0, 5
End Sub

Private Sub Command3_Click()
Animation1.Stop
End Sub

Private Sub Command4_Click()
Animation1.Close
End Sub

************************************

RichTextBox and  CommonDialog control:
------------------------------------------------------------------
Private Sub Command1_Click()
CommonDialog1.ShowOpen
RichTextBox1.LoadFile CommonDialog1.FileName
End Sub

Private Sub Command2_Click()
CommonDialog1.ShowSave
RichTextBox1.SaveFile CommonDialog1.FileName
End Sub

Private Sub Command3_Click()
RichTextBox1.Text = ""
End Sub

Private Sub Command4_Click()
RichTextBox1.SelBold = Not RichTextBox1.SelBold
End Sub

Private Sub Command5_Click()
RichTextBox1.SelItalic = Not RichTextBox1.SelItalic
End Sub

Private Sub Command6_Click()
RichTextBox1.SelUnderline = Not RichTextBox1.SelUnderline
End Sub

Private Sub Command7_Click()
CommonDialog1.ShowColor
RichTextBox1.SelColor = CommonDialog1.Color
End Sub






*********************************************
ProgressBar
1.

ProgressBar Coding
-----------------------------
'Private Sub Timer1_Timer()
'ProgressBar1.Value = ProgressBar1.Value + 1
'If ProgressBar1.Value = 100 Then
'ProgressBar1.Value = 0
'End If
'End Sub
************************************************
MediaPlayer Coding(*)
---------------------------
Private Sub Form_Load()
MediaPlayer1.FileName = "C:\WINNT\CLOCK.AVI"
End Sub
************************************************
Animation Control Coding:(*)
------------------------
Private Sub Command1_Click()
Animation1.Open "C:\WINNT\CLOCK.AVI"
End Sub

Private Sub Command2_Click()
Animation1.Play 2, 4, 6
End Sub

Private Sub Command3_Click()
Animation1.Stop
End Sub

Private Sub Command4_Click()
Animation1.Close
End Sub
==========================
TREEVIEW CODING
Private Sub Command1_Click()
'TreeView1.Nodes.Add , , "I", "IND"
'TreeView1.Nodes.Add , , "A", "ASIA"
'TreeView1.Nodes.Add , , "E", "EUROPE"
'TreeView1.Nodes.Add "I", tvwChild, , "MUMBAI"
'TreeView1.Nodes.Add "I", tvwChild, , "CHENNAI"
'TreeView1.Nodes.Add "A", tvwChild, , "IRAN"
'TreeView1.Nodes.Add "A", tvwChild, , "IRAQ"


Dim PARKEY As String
Dim TEXT As String
Dim CHTEXT As String
For I = 1 To 10
TEXT = "NODE : " & I
TreeView1.Nodes.Add , , TEXT, TEXT
    For J = 1 To 3
    CHTEXT = "CHILDNODE : " & I & J
    TreeView1.Nodes.Add TEXT, tvwChild, , CHTEXT
    Next J
Next I

End Sub

=====================
LISTVIEW CODING
Private Sub Combo1_Click()
   ListView1.View = Combo1.ListIndex
End Sub

Private Sub Command1_Click()
Dim colX As ColumnHeader ' Declare variable.
'''''''''''Dim intX As Integer ' Counter variable.
'''''''''''For intX = 1 To 4
'''''''''''   Set colX = ListView1.ColumnHeaders.Add()
'''''''''''   colX.Text = "Field " & intX
'''''''''''   colX.Width = ListView1.Width / 4
'''''''''''Next intX
ListView1.ColumnHeaders.Add
ListView1.ColumnHeaders(1).Text = "Name"
ListView1.ColumnHeaders.Add
ListView1.ColumnHeaders(2).Text = "Address"
ListView1.ColumnHeaders.Add
ListView1.ColumnHeaders(3).Text = "DOB"
ListView1.ColumnHeaders.Add
ListView1.ColumnHeaders(4).Text = "City"

ListView1.ListItems.Add
ListView1.ListItems(1).Text = "name1"
ListView1.ListItems(1).ListSubItems.Add , , "Hitchhiker's Guide to Visual Basic and SQL Server"
ListView1.ListItems(1).ListSubItems.Add , , "Vaughn, William R."
ListView1.ListItems(1).ListSubItems.Add , , "1996"
ListView1.ListItems(1).ListSubItems.Add , , " 1-55615-906-4"
ListView1.ListItems.Add
ListView1.ListItems(2).Text = "name2"
ListView1.ListItems(2).ListSubItems.Add , , "Hitchhiker's Guide to Visual Basic and SQL Server"
ListView1.ListItems(2).ListSubItems.Add , , "Vaughn, William R."
ListView1.ListItems(2).ListSubItems.Add , , "1996"
ListView1.ListItems(2).ListSubItems.Add , , " 1-55615-906-4"
ListView1.ListItems(2).ListSubItems.Add , , "india"


End Sub

Private Sub Form_Load()
ListView1.View = lvwReport
   With Combo1
      .AddItem "Icon"          '0
      .AddItem "Small Icon"    ' 1
      .AddItem "List"          ' 2
      .AddItem "Report"       ' 3
   End With
End Sub





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






Data Environment
The Data Environment designer provides an interactive,
 design-time environment for creating DAO objects which is
 used for reports.

Data Report
Used to produce formatted and attractive outputs as reports.

To create a report :
1. Add Data-Environment  from Project menu.
2. In the DataEnvironment window, right click the connection1 properties and
    select the provider, -> next -> connection ( data source name ) --> Test connection.
3. Right-click the connection1, add command.
4. Right-click the command1 properties, select the source of data --> Object name -> OK.
5.  Add Data-Report  from Project menu.
6. Set the property
    Data source -> DataEnvironment1
    DataMember->Command1.
7.Drag the command1 from dataenvironment window to the data report's Detail section.
8.Run the report.













3.3.1  Introduction to Visual Basic 6.0


The “Visual” part refers to the method used to create the Graphical User Interface (GUI).  Rather than writing numerous lines of code to describe the appearance and locatin of interface elements, simply add pre built object in to place on screen.

The “Basic” part refers to the BASIC language, a language used by more programmers than any other language in the history of computing.

The Visual Basic programming language is not unique to Visual Basic.

The Visual Basic programming system, application, edition included in Microsoft Excel, Microsoft Access & many other windows application uses the same language.



Data access features allow to create database, front-end applicatinos and scalable Server-side components for most popular database formats.

Active X technologies allow the functionality provide the other applications.  Such as Microsoft word, Microsoft Excel and other Window applications.

Internet capabilities make it easy to provide access to documents and appilcations across the Internet of intranet from within application or to create internet server applications.

The finished application is a true .Exe file that uses the Visual Basic a Visual machine that can freely distribute. The components involved in Visual Basic 6.0.

DAO
This new data access technology features a simple object model, better integration with other Microsoft and non-Microsoft technologies, a common interface for both local and remote data access, remotable and disconnected record sets, a user-accessible data binding interface and hierarichal recordsets.

Data Environment
The Data Environment designer provides an interactive, design-time environment for creating DAO objects.

DAO Data Control
The new OLE DB aware data  source control that functions much like the intrinsic data and remote Data controls, in that it allows us to create a database application with minimum code.

OLE DB Support
OLE DB is a set of com interface that provide application with uniform access to data stored in device information sources, both relational & non –relational.

Data Report
Allow us to use drag and drop to Quickly create reports from any recordset, including hierarichal recordset.

Text Box

A TEXT Box control, sometimes called an edit field or edit control, displays information entered at design time, entered by the user, or assigned to the control in code at run time.

Timer
A timer control can execute code at regular intervals by causing a timer event to occur. The TIMER control, invisible to the user, is useful for background processing.

LABEL

A LABEL control is a graphical control and we can use to display text that a user can’t change directly.

COMBO Box
A Combo box control combines the features of a Text Box control and a LIST Box control users can enter information in the text box portion or select an item from the list box of the control.
DATA GRID
Displays and enables data manipulations of a series of rows and columns representing records and fields from a Recordset objects.


DATA LIST
The Data List control is a data bound List box that is automatically populated from a field in an attached data source, and optionally updates a field in a related table of another data source.

Access 7.0
It is a personal computer based RDBMS. This provides most of the features available in the high end RDBMS products like Oracle, Sybase, Ingress etc. VB keeps access as its native database.  Developer can create a database for development & further can create.

The tables required to store data.  During the initial Development phase data can be stored in the access database & during the implementation phase depending on the volume data can use a higher – end database.





MS-ACCESS 7.0

MS-ACCESS is a powerful database management system and the user can create entire application that requires little or no programming. It supports GUI features and an entire programming language, VBA (Visual Basic 6.0 for Application) that can be used to develop richer application.

Access is easy enough to use that, in short time; beginners can to manage their own data. In MS-ACCESS, the Database means a collection of tables that hold data. It collectively stores all the other related objects such as queries, Forms, Reports that are used to implement the database management function effectively.

The MS-ACCESS database can act as a Back-End Database for Visual Basic 6.0. While using Visual B basic 6.0 as a Front End tool, MS-ACCESS supports the user with its powerful management functions. A beginner can create his/her own Database very simply using some mouse clicks.

MS-ACCESS database supports so many data types where a user can incorporate data from other applications. A database created in MS-ACCESS can be accessed through Visual Basic 6.0 using a data control. Here database means, a collection of related tables and a table means a collection of number of records where a record means collection of inter-related fields.

A single table can have any number of indexed files that can be used to locate records using an expression. This helps in filtering out information according to specific criteria.

A user can move inside a table very easily using the navigator tools supported by the MS-ACCESS database. A table can be accessed in a number of ways like as snapshot,dynaset,table etc......

Note

      Snapshot: Snapshot is a representation of a table cannot be updated.

      Dynaset: Dynaset is a collection of updateable tables.

      Table: The term represents a single table, which is updateable

In other words the saying "Necessity is the need of invention holds true for MS-ACCESS also i.e., with the help of MS-ACCESS either a beginner (or) On advanced programmer can develop his/her own application effectively.



 ActiveX Data Object Data Control  - ADODC
------------------------------------------------------------
ADODC data control is used to connect Visual Basic with
Oracle.

1.In Project - > Components , Select Microsoft ADODC DATA CONTROL.
2. Draw a ADODC control in the form.
3. Right click ; in the properties, give the connection
string as
PROVIDER  --- MICROSOFT OLEDB PROVIDER FOR ORACLE.
4. ENTER THE SERVER NAME : ora
5.ENTER THE USERNAME :scott
6.ENTER THE PASSWORD:tiger
7.In authentication tab : supply username and password again.
8. In recordsource tab,  command type -> table , give tablename. -> Apply -> OK.
9..In Project - > Components , Select Microsoft  DATAGRID CONTROL.
10. Draw a DATAGRID control in the form.
11. SET THE DATASOURCE TO ADODC1.
12. RUN THE FORM.
13. THE TABLE CONTENTS WILL BE DISPLAYED IN THE DATAGRID.
**************************

CONTENTS
1.SQL -> Structured Query Language
2.PL/SQL-> Procedural Language/Structured Query Language

SQL
Three types of commands to access the Database.
DDL 1.Data Definition Language  ( Create,Alter,Drop,Desc)
DML 2.Data Manipulation Language (Insert,Update,Delete,Select)
DCL 3.Data Control Language (Grant,Revoke)
    TCL Transaction Control Language ( Commit,Rollback).


RICHTEXTBOX,COMMONDIALOG AND CALENDAR1.VALUE
Private Sub Calendar1_Click()
Text1 = Calendar1.Value
End Sub

Private Sub Command1_Click()
CommonDialog1.ShowOpen
RichTextBox1.LoadFile CommonDialog1.FileName
End Sub

Private Sub Command10_Click()
CommonDialog1.ShowColor
RichTextBox1.SelColor = CommonDialog1.Color
End Sub

Private Sub Command11_Click()
CommonDialog1.ShowPrinter
End Sub

Private Sub Command2_Click()
CommonDialog1.ShowSave
RichTextBox1.SaveFile CommonDialog1.FileName
End Sub

Private Sub Command3_Click()
RichTextBox1.SelBold = True
End Sub

Private Sub Command4_Click()
RichTextBox1.SelItalic = True
End Sub

Private Sub Command5_Click()
RichTextBox1.SelUnderline = True
End Sub

Private Sub Command6_Click()
Clipboard.SetText RichTextBox1.SelText
RichTextBox1.SelText = ""
End Sub

Private Sub Command7_Click()
RichTextBox1.Text = ""
RichTextBox1.SetFocus
End Sub

Private Sub Command8_Click()
Clipboard.SetText RichTextBox1.SelText
End Sub

Private Sub Command9_Click()
RichTextBox1.SelText = Clipboard.GetText
End Sub




------------------------------


MDIFORMS and Menus

1.  With VB, two types of applications can be created
    SDI  -Single Document Interface
    MDI-Multiple Document Interface



Comments