Skip to main content

Microsoft Visual Basic 6.0

Ø  Visual basic project extension name is: .vbp

Ø  Visual basic Form extension name is: .frm

Ø  How to save a project?                  Go to file menuclick save project write form name save

Ø  There are three types of mode: i)Run/Start          ii)Break/Debug                 iii)End

Design:-




Private Sub Command1_Click()
Form1.BackColor = RGB(255, 0, 0)
End Sub

Private Sub Command2_Click()
Form1.BackColor = RGB(0, 255, 0)
End Sub

Private Sub Command3_Click()
Form1.BackColor = RGB(0, 0, 255)
End Sub
Ø  Val: to convert a text to number
Write a program in VB, input  a number and change your label size:
Private Sub Command1_Click()
Label2.FontSize = Text1.Text
End Sub
Write a program in VB input first name, last name and display your full name: 
Private Sub Command1_Click()
Text3.Text = Text1.Text + " " + Text2.Text
End Sub

Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End Sub

Private Sub Command3_Click()
Unload Me
End Sub
Ø  If function:
i)             If condition then
True body
End If
ii)                   If condition then
True body
Else
False body
End If
iii)                 If condition then
True body
ElseIf condition then
True body
Else
False body
End If
Dim:
Ø  Write a program in VB input two numbers and display sum of those numbers:


Ø  Message box:            i) MsgBox            ii)InputBox
Ø  Write a program in VB input a number and check odd or even:

Private Sub Command1_Click()
Dim A As Integer
A = Val(Text1.Text)
If A Mod 2 = 0 Then
MsgBox ("the number is even")
Else
MsgBox ("the number is odd")
End If
End Sub
Ø  write a program in VB input your age and check voter or non voter:
Private Sub Command1_Click()
Dim A As Integer
A = Val(Text1.Text)
If A >= 18 Then
Label3.Caption = "Voter"
Else
Label3.Caption = "Non Voter"
End If
End Sub
Ø  write a program in VB input two numbers and check maximum of those numbers:
Private Sub Command1_Click()
Dim a, b As Integer
a = Val(Text1.Text)
b = Val(Text2.Text)
If a > b Then
Label4.Caption = a
Else
Label4.Caption = b
End If
End Sub
Ø  write a program in VB input three numbers and display maximum of those numbers and minimum of those numbers:
Dim a, b, c, d As Integer
Private Sub Command1_Click()
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If a < b Then
d = b
ElseIf a > b Then
d = a
End If
If c > d Then
MsgBox (c)
Else
MsgBox (d)
End If
End Sub

Private Sub Command2_Click()
a = Val(Text1.Text)
b = Val(Text2.Text)
c = Val(Text3.Text)
If a > b Then
d = b
ElseIf a < b Then
d = a
End If
If c < d Then
MsgBox (c)
Else
MsgBox (d)
End If
End Sub



Ø  len(“text”)4
Ø  str(“5”+”5”)55
Ø  Ucase(“Ram”)RAM
Ø  Lcase(“Ram”)ram
Ø  Asc(“A”)65
Ø  Chr(65)A
Ø  StrReverse("Ram")maR


Ø  Len:

Private Sub Command1_Click()
Dim a As String
Dim b As Integer
a = Text1.Text
b = Len(a)
Label3.Caption = b
End Sub
Ø  Ucase:


Private Sub Command1_Click()
Dim a, b As String
a = Text1.Text
b = UCase(a)
Label3.Caption = b
End Sub
Ø  Lcase:


Private Sub Command1_Click()
Dim a, b As String
a = Text1.Text
b = LCase(a)
Label3.Caption = b
End Sub
Ø  Asc:


Private Sub Command1_Click()
Dim a As String
Dim b As Integer
a = Text1.Text
b = Asc(a)
Label3.Caption = b
End Sub
Ø  Chr:


Private Sub Command1_Click()
Dim a As String
Dim b As Integer
b = Text1.Text
a = Chr(b)

Label3.Caption = a
End Sub
Ø  StrReverse:
Private Sub Command1_Click()
Dim a, b As String
a = Text1.Text
b = StrReverse(a)
Label3.Caption = b
End Sub
Ø  Write a program in VB input a string and check the string palindrome or not:
Private Sub Command1_Click()
Dim a, b As String
a = Text1.Text
b = StrReverse(a)
If a = b Then
Label3.Caption = "palindrom"
Else
Label3.Caption = "not palindrom"
End If
End Sub
Ø  Message box:    two types of        i)MsgBox            ii)InputBox

Ø  InputBox:

Private Sub Form_Load()
Dim a, b, c As Integer
a = InputBox("Enter your 1st number")
b = InputBox("Enter your 2nd number")
c = Val(a) + Val(b)
MsgBox ("sum of two numbers is:-" + Str(c))
End Sub
Ø  Circle program :

Private Sub Form_Load()
Form1.Cls
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

        Circle (X, Y), 180, RGB(180, 65, 10) * Rnd

End Sub
Ø  Color coding:
Private Sub Form_Load()
Form1.BackColor = RGB(0, 0, 0)
Label4.AutoSize = True
HScroll1.Min = 0
HScroll1.Max = 255
HScroll2.Min = 0
HScroll2.Max = 255
HScroll3.Min = 0
HScroll3.Max = 255
End Sub
Private Sub hscroll1_change()
Dim R, G, B As Integer
R = HScroll1.Value
G = HScroll2.Value
B = HScroll3.Value
Form1.BackColor = RGB(R, G, B)
Label4.Caption = "RGB(" + Str(R) + "," + Str(G) + "," + Str(B) + ")"
End Sub
Private Sub hscroll2_change()
Dim R, G, B As Integer
R = HScroll1.Value
G = HScroll2.Value
B = HScroll3.Value
Form1.BackColor = RGB(R, G, B)
Label4.Caption = "RGB(" + Str(R) + "," + Str(G) + "," + Str(B) + ")"
End Sub
Private Sub hscroll3_change()
Dim R, G, B As Integer
R = HScroll1.Value
G = HScroll2.Value
B = HScroll3.Value
Form1.BackColor = RGB(R, G, B)
Label4.Caption = "RGB(" + Str(R) + "," + Str(G) + "," + Str(B) + ")"
End Sub
Ø  Timer:
By default timer interval=0
1 second = 1000 interval
Private Sub Form_Load()
Timer1.Interval = 1
Label1.AutoSize = True
Label1.FontSize = 18
Label1.ForeColor = vbRed
Label1.Left = 0
End Sub
Private Sub timer1_timer()
Label1.Left = Label1.Left + 15
If Label1.Left >=Form1.Width Then
Label1.Left = 0
End If
End Sub
Ø  Loop:     three types of loop          i)for,      ii)while,                iii)do-while
Ø  For:        for interval testing step increment/decrement
Ø  Print the series 1,2,3,………….upto 10
Private Sub Command1_Click()
Dim I, A As Integer
A = 1
For I = 1 To 10
Print A
A = A + 1
Next I
End Sub
_____________OR__________________
Private Sub Command1_Click()
Dim I As Integer
For I = 1 To 10
Print I
Next I
End Sub
Ø  Print the series 100,95,90,……….. up to 10 terms:
Private Sub Command1_Click()
Dim I, A As Integer
A = 100
For I = 1 To 10
Print A
A = A - 5
Next I
End Sub
Ø  Print the series 1,3,5,……….up to 10 term:
Private Sub Command1_Click()
Dim I, A As Integer
A = 1
For I = 1 To 10
Print A
A = A + 2
Next I
End Sub
Ø  Print the series 100,95,85,70………..up to ten terms:
Private Sub Command1_Click()
Dim I, A, B As Integer
A = 100
B = 5
For I = 1 To 10
Print A
A = A - B
B = B + 5
Next I
End Sub





Private Sub Command1_Click()
Dim P, D, I As Integer
Cls
List1.Clear
P = 1
D = 0
For I = 1 To 8 Step 1
Print P
List1.AddItem (P)
P = P + D
D = P - D
Next I

End Sub


Ø  COMPUTER print order:
Private Sub Command1_Click()
Dim A, B As String
Dim I, L As Integer
A = Text1.Text
L = Len(A)
For I = 1 To L
B = Mid(A, I, 1)
Print B
Next I
End Sub
Ø  RETUPMOC:

Private Sub Command1_Click()
Dim A, B, r As String
Dim I, L As Integer
A = Text1.Text
L = Len(A)
r = StrReverse(A)
For I = 1 To L
B = Mid(r, I, 1)
Print B
Next I
End Sub
Ø  Write a program in VB input 3 numbers and display maximum number using message box:
Private Sub Command1_Click()
Dim A, B, C, M As Integer
A = Val(Text1.Text)
A = Val(Text2.Text)
A = Val(Text3.Text)            
If A < B Then
M = B
End If
If B < C Then
M = C
End If
MsgBox ("the maximum number is:" + Str(M))
End Sub
Ø  Combo box:

Private Sub Form_Load()
Combo1.AddItem "Ran"
Combo1.AddItem "Shyam"
Combo1.AddItem "Jodu"
End Sub
Ø  Write a program in VB input two numbers and use operators from combo box ‘+’ , ’-’ , ’*’ ,  ’/’and display result
Private Sub Command1_Click()
Dim a, b As Integer
Dim c as Double
a = Val(Text1.Text)
b = Val(Text2.Text)
If Combo1.Text = "+" Then
c = a + b
ElseIf Combo1.Text = "-" Then
c = a - b
ElseIf Combo1.Text = "*" Then
c = a * b
ElseIf Combo1.Text = "/" Then
c = a / b
End If
Label5.Caption = c
End Sub

Private Sub Form_Load()
Combo1.AddItem "+"
Combo1.AddItem "-"
Combo1.AddItem "*"
Combo1.AddItem "/"
End Sub
Ø  Write a program in VB input  a number and check the number odd or even when the  number is even save the number in list1 when the number is odd save the number in last2:
Private Sub Command1_Click()
Dim a As Integer
a = Val(Text1.Text)
If a Mod 2 = 0 Then
List1.AddItem (a)
Text1.Text = ""
Text1.SetFocus
Else
List2.AddItem (a)
Text1.Text = ""
Text1.SetFocus
End If
End Sub

Private Sub Command2_Click()
List1.Clear
End Sub

Private Sub Command3_Click()
List2.Clear
End Sub
Ø  Write a program in VB input your friends name and add the names in  combo box:          1.count how many friends. 2.delete your selected friend name.
Private Sub Command1_Click()
Dim s As String
Dim n As Integer
s = Text1.Text
n = Combo1.ListCount
If Len(s) <= 0 Then
MsgBox ("enter your friend's name")
Else
Combo1.AddItem UCase(s)
Text1.Text = ""
Text1.SetFocus
End If
n = Combo1.ListCount
Label4.Caption = n
End Sub

Private Sub Command2_Click()
Dim i, n As Integer
i = Combo1.ListIndex
If i < 0 Then
MsgBox ("select friend name")
Else
Combo1.RemoveItem (i)
End If
n = Combo1.ListCount
Label4.Caption = n
End Sub
Ø  Shapes:
Six types of shapes
0-Rectangle
1-Square
2-oval
3-Circle
4-rounded rectangle
5-rounded square
Ø  Fill styles:
8 types of fill styles
0-Solid
1-transpard
2-horizontal line
3-vertical line
4-upward diagonal
5-downward diagonal
6-cross
7-diagonal cross
Ø   

Select shapes one by oneàgo to properties windowàfill styleà0-Solid

Private Sub Form_Load()
Timer1.Interval = 100
End Sub

Private Sub Timer1_Timer()
Shape1.FillColor = RGB((Rnd * 255), (Rnd * 255), (Rnd * 255))
Shape2.FillColor = RGB((Rnd * 255), (Rnd * 255), (Rnd * 255))
Shape3.FillColor = RGB((Rnd * 255), (Rnd * 255), (Rnd * 255))
Shape4.FillColor = RGB((Rnd * 255), (Rnd * 255), (Rnd * 255))
End Sub
Ø   


Private Sub Command1_Click()
Shape1.Shape = 0
Shape1.FillStyle = 2
Shape1.BorderColor = RGB(25, 200, 25)
End Sub

Private Sub Command2_Click()
Shape1.Shape = 1
Shape1.FillStyle = 3
Shape1.BorderColor = RGB(25, 200, 25)
End Sub

Private Sub Command3_Click()
Shape1.Shape = 2
Shape1.FillStyle = 4
Shape1.BorderColor = RGB(25, 200, 25)
End Sub

Private Sub Command4_Click()
Shape1.Shape = 3
Shape1.FillStyle = 5
Shape1.BorderColor = RGB(25, 200, 25)
End Sub

Private Sub Command5_Click()
Shape1.Shape = 4
Shape1.FillStyle = 6
Shape1.BorderColor = RGB(25, 200, 25)
End Sub

Private Sub Command6_Click()
Shape1.Shape = 5
Shape1.FillStyle = 7
Shape1.BorderColor = RGB(25, 200, 25)
End Sub

Private Sub Command7_Click()
Unload Me
End Sub

Private Sub Form_Load()
HScroll1.Min = 1
HScroll1.Max = 36
End Sub

Private Sub HScroll1_Change()
Shape1.BorderWidth = HScroll1.Value
End Sub
Ø   

Private Sub Command1_Click()
Dim dob As Date
Dim cd, cm, cy, yd, ym, yy As Integer
dob = DateValue(Text1.Text)
cd = Day(Now)
cm = Month(Now)
cy = Year(Now)
yd = Day(dob)
ym = Month(dob)
yy = Year(dob)
If cd < yd Then
cd = cd + 30
ym = ym + 1
End If
d = cd - yd
If cm < ym Then
cm = cm + 12
yy = yy + 1
End If
m = cm - ym
If cy < yy Then
MsgBox ("check your age")
Else
y = cy - yy
End If
Label6.Caption = y
Label7.Caption = m
Label8.Caption = d
End Sub
  •  




Private Sub Command1_Click()
If Check1.Value = 1 Then
Label1.FontSize = 18
Label2.FontSize = 18
Label3.FontSize = 18
Else
Label1.FontSize = 14
Label2.FontSize = 14
Label3.FontSize = 14
End If

If Check2.Value = 1 Then
Label1.FontBold = True
Label2.FontBold = True
Label3.FontBold = True
Else
Label1.FontBold = False
Label2.FontBold = False
Label3.FontBold = False
End If

If Check3.Value = 1 Then
Label1.FontItalic = True
Label2.FontItalic = True
Label3.FontItalic = True
Else
Label1.FontItalic = False
Label2.FontItalic = False
Label3.FontItalic = False
End If

If Check4.Value = 1 Then
Label1.FontUnderline = True
Label2.FontUnderline = True
Label3.FontUnderline = True
Else
Label1.FontUnderline = False
Label2.FontUnderline = False
Label3.FontUnderline = False
End If

If Option1.Value = True Then
Label1.ForeColor = RGB(255, 0, 0)
Label2.ForeColor = RGB(255, 0, 0)
Label3.ForeColor = RGB(255, 0, 0)
ElseIf Option2.Value = True Then
Label1.ForeColor = RGB(0, 255, 0)
Label2.ForeColor = RGB(0, 255, 0)
Label3.ForeColor = RGB(0, 255, 0)
ElseIf Option3.Value = True Then
Label1.ForeColor = RGB(0, 0, 255)
Label2.ForeColor = RGB(0, 0, 255)
Label3.ForeColor = RGB(0, 0, 255)
ElseIf Option4.Value = True Then
Label1.ForeColor = RGB(0, 0, 0)
Label2.ForeColor = RGB(0, 0, 0)
Label3.ForeColor = RGB(0, 0, 0)
End If

Dim a, b As Integer
Dim c as Double
a = Val(Text1.Text)
b = Val(Text2.Text)
If Combo1.Text = "+" Then
c = a + b
ElseIf Combo1.Text = "-" Then
c = a - b
ElseIf Combo1.Text = "*" Then
c = a * b
ElseIf Combo1.Text = "/" Then
c = a / b
End If
Label4.Caption = c

End Sub

Private Sub Form_Load()
Combo1.AddItem ("+")
Combo1.AddItem ("-")
Combo1.AddItem ("*")
Combo1.AddItem ("/")
End Sub


Ø  Write a program in VB display picture using drive list box, dirlist box, file list box and image:
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(File1.Path + "\" + File1.FileName)
End Sub

Ø  How to insert form?
Go to stander toolbar click add formopen
Ø  Write a program in VB, check password:
Private Sub Command1_Click()
If Text1.Text = "bappasaikh1994" Then
If Text2.Text = "8686632086" Then
Form2.Show
Unload Me
Else
MsgBox ("check your password")
End If
Else
MsgBox ("check your username")
Text1.Text = ""
End If
End Sub

Private Sub Command2_Click()
Unload Me

End Sub
Ø  Menu editor(ctrl+E):
Ø  How to open menu editor?         Go to stander toolbarclick tools menuclick menu editor



Ø  How to open rich text box and common dialog?

Go to project menucomponents…..

Ø  Change name in properties:
RichTextBox1R
CommonDialog 1C
Ø  View code:



Private Sub Form_Resize()
R.Width = Form1.Width
R.Height = Form1.Height - 950
End Sub

Private Sub New_Click()
R.Text = ""
End Sub

Private Sub Open_Click()
C.ShowOpen
R.FileName = C.FileName
End Sub

Private Sub Save_Click()
R.Visible = True
C.ShowSave
R.SaveFile (C.FileName)
End Sub

Private Sub SaveAs_Click()
R.Visible = True
C.ShowSave
R.SaveFile (C.FileName)
End Sub

Private Sub Print_Click()
C.Action = 5
End Sub

Private Sub Exit_Click()
Unload Me
End Sub

Private Sub Cut_Click()
Clipboard.Clear
Clipboard.SetText (R.SelText)
R.SelText = ""
End Sub

Private Sub Copy_Click()
Clipboard.Clear
Clipboard.SetText (R.SelText)
End Sub

Private Sub Paste_Click()
R.SelText = Clipboard.GetText
End Sub

Private Sub Font_Click()
R.Visible = True
C.Flags = cdlCFBoth Or cdlCFEffects
C.ShowFont
R.SelFontName = C.FontName
R.SelFontSize = C.FontSize
R.SelBold = C.FontBold
R.SelItalic = C.FontItalic
R.SelUnderline = C.FontUnderline
R.SelStrikeThru = C.FontStrikethru
R.SelColor = C.Color
End Sub

Private Sub Left_Click()
R.SelAlignment = 0
End Sub

Private Sub Right_Click()
R.SelAlignment = 1
End Sub

Private Sub Center_Click()
R.SelAlignment = 2
End Sub










Comments