Docsity

Visual Basic Notes - Visual set - Engeneering, Study notes of Computer Applications

Toggle sidebar
bg1
VISUAL BASIC
PREPARED BY MR.P.PERINPA KUMAR Page 1
VISUAL BASIC
Software
System Software Application Software
Application package Program / Language
Visual Basic is a compiler. It’s used to create / develop new applications software
Compiler
The compiler is convert 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
III. Write the Coding
IV. Save your Project
• .frm
• .vbp
V. Test your Project
•
Word processing
• Sprat sheet
• Accounting
• Graphic
• Multimedia
• Etc………
•
Visual Basic
• C++
• C Language
• C #
• Java
• Java#
•
Etc………
Design time
Run time
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

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

VISUAL BASIC

Software

System Software Application Software

Application package Program / Language

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

Compiler

The compiler is convert 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 III. Write the Coding IV. Save your Project

  • .frm
  • .vbp V. Test your Project
  • Word processing
  • Sprat sheet
  • Accounting
  • Graphic
  • Multimedia
  • Etc………
  • Visual Basic
  • C++
  • C Language
  • C #
  • Java
  • Java#
  • Etc………

Design time

Run time

Tools Name Properties Short Name Label Caption lbl

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 Size = 20

III. Write the coding To get code window

  • Double click on the form
  • View menu Code
A

ab

√

Operators

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

II. Relational operator a. > Greater than b. < Less than c. >= Grater than or Equal to d. <= Less than or Equal to e. = Equal to f. != or <> Not equal to

III. Increment & Decrement operator a. ++ Postfix Increment b. -- Postfix Decrement c. ++ Prefix Increment d. -- Prefix Decrement

IV. Assign operator a. += Assign Add b. -= Assign Subtract c. /= Assign Divide d. *= Assign Multiple

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

txt

txt

lbl

cmd1 cmd2 cmd

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 Size = 14 Name = lbl

Text

1. Name = txt Text = “” Font Font = Arial black Size = 14 2. Name = txt Text = “” Font Font = Arial black Size = 14

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

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) End If

Sample (Write the program to find the big or small number)

Coding

Private Sub cmd1_Click() If (Txt1.Text > Txt2.Text) Then lbl4.Caption = "Number 1 is Big" Else lbl4.Caption = "Number 2 is Big" End If End Sub

Private Sub cmd2_Click() If (Txt1.Text < Txt2.Text) Then lbl4.Caption = "Number 1 is Small"

cmd

cmd

cmd2 cmd

lbl

txt1 txt

Condition Basic salary> Bonus=Basic salary x 10% Incentive=

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

Syntax Inputbox (“Prompt”,”Title”,”Default”) Eg: a = InputBox "Your ID", "Enter your ID", "ID"

Massage Box

Syntax Massagebox (“Prompt”,”Button”,”Title”) Eg: b = MsgBox("Invalide ID", vbOKCancel, "Error")

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

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

Syntax If (Conditions) Then (Statements) ElseIF (Conditions) Then (Statements) ElseIF (Conditions) Then (Statements) ………………………… ………………………… ………………………… ………………………… Else (Statements) End If

Example (Write the program to find out the result)

Condition Marks>=85 Grade=A Marks>=65 Grade=B Marks>=45 Grade=C Marks>=25 Grade=S Marks<25 Grade=W

cmd1 cmd2 cmd

lbl

txt

txt

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 lbl3.Caption = "Fail" End If End Sub Private Sub cmd2_Click()

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

Re exam Visual Basic

Re exam C++

Re exam Java#

txt1.Text = "" txt2.Text = "" txt3.Text = "" txt4.Text = "" lbl1.Caption = "" lbl2.Caption = "" lbl3.Caption = "" End Sub

Private Sub cmd3_Click() End End Sub

III. Nexted IF

Syntax

If (Conditions) Then If (Conditions) Then If (Conditions) Then (Statements) Else (Statements) EndIf Else (Statements) EndIf Else (Statements) EndIf

Example (Write a program to find the Leap year)

cmd1 cmd2 cmd

lbl

lbl

txt

txt

Example (Write a program of ABC CO Salary sheet)

Condition

Experience >10 years Basic salary > Rs.

Experience >10 years Basic salary < Rs.

Experience <10 years Basic salary > Rs.

Experience <10 years Basic salary < Rs.

EPF = Basic salary x 8% Coding

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%

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

Private Sub another_Click() empname.Text = "" title.Text = "" experience.Text = "" basicsalary.Text = "" bonus.Caption = "" incentive.Caption = "" grosspay.Caption = "" epf.Caption = "" nopay.Text = "" advance.Text = "" netsalary.Caption = "" End Sub

Private Sub calculate_Click() If (experience.Text > 10) Then If (basicsalary.Text > 25000) Then bonus.Caption = basicsalary.Text * 0. incentive.Caption = basicsalary.Text * 0. Else bonus.Caption = basicsalary.Text * 0. incentive.Caption = basicsalary.Text * 0. End If Else If (basicsalary.Text < 25000) Then bonus.Caption = basicsalary.Text * 0. incentive.Caption = basicsalary.Text * 0. Else bonus.Caption = basicsalary.Text * 0. incentive.Caption = basicsalary.Text * 0. End If End If grosspay.Caption = Val(basicsalary.Text) + Val(bonus.Caption) + Val(incentive.Caption) epf.Caption = basicsalary.Text * 0. netsalary.Caption = Val(grosspay.Caption) - Val(epf.Caption) - Val(nopay.Text) - Val(advance.Text) End Sub

Private Sub end_Click() End End Sub