0% found this document useful (0 votes)
25 views15 pages

VB 11

This document provides an overview of the Visual Basic Integrated Development Environment (IDE) and its components. It describes the various windows and tools available in the IDE such as the menu bar, toolbox, form designer, code editor, and object browser. It then discusses different controls and objects that can be used in forms like labels, textboxes, buttons, and their properties. The document also covers various operators, control flow statements, functions, and how to create projects with menus, common dialog boxes, and more. It provides examples of using timers, drives, directories, files, shapes and their animation, and handling events in the code behind windows.

Uploaded by

Dipan Sahoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views15 pages

VB 11

This document provides an overview of the Visual Basic Integrated Development Environment (IDE) and its components. It describes the various windows and tools available in the IDE such as the menu bar, toolbox, form designer, code editor, and object browser. It then discusses different controls and objects that can be used in forms like labels, textboxes, buttons, and their properties. The document also covers various operators, control flow statements, functions, and how to create projects with menus, common dialog boxes, and more. It provides examples of using timers, drives, directories, files, shapes and their animation, and handling events in the code behind windows.

Uploaded by

Dipan Sahoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 15

Visual Basic An Introduction

VB IDE (Integrated Development Enviornment)


Componets are
- MenuBar
- ToolBox
- Standard Toolbar
- Project Explorer Window
- Properties Window
- Form Layout Window
- Form Designer Window
- Code Editor Window
- Object Browser Window
- Immediate Window
ToolBox All Object Discussion
Object & Event @ Code Editor Window
Mathmetical Operator
Plus (+)
Minus (-)
Into (*)
Division (/)
Integer Division (\)
String Operator
Plus (+)
Empersand (&)
Comparison Operator
> greater than
< less than
== equal to
<= Less than or equal to
>= Greater than or equal to
!= or <> Not Equal To
Logical Operator
and (&&)
or (||)
not (!)
Control Flow Statement
Sequence
Selection
Iteration/Loop
Selection
If Statement
If Else Statement
Nested If
Select Case Statement
Iteration
For....... Next
do while........... loop
while.......... wend
with ................. end with
Input Box Function
Message Box Function
Menu
Designing & Details
Adding Code
Managing Form Methods
MDI & SDI Form
Common Dialog Box
Adodc Control
ToolBar
Status Bar
Creating EXE Files
Using Inbuilt Project & Setup

====================x====================
Pointer
Move, Resize Etc...
Picture
Properties = Picture, AutoSize
Format (.jpg, bmp, mpeg, gif, wmf, ico)
Label
Proerties = (Caption, AutoSize, WordWrap)
Textbox
Properties =(Text, Locked, MaxLength, MultiLine, Password)
Frame
Minimum use
Command Button
Properties = (Caption, Font)
CheckBox
Properties = (Value)
========== code ==========
Private Sub Check1_Click()
If Check1.Value = 1 Then
Label1.Caption = "MIIT"
Else
Label1.Caption = "#name"
End If
End Sub

Private Sub Option1_Click()


If Option1.Value = True Then
Label1.Caption = "Male"
End If
End Sub

Private Sub Option2_Click()


If Option2.Value = True Then
Label1.Caption = "Female"
End If
End Sub
============= x ==========

Combo Box
Style = (DropDown, Simple, Dropdown List)
Properties= (Style, Text, List, Sorted)
Method = Add Item, Remove Item, Access Item

Private Sub Command1_Click()


Combo1.AddItem (Text1.Text)
End Sub

Private Sub Command2_Click()


Combo1.RemoveItem (0)
End Sub
=======================x============
Example of Combo & ListBox
Component on Form = Combo1, List1, Text1, Command1
------------Code-------------
Private Sub Command1_Click()
Combo1.AddItem (Text1.Text)
List1.AddItem (Text1.Text)
End Sub

Private Sub Command2_Click()


Combo1.RemoveItem (0)
List1.RemoveItem (0)
End Sub
================x=================
Horizontal & Vertical ScrollBar
Hscroll1 & Vscroll1 = General Properties
= (Min, Max, Value, Large Change, Small Change)

Component on form = Label1, VScroll1, HScroll1


Label1 = Properties = Big Size, Font Face= Arial
hscroll1 & vscroll1 = properties
= Min = 10
= Max = 500
= Large Change = 10
= Small Change = 1

----------- Code -----------


Private Sub HScroll1_Change()
Label1.FontSize = HScroll1.Value
End Sub

Private Sub VScroll1_Change()


Label1.FontSize = VScroll1.Value
End Sub
==============x================
Timer Control
Properties = (Enabled, Interval)
1000 milli second=1 Second
Interval min to max = 1ms to 65535 ms (1 Hour)
Component on Form= (Label1, Timer1)
-----------code-----------
Timer1= Properties = Interval = 1000

Private Sub Timer1_Timer()


Label1.Caption = Format(Now(), "HH:MM:ss")
End Sub
===================
Project on Stop Watch
Component on Form = Text1, Command1, Command 2, Timer1
------- Code -----------
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub

Private Sub Command2_Click()


Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()


Text1.Text = Text1.Text + 1
End Sub
==================x============
Drive Listbox, Directory Listbox, File List Box
Component on Form = Drive1, Dir1, File1, Image1
Form1= Properties= Window State = Maximize
Image1=> Properties => Stretch=True
------Code---------
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()


Dir1.Path = Drive1.Drive
End Sub

Private Sub File1_Click()


Image1.Picture = LoadPicture(Dir1.Path & "\" & File1.FileName)
End Sub
===========x===========
Shape
Properties = (Shape, Fill Style, Border Color, Border Width)
Component on Form1 (Shape1, Timer1)
Timer1= Properties = Interval = 10
----------code ----------
Private Sub Timer1_Timer()
Shape1.Left = Shape1.Left + 50
Shape1.Top = Shape1.Top + 10
End Sub
========= Object & Event @ Code Editor Window ==============

Private Sub Form_Load()


Text1 = 10
Text2 = 2
End Sub

Private Sub Text1_Click()


Text3 = Val(Text1) \ Val(Text2)
Text4 = Val(Text1) Mod Val(Text2)
End Sub

Private Sub Text2_Change()


Text3 = Val(Text1) + Val(Text2)
End Sub

Private Sub Text2_Click()


Text3 = Val(Text1) - Val(Text2)
End Sub

Private Sub Text2_DblClick()


Text3 = Val(Text1) * Val(Text2)
End Sub

Private Sub Text2_GotFocus()


Form1.BackColor = vbRed
End Sub

Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)


Text3 = Val(Text1) / Val(Text2)
End Sub

Private Sub Text2_LostFocus()


Form1.BackColor = vbGreen
End Sub

Private Sub Text2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As


Single)
Form1.BackColor = vbWhite
End Sub

Private Sub Text2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As


Single)
Form1.BackColor = vbBlack
End Sub

Private Sub Text2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As


Single)
Form1.BackColor = vbBlue
End Sub

==============MATH SYMBOL AND COMPARISON =================


Private Sub Command1_Click()
If Val(Text1.Text) < Val(Text2.Text) Then
Text3 = "1st is Smaller"
Else
Text3.Text = "2nd is Smaller"
End If

End Sub

Private Sub Command2_Click()


If Val(Text1.Text) > Val(Text2.Text) Then
Text3 = "1st is Greater"
Else
Text3.Text = "2nd is Greater"
End If
End Sub

Private Sub Command3_Click()


If Val(Text1.Text) = Val(Text2.Text) Then
Text3.Text = "Both are equal"
Else
Text3.Text = "No Equal"
End If
End Sub

Private Sub Command4_Click()


If Val(Text1.Text) > Val(Text2.Text) And Val(Text3.Text) Then
Print "1st is Greater"
ElseIf Val(Text2.Text) > Val(Text3.Text) And Val(Text1.Text) Then
Print "2nd is greater"
Else
Print "3rd is greater"
End If
End Sub
================x================
Component on Form Text1, Text2, Command1
' SELECTION IF STATEMENT

Private Sub Command1_Click()


If Val(Text1.Text) > 0 Then
Text2.Text = "Positive Number"
End If
End Sub
============
'SELECTION IF ....ELSE STATEMENT

Private Sub Command1_Click()


If Val(Text1.Text) > 0 Then
Text2.Text = "Positive Number"
Else
Text2.Text = "Negetive Number"
End If
End Sub
==============
'SELECTION NESTED IF STATEMENT
Private Sub Command1_Click()
t = Val(Text1)
If t > 450 Then
Text2 = "1st Class"
ElseIf t > 350 Then
Text2 = "2nd Class"
ElseIf t > 250 Then
Text2 = "3rd Class"
Else
Text2 = "Fail"
End If
End Sub
=================
'SELECTION SELECT CASE STATEMENT
Private Sub Command1_Click()
Select Case Val(Text1.Text)
Case Is > 450
Text2.Text = "1st Class"
Case Is > 350
Text2.Text = "2nd Class"
Case Is > 250
Text2.Text = "3rd Class"
Case Else
Text2.Text = "Fail"
End Select
End Sub
======================
EXAMPLE OF FOR STATEMENT

Private Sub Command1_Click()


For i = 1 To 200
List1.AddItem i
Next i
End Sub

========================
EXAMPLE OF WHILE......... WEND

Private Sub Command1_Click()


While a <= 200
List1.AddItem a
a = a + 1
Wend
End Sub

=========================
EXAMPLE OF DO.......... WHILE ...... LOOP

Private Sub Command1_Click()


Do While (a <= 20)
Print a
a = a + 1
Loop
End Sub
=======================
EXAMPLE OF WITH........... END WITH STATEMENT

Private Sub Command1_Click()


With Form1
.BackColor = vbRed
.Left = 2000
.Top = 2000
.Height = 5000
.Width = 5000
.Caption = "MIIT Computer"
End With
End Sub
==========================
EXAMPLE OF INPUT BOX

Private Sub Command1_Click()


a = InputBox("Enter the 1st Number", "MIIT Project", 20, 5000, 5000)
For b = 1 To a
Print b
Next
End Sub
========================
EXAMPLE OF MESSAGE BOX

Private Sub Command1_Click()


a = InputBox("Enter the 1st Number", "MIIT Project", 20, 5000, 5000)
b = InputBox("Enter the 2nd Number", "MIIT Project", 32, 5000, 5000)
c = Val(a) + Val(b)
MsgBox "The Addition Result is " & c, vbYesNo, "MIIT Answer"
End Sub
===========================
=============================
How to Insert Extra Components on Form Like Rich Textbox or Common Dialog
======================================================x====
- Right Click on the Toolbox
- Components...
- [Check] = Microsoft Common Dialog Control 6.0
- [Check] = Microsoft Rich textbox Control 6.0
- Apply => Close
================================
Notepad Project
Components to be used (Menubar, RichTextbox1, Commondialog1)
Write Codes
===============
Private Sub clr_Click()
CommonDialog1.ShowColor
RichTextBox1.SelColor = CommonDialog1.Color
End Sub

Private Sub fnt_Click()


CommonDialog1.ShowFont
RichTextBox1.SelFontName = CommonDialog1.FontName
RichTextBox1.SelFontSize = CommonDialog1.FontSize
RichTextBox1.SelBold = CommonDialog1.FontBold
RichTextBox1.SelItalic = CommonDialog1.FontItalic
RichTextBox1.SelUnderline = CommonDialog1.FontUnderline
End Sub

Private Sub nw_Click()


RichTextBox1.Text = ""
End Sub

Private Sub opn_Click()


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

Private Sub prnt_Click()


CommonDialog1.ShowPrinter
End Sub

Private Sub sv_Click()


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

========= NotePad Project ====================


Create a New Project
Project => Add MDI Form => Open
@MDI Form1 => Properties => Windows State = Maximize
@Form1 => Properties => Windows State = Maximize
@Form1 => Properties => MDI Child => True
@ MDI Form => Design all Suitable Menu for Notepad

@MDI Form1 => Add a Microsoft Common Dialog Control 6.0


- Right Click on Toolbox=> Components
- [Check] = Microsoft Common Dialog Control 6.0
- Apply => Ok
- Drag the CommonDialog Control on the MDI Form
@ Form1 => Add Rich Textbox
- Right Click on Toolbox => Components
- [Check] = Microsoft Rich Textbox Control 6.0
- Apply => Ok
- Drag the Rich Textbox Control on the Form1 [BigSize]
---------------------- :|| Write The Codes
||:-----------------------------------
Private Sub clr_Click()
CommonDialog1.ShowColor
Form1.RichTextBox1.SelColor = CommonDialog1.Color
End Sub

Private Sub nw_Click()


Load Form1
Form1.Show
End Sub
Private Sub opn_Click()
CommonDialog1.ShowOpen
Form1.RichTextBox1.LoadFile (CommonDialog1.FileName)
End Sub

Private Sub pnt_Click()


CommonDialog1.ShowPrinter
End Sub

Private Sub sv_Click()


CommonDialog1.ShowSave
Form1.RichTextBox1.SaveFile (CommonDialog1.FileName)
End Sub

Private Sub ft_Click()


CommonDialog1.ShowFont
Form1.RichTextBox1.SelFontName = CommonDialog1.FontName
Form1.RichTextBox1.SelFontSize = CommonDialog1.FontSize
Form1.RichTextBox1.SelBold = CommonDialog1.FontBold
Form1.RichTextBox1.SelItalic = CommonDialog1.FontItalic
Form1.RichTextBox1.SelUnderline = CommonDialog1.FontUnderline
End Sub

================================================
SPLASH SCREEN
- Project => Add Form => SplashScreen => Open
- Delete all the Existing Code
- Add a Timer Control => Properties => Interval = 3000
- Code ------------
Private Sub Timer1_Timer()
Load frmLogin
frmLogin.Show
Unload Me
End Sub
==========================
- PASSWORD SCREEN
- Project => Add Form => Login Dialog => Open
- Delete all the Existing Code
--------- Code -----------
Private Sub cmdOK_Click()
If txtUserName = "saroj" And txtPassword = "miit" Then
Load MDIForm1
MDIForm1.Show
unload frmlogin
Else
MsgBox ("Invalid User")
End If
End Sub
=====================
SETUP THE STARTUP OBJECT
- Project => Project1 Properties => Startup Object => FrmSplash => Ok
==================x==============
PROJECT CALCULATOR
- Create a New Project
- Resize like an Calculator
- Design all suitable Menu
- Add Text1 => Resize Text1 => Text1=Font Face= Arial, Size = 24
- Text1 => Properties => Alignment => Right
- Text1 => Properties => Text => 0
- Assign Command1 => Resize=> Copy & Paste 11times
- Command1(0)=> Caption => .
- Command1(1)=> Caption => 0
- Command1(2)=> Caption => 00
- Command1(3)=> Caption => 1
- Command1(4)=> Caption => 2
- Command1(5)=> Caption => 3
- Command1(6)=> Caption => 4
- Command1(7)=> Caption => 5
- Command1(8)=> Caption => 6
- Command1(9)=> Caption => 7
- Command1(10)=> Caption => 8
- Command1(11)=> Caption => 9
- Add Command2 = Caption = =
- Add Command3 = Caption = +
- Add Command4 = Caption = -
- Add Command5 = Caption = x
- Add Command6 = Caption = /
- Add Command7 = Caption = %
- Add Command8 = Caption = 1/x
- Add Command9 = Caption = M+
- Add Command10 = Caption = M-
- Add Command11 = Caption = MC
- Add Command12 = Caption = MR
- Add Command13 = Caption = C
- Add Command14 = Caption = CE
- Form1 => Caption => Calculator
========= CODE ===============
Dim op As String
Dim a, b, c As Double
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text & Command1(Index).Caption
End Sub

Private Sub Command12_Click()


a = 0
b = 0
c = 0
Text1.Text = ""
End Sub

Private Sub Command2_Click()


b = Val(Text1.Text)
Select Case op
Case "p"
c = a + b
Case "m"
c = a - b
Case "i"
c = a * b
Case "d"
c = a / b
End Select
Text1.Text = c
End Sub
Private Sub Command3_Click()
a = Val(Text1.Text)
op = "p"
Text1.Text = ""
End Sub

Private Sub Command4_Click()


a = Val(Text1.Text)
op = "m"
Text1.Text = ""
End Sub

Private Sub Command5_Click()


a = Val(Text1.Text)
op = "i"
Text1.Text = ""
End Sub

Private Sub Command6_Click()


a = Val(Text1.Text)
op = "d"
Text1.Text = ""
End Sub
=====================================
Adding Toolbar & Status Bar on a Project
=====================================
Creating Images
- Open Wordpad => Print Screen => Close Wordpad
- Open Ms Paint1 => & Paste
- Open Ms Paint2 => Resize Small Size only
- Cut the Small size toolbar Pictures from MsPaint1 and Paste on the MsPaint2
---Save as bmp and specify filename
- Close all Paint1, Paint2,

- Create a New Project


- Right Click Toolbox => Component => [Check]Microsoft Windows Common Control 5.0
[SP2] => Apply => Ok
- Create a Menubar
- Draw a Toolbar1 on the Top
- Assign ImageList1 on the Form1
- Right Click on the ImageList1 => Properties => Images =>
- Insert Pictures => Locate Picture => Open
- Repeat until Last Picture upload to imagelist1
- Toolbar1 Right Click => Properties => General => Image List = ImageList1
- Button =>
- Insert Button => Specify Image Number
- Repeat Upto Last Image
============== Code ====================
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Index
Case 1
MsgBox "new"
Case 2
MsgBox "open"
Case 3
MsgBox "you click on save"
End Select
End Sub
================== Status Bar =================
- Draw a Statusbar1 on form1
- Right Click on Statusbar1 => Properties => Panels
Panel1 => Text => MIIT Computers Pvt. Ltd
Panel2 => Style => Caps
Panel3 => Style => NumLock
Panel4 => Style => ScrollLock
Panel5 => Style => Date
Panel6 => Style => Time

================ Math Symbols ===================


Component on Form1
Text1, Text2, Text3
Command1 = +
Command2 = -
Command3 = /
Command4 = *
Command5 = \
Command6 = Plus
Command7 = &
Command8 = >
Command9 = <
Command10 = <=
Command11 = >=
Command12 = <>
Command13 = And
Command14 = Or
Command15 = =
Command16 = CE
Command17 = Exit
Command18 = Not

Private Sub Command1_Click()


Text3 = Val(Text1) + Val(Text2)
End Sub

Private Sub Command10_Click()


If Val(Text1) <= Val(Text2) Then
Text3 = "1st is lessthan or equal"
Else
Text3 = "2nd is lessthan or equal"
End If
End Sub

Private Sub Command11_Click()


If Val(Text1) >= Val(Text2) Then
Text3 = "1st is greaterthan or equal"
Else
Text3 = "2nd is greaterthan or equal"
End If
End Sub

Private Sub Command12_Click()


If Val(Text1) <> Val(Text2) Then
Text3 = "both are Not equal"
Else
Text3 = "both are Equal"
End If
End Sub
Private Sub Command13_Click()
If Text1 = "miit" And Text2 = "123" Then
Text3 = "Welcome Login"
Else
Text3 = "Sorry Try Again !"
End If
End Sub

Private Sub Command14_Click()


If Text1 = "married" Or Val(Text2) >= 18 Then
Text3 = "You are Insured"
Else
Text3 = "You are not Insured"
End If
End Sub

Private Sub Command15_Click()


If Val(Text1) = Val(Text2) Then
Text3 = "both are equal"
Else
Text3 = "both are different"
End If
End Sub

Private Sub Command16_Click()


Text1 = ""
Text2 = ""
Text3 = ""
End Sub

Private Sub Command17_Click()


Unload Me
End Sub

Private Sub Command18_Click()


Text1.Visible = Not (Text1.Visible)
End Sub

Private Sub Command2_Click()


Text3 = Val(Text1) - Val(Text2)
End Sub

Private Sub Command3_Click()


Text3 = Val(Text1) / Val(Text2)
End Sub

Private Sub Command4_Click()


Text3 = Val(Text1) * Val(Text2)
End Sub

Private Sub Command5_Click()


Text3 = Val(Text1) \ Val(Text2)
End Sub

Private Sub Command6_Click()


Text3 = Text1 + Text2
End Sub
Private Sub Command7_Click()
Text3 = Text1 & Text2
End Sub

Private Sub Command8_Click()


If Val(Text1) > Val(Text2) Then
Text3 = "1st is greater"
Else
Text3 = "2nd is greater"
End If
End Sub

Private Sub Command9_Click()


If Val(Text1) < Val(Text2) Then
Text3 = "1st is smaller"
Else
Text3 = "2nd is smaller"
End If
End Sub
======================x=======================
- Create a New Project (Form1 Autometically Comes)
- Project => Add MDI Form => Open
- Select Form1 => Properties => MDI Child = True
- MDI Form => Right Click => Menu Editor

MenuBar Designing = three Method


1) Ctrl+E
2) Tools => Menu Editor
3) Form Right Click => Menu Editor
Specify Details
Caption = &File
Name = fl
<= or => to setup the Headmenu or Submenu
Shortcut Key =

File
... New
... Open
... Save
... Save As
Edit
... Cut
... Copy
... Paste
Format
... Font
... WordWrap
==========================x==================
Adding Adodc Control

- Create an Access file "address.mdb" => Save 2000 Format


- Save 10 Nos of Records
(Slno, Name, Father's Name, Date of Birth, At, Po, Dist, Pin, Phone)
- Create a vb Project
- Label1 => Caption="AddressBook" => Font = "Arial, Bold, 28, Darkblue"+Underline
- Add => Label2 to Label 10 For AddressBook Caption
(Slno, Name, Father's Name, Date of Birth, At, Po, Dist, Pin, Phone)
- Add => Text 1 to Text 9 Beside these Labels
- Rightclick on Toolbox => Components =>
Check ="Microsoft ADO Data Control 6.0 [OLEDB]
- Add Adodc1 on Form1
- Right Click on Adodc1 => Adodc Properties => Use Connection String => Build =>
Microsoft Jet 4.0 OLEDB Provider => Next => Select Database = Browse => Locate ur
data "Address.mdb" => Open => Test Connection => Advanced => AccessPermission
="ReadWrite" => Ok => Record Source=> Command Type="adCmdTable" => Table="Table1"
=> Apply => Ok

- Select All Textbox => DataSource => Adodc1


- Text1 => Data Field => Slno
- Text2 => Data Field => cname
- Text3 => Data Field => fathername
- Text4 => Data Field => dateofbirth
- Text5 => Data Field => at
- Text6 => Data Field => post
- Text7 => Data Field => dist
- Text8 => Data Field => pin
- Text9 => Data Field => phone

- Add => Command Button 1 to 8


(Caption = AddNew, Delete, First, Last, Previous, Next, Update, Exit)
========= Code ===============
Private Sub Command1_Click()
Adodc1.Recordset.AddNew
End Sub

Private Sub Command2_Click()


Adodc1.Recordset.Update
End Sub

Private Sub Command3_Click()


Adodc1.Recordset.Delete
End Sub

Private Sub Command4_Click()


Adodc1.Recordset.MoveFirst
End Sub

Private Sub Command5_Click()


Adodc1.Recordset.MoveLast
End Sub

Private Sub Command6_Click()


Adodc1.Recordset.MovePrevious
End Sub

Private Sub Command7_Click()


Adodc1.Recordset.MoveNext
End Sub

Private Sub Command8_Click()


Unload Me
End Sub

You might also like