Docsity

Visual Basic Notes - A compiler, Study notes of Computer Applications

Toggle sidebar
bg1
VISUAL BASIC
Software
System
Software Ap
plication Software
Application package Program / Language
Visual Basic is a compiler. It’s used to create / develop new applications software
Compiler
The compiler is converting the Human Language to Computer Language with
ASCII value.
A 65 01000001
Human Language ASCII Computer Language
ASCII: American Standard Code for Information Interchange
To open Visual Basic 6.0
• Click start
• Select the program
• Select MS Visual Basic 6.0
• Click MS Visual Basic 6.0
Step to create the project
I.
Design the Form
II. Set the Properties
VISUAL BASIC
Page 1 PREPARED BY MR.P.PERINPAKUMAR
• Visual Basic
• C++
• C Language
• C #
• Java
• Java#
• Word processing
• Sprat sheet
• Accounting
• Graphic
• Multimedia
• Etc………
Design time
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Visual Basic Notes - A compiler and more Study notes Computer Applications in PDF only on Docsity!

VISUAL BASIC

Software

System Software Ap plication Software

Application package Program / Language

Visual Basic is a compiler. It’s used to create / develop new applications software

Compiler

The compiler is converting the Human Language to Computer Language with ASCII value. A 65 01000001

Human Language ASCII Computer Language

ASCII: American Standard Code for Information Interchange

To open Visual Basic 6.

  • Click start
  • Select the program
  • Select MS Visual Basic 6.
  • Click MS Visual Basic 6.

Step to create the project

I.

Design the Form II. Set the Properties

Page 1 PREPARED BY MR.P.PERINPAKUMAR

  • Visual Basic
  • C++
  • C Language
  • C #
  • Java
  • Java#
  • Word processing
  • Sprat sheet
  • Accounting
  • Graphic
  • Multimedia
  • Etc………

Design time

III. Write the Coding IV. Save your Project

  • .frm

.vbp V. Test your Project

Tools Name Properties Short Name

A

Label Caption lbl

ab

Text box Text txt

Command button Caption cmd

√

Check box Caption chk

Option button (Radio button)

Caption opt

Frame Caption fra

Sample project

I. Design the form

II. Set the properties Name = form Caption = First project Fore color = red Font Fount = Arial black Style = Bold PREPARED BY MR.P.PERINPAKUMARPage 2

Run time

  • Press F5 on the Key board

Data Types

Int = Integer : 7434 (Max 4 Digit) Long Int = Long Integer : 479492494 (Max 10 Digit) Double = Floating point number : 7432.47 (Max 2 Digit after decimal point) Float = Floating point number : 7432.47 (Max 6 Digit after decimal point) Char = Character : A (1 Character) String = String : A BCD

Operators

I. Arithmetic operators I.a. + Addition (a + b) I.b. - Subtraction (a - b) I.c. / Division (a / b) I.d. \ Integer Division (a \ b), (Here result is integer) I.e. * Multiplication (a * b) I.f. (^) Mod Modulo (a Mod b), (Reminder only for Integer value) I.g. ^ Exponentiation (N ^ m)=(N m^ )

II. Relational operator I.h. > Greater than I.i. < Less than I.j. >= Greater than or Equal to I.k. <= Less than or Equal to I.l. = Equal to I.m. != or <> Not equal to

III. Increment & Decrement operator I.n. ++ Postfix Increment I.o. (^) -- Postfix Decrement I.p. ++ Prefix Increment I.q. -- Prefix Decrement

IV. Assign operator I.r. += Assign Add

PREPARED BY MR.P.PERINPAKUMARPage 4

I.s. -= Assign Subtract I.t. /= Assign Divide I.u. *= Assign Multiple

Sample 1- ( write a program answer of Add Two Numbers)

Label

  1. Caption = number Font Font = Arial black Size = 14
  2. Caption = number Font Font = Arial black Size = 14
  3. Caption = Total Font Font = Arial black Size = 14
  4. Caption = “” Font Font = Arial black

Page 5 PREPARED BY MR.P.PERINPAKUMAR

lbl1txt2txt1cmd3cmd2cmd

End End Sub

Private Sub cmd3_Click() Txt1.Text = "" Txt2.Text = "" lbl4.Caption = "" End Sub

Sample (Write program sample calculator)

Coding

Private Sub cmd1_Click() lbl4.Caption = Val(Txt1.Text) + Val(Txt2.Text) End Sub

Private Sub cmd2_Click() lbl4.Caption = Val(Txt1.Text) - Val(Txt2.Text) End Sub

Private Sub cmd3_Click() lbl4.Caption = Val(Txt1.Text) / Val(Txt2.Text) End Sub

Private Sub cmd4_Click() lbl4.Caption = Val(Txt1.Text) * Val(Txt2.Text) End Sub

Page 7 PREPARED BY MR.P.PERINPAKUMAR

lbl1cmd6cmd7cmd5cmd4cmd3cmd2cmd1txt2txt

Private Sub cmd5_Click() lbl4.Caption = Val(Txt1.Text) Mod Val(Txt2.Text) End Sub

Private Sub cmd6_Click() Txt1.Text = "" Txt2.Text = "" lbl4.Caption = "" End Sub

Private Sub cmd7_Click() End End Sub

Controlling Statement

  1. If Statement
  2. Looping Statement
  3. Case Statement

If Statement

The If statement is a logical function. There are have three type. These are I. If ………….. Else …………….. Statement II. If ………….. Else If …………... Statement III.Nexted IF

I. If …………. Else …………… Statement

Syntax If (Conditions) Then (Statements) Else (Statements)

PREPARED BY MR.P.PERINPAKUMARPage 8

Txt2.Text = "" lbl4.Caption = "" End Sub

Private Sub cmd4_Click() End End Sub

Sample (Write a program sample salary sheet)

Condition Basic salary> Bonus=Basic salary x 10% Incentive= PREPARED BY MR.P.PERINPAKUMARPage 10

txt7txt6txt5lbl3lbl2txt4txt1txt2txt3lbl1cmd2cmd3cmd

Basic salary< Bonus=Basic salary x 5% Incentive=

Coding Private Sub cmd1_Click() If (txt3.Text > 10000) Then lbl1.Caption = Val(txt3.Text) * 10 / 100 lbl2.Caption = 750 Else lbl1.Caption = Val(txt3.Text) * 5 / 100 lbl2.Caption = 500 End If lbl3.Caption = Val(txt3.Text) + Val(txt4.Text) + Val(lbl1.Caption) + Val(lbl2.Caption) lbl4.Caption = Val(lbl3.Caption) - Val(txt5.Text) - Val(txt6.Text) End Sub

Private Sub cmd2_Click() txt1.Text = "" txt2.Text = "" txt3.Text = "" txt4.Text = "" lbl1.Caption = "" lbl2.Caption = "" lbl3.Caption = "" txt5.Text = "" txt6.Text = "" lbl4.Caption = "" End Sub

Private Sub cmd3_Click() End End Sub

Input Box & Massage Box

Input Box

Page 11 PREPARED BY MR.P.PERINPAKUMAR

Coding Page 13 PREPARED BY MR.P.PERINPAKUMAR

txt1txt2txt3txt4lbl1lbl2lbl3txt5txt6lbl4cmd2cmd3cmd

Private Sub cmd1_Click() If (txt3.Text > 10000) Then lbl1.Caption = Val(txt3.Text) * 10 / 100 lbl2.Caption = 750 Else lbl1.Caption = Val(txt3.Text) * 5 / 100 lbl2.Caption = 500 End If lbl3.Caption = Val(txt3.Text) + Val(txt4.Text) + Val(lbl1.Caption) + Val(lbl2.Caption) lbl4.Caption = Val(lbl3.Caption) - Val(txt5.Text) - Val(txt6.Text) End Sub

Private Sub cmd2_Click() txt1.Text = "" txt2.Text = "" txt3.Text = "" txt4.Text = "" lbl1.Caption = "" lbl2.Caption = "" lbl3.Caption = "" txt5.Text = "" txt6.Text = "" lbl4.Caption = "" End Sub

Private Sub cmd3_Click() End End Sub

Private Sub Form_Load() a = InputBox("Your ID", "Enter your ID", "ID") If (a = "inpan") Then Form1.Visible = True Else b = MsgBox("Invalide ID", vbOKCancel, "Error") End If End Sub

II. If …………. ElseIF …………… Statement

PREPARED BY MR.P.PERINPAKUMARPage 14

Coding Private Sub cmd1_Click() If (txt2.Text >= 85) Then lbl1.Caption = "A" ElseIf (txt2.Text >= 65) Then lbl1.Caption = "B" ElseIf (txt2.Text >= 45) Then lbl1.Caption = "C" ElseIf (txt2.Text >= 25) Then lbl1.Caption = "S" Else lbl1.Caption = "W" End If End Sub

Private Sub cmd2_Click() txt1.Text = "" txt2.Text = "" lbl1.Caption = "" End Sub

Private Sub cmd3_Click() End End Sub

Example (Write the program to find the computer result)

PREPARED BY MR.P.PERINPAKUMARPage 16

lbl3lbl2lbl1txt3txt2txt1cmd3cmd2cmd

Condition

Visual Basic >= 60 C++ >= 60 Java# >=

Visual Basic < 60 C++ >= 60 Java# >=

Visual Basic >= 60 C++ < 60 Java# >=

Visual Basic >= 60 C++ >= 60 Java# <

Otherwise Fail

Coding Private Sub cmd1_Click() lbl1.Caption = Val(txt2.Text) + Val(txt3.Text) + Val(txt4.Text) lbl2.Caption = lbl1.Caption / 3 If (txt2.Text >= 60) And (txt3.Text >= 60) And (txt4.Text >= 60) And (lbl2.Caption >= 88) Then lbl3.Caption = "Good pass" ElseIf (txt2.Text >= 60) And (txt3.Text >= 60) And (txt4.Text >= 60) And (lbl2.Caption < 88) Then lbl3.Caption = "Standard pass" ElseIf (txt2.Text < 60) And (txt3.Text >= 60) And (txt4.Text >= 60) Then lbl3.Caption = "Re exam Visual Basic" ElseIf (txt2.Text >= 60) And (txt3.Text < 60) And (txt4.Text >= 60) Then lbl3.Caption = "Re exam C++" ElseIf (txt2.Text >= 60) And (txt3.Text >= 60) And (txt4.Text < 60) Then lbl3.Caption = "Re exam Java#" Else Page 17 PREPARED BY MR.P.PERINPAKUMAR

Average >= 88 Good pass Average <= 88 Standard pass

Re exam Visual BasicRe exam C++Re exam Java#

Condition Year mod 4 = Year mod 100! 0

Or Year mod 4= Year mod 100= Year mod 400=

Coding Private Sub cmd1_Click() If (txt1.Text Mod 4 = 0) Then If (txt1.Text Mod 100 = 0) Then If (txt1.Text Mod 400 = 0) Then lbl1.Caption = "This year is leap year" Else lbl1.Caption = "This year is not leap year" End If Else lbl1.Caption = "This year is leap year" End If Else lbl1.Caption = "This year is not leap year" End If End Sub

Private Sub cmd2_Click() txt1.Text = "" lbl1.Caption = "" End Sub

Private Sub cmd3_Click() Page 19 PREPARED BY MR.P.PERINPAKUMAR

Leap year otherwise Not Leap year

End End Sub

Example (Write a program of ABC CO Salary sheet)

Condition

Experience >10 years Basic salary > Rs.

Experience >10 years Basic salary < Rs.

PREPARED BY MR.P.PERINPAKUMARPage 20

Bonus = Basic salary x 25% Incentive = Basic salary x 5%

Bonus = Basic salary x 10% Incentive = Basic salary x 3%

Bonus = Basic salary x 15% Incentive = Basic salary x 4%