BS CTC

v     Microsoft Visual Basic 6.0

v Toolbox:

Ø  Object

v Properties:

Ø  Value

v  Even:

Ø  Code

Example:1 

                        Private Sub Form_Load()

Text1.Text = "Welcome to Visual basic World"

End Sub

Example:2  

                        Private Sub Command1_Click()

Label1.Caption = "Ahmad"

End Sub

Example: 3

 

Example: 4

 

Example: 5

Private Sub Command3_Click()

Text1.text=" "

End Sub

Example: 6

                     Private Sub Command4_Click()

End

End Sub

 Example: 7

Private Sub Command1_Click()

Text2.Text = Text1.Text

Text2.FontSize = 28

End Sub

 Example: 8

Private Sub Command2_Click()

Form2.Show

End Sub

Example: 9

Private Sub Command2_Click()

Form2.Hide

End Sub

Example: 10

Private Sub Command1_Click()

List1.AddItem (Text1.Text)

Text1.Text = ""

End Sub

Example: 11

Private Sub Option1_Click()

Form1.BackColor = vbGreen

End Sub

 

Private Sub Option2_Click()

Form1.BackColor = vbBlue

End Sub

 

Private Sub Option3_Click()

Form1.BackColor = vbRed

End Sub

 Example: 12

Private Sub Check1_Click()

Text1.FontBold = Check1.Value

End Sub

 

Private Sub Check2_Click()

Text1.FontItalic = Check2.Value

End Sub

 

 Private Sub Check3_Click()

Text1.FontUnderline = Check3.Value

End Sub

Example: 13

Private Sub Combo1_Change()

Text1.FontSize = Val(Combo1.Text)

End Sub

 

Private Sub Form_Load()

Dim k As Integer

k = 1

For i = 1 To 100

Combo1.AddItem Str(k)

k = k + 1

Next

End Sub

Example: 14

Private Sub Command1_Click()

MsgBox "WELL COME TO VISUAL BASIC 6.0"

End Sub

Example: 15

Private Sub Command1_Click()

List1.AddItem Text1.Text

Text1.Text = ""

End Sub

 

Private Sub Command2_Click()

List1.Clear

End Sub

 

Private Sub Command3_Click()

MsgBox List1.ListCount

End Sub

Example: 16

Dim i As Integer

Private Sub Command1_Click()

i = 1

Do While i <= 5

Print "MURSHID"; i

i = i + 1

Loop

End Sub

Example: 17

Dim x As Integer

Private Sub command1_click()

x = CInt(Text1.Text)

If x >= 33 Then

Text2.Text = "Pass"

Else

Text2.Text = "Fail"

End If

End Sub

Example: 18

Dim x As Integer

Private Sub Command1_Click()

x = CInt(Text1.Text)

Select Case x

Case 1

MsgBox ("Sunday")

Case 2

MsgBox ("Monday")

Case 3

MsgBox ("Tuesday")

Case 4

MsgBox ("Thursday")

Case 5

MsgBox ("Wednesday")

46

Case 6

MsgBox ("Friday")

Case 7

MsgBox ("Saturday")

End Select

End Sub

Example: 19

Dim x As Integer

Private Sub Command1_Click()

x = CInt(Text1.Text)

Select Case x

Case 80 To 100

MsgBox ("Grade: A+")

Case 70 To 79

MsgBox ("Grade: A")

Case 60 To 69

MsgBox ("Grade: A-")

Case 50 To 59

MsgBox ("Grade: B")

Case 40 To 49

MsgBox ("Grade: C")

Case 33 To 39

MsgBox ("Grade: D")

Case 0 To 32

MsgBox ("Fail")

Case Else

MsgBox "the range is 0-100", vbCritical, "error"

End Select

End Sub

Example: 20

Dim i As Integer

Private Sub Command1_Click()

i = 2

Do While i <= 10

Print i

i = i + 2

Loop

End Sub

Example: 21

Dim i As Integer

Private Sub Command1_Click()

i = 1

Do Until i > 5

Print "hello"; i

i = i + 1

Loop

End Sub

Example: 22  

 

Example: 23

LoadPicture

IMAGE

Name:

 

Caption:

 

BUTTON

Name:

 

Caption:

 

                        Private Sub Command1_Click()

Image1.Picture = LoadPicture("")

Image1.Stretch = True

End Sub 

 Example: 24

Time & Date

Label1

Name:

lblTime

Font:

18

Label2

Name:

lblDate

Font:

18

Timer

Interval:

1

 Private Sub Timer1_Timer()

lbltime.Caption = Time

lbldate.Caption = Date

End Sub

 Example: 25  

Calculator

TextBox1

Text:

Clear

TextBox2

Text:

Clear

TextBox3

Text:

Clear

Button1

Caption:

+

FontSize:

24

Button2

Caption:

-

FontSize:

24

Button3

Caption:

*

FontSize:

24

Button4

Caption:

/

FontSize:

24

                         Private Sub Command1_Click()

Dim myNumber1 As Integer

Dim myNumber2 As Integer

myNumber1 = Val(Text1.Text)

myNumber2 = Val(Text2.Text)

Text3.Text = myNumber1 + myNumber2

End Sub

 

Private Sub Command2_Click()

Dim myNumber1 As Integer

Dim myNumber2 As Integer

myNumber1 = Val(Text1.Text)

myNumber2 = Val(Text2.Text)

Text3.Text = myNumber1 - myNumber2

End Sub

 

Private Sub Command3_Click()

Dim myNumber1 As Integer

Dim myNumber2 As Integer

myNumber1 = Val(Text1.Text)

myNumber2 = Val(Text2.Text)

Text3.Text = myNumber1 * myNumber2

End Sub

 

Private Sub Command4_Click()

Dim myNumber1 As Integer

Dim myNumber2 As Integer

myNumber1 = Val(Text1.Text)

myNumber2 = Val(Text2.Text)

Text3.Text = myNumber1 / myNumber2

End Sub

Example: 26

Color Mixer

Picture

Name:

picColor

HScrollbar1

Name:

HscRed

Max:

255

Min:

0

LargeChange:

5

SmallChange:

5

HScrollbar2

Name:

HscGreen

Max:

255

Min:

0

LargeChange:

5

SmallChange:

5

HScrollbar3

Name:

HscBlue

Max:

255

Min:

0

LargeChange:

5

SmallChange:

5

Label1

Name:

lblRed

Caption:

0

Label2

Name:

lblGreen

Caption:

0

Label3

Name:

lblBlue

Caption:

0

                         Private Sub HscRed_Change()

picColor.BackColor = RGB (HscRed.Value, HscGreen.Value, HscBlue.Value)

lblRed.Caption = HscRed.Value

End Sub

 

Private Sub HscGreen_Change()

picColor.BackColor = RGB(HscRed.Value, HscGreen.Value, HscBlue.Value)

lblGreen.Caption = HscGreen.Value

End Sub

 

Private Sub HscBlue_Change()

picColor.BackColor = RGB(HscRed.Value, HscGreen.Value, HscBlue.Value)

lblBlue.Caption = HscBlue.Value

End Sub

 

Example: 27

Flight Planner

Form1

Name:

frmFlight

Caption:

Flight Planner

BorderStyle:

1-Fixed Single

List1

Name:

lstCities

Sorted:

True

Combo1

Name:

cboSeat

Style:

2-Dropdown List

Combo2

Name:

cboMeal

Style:

1-Simple

Text:

[blank]

Command1:

Name:

cmdAssign

Caption:

&Assign

Command2

Name;

cmdExit

Caption:

E&xit

Label1

Caption:

Destination

Label2

Caption:

Seat Lacation

Label3

Caption:

Meal Preference

                         Private Sub Form_Load()

lstCities.Clear

lstCities.AddItem "Class 1"

lstCities.AddItem "Class 2"

lstCities.AddItem "Class 3"

lstCities.AddItem "Class 4"

lstCities.AddItem "Class 5"

lstCities.AddItem "Class 6"

lstCities.AddItem "Class 7"

lstCities.AddItem "Class 8"

lstCities.AddItem "Class 9"

lstCities.ListIndex = 0

 

cboSeat.AddItem "1"

cboSeat.AddItem "2"

cboSeat.AddItem "3"

cboSeat.AddItem "4"

cboSeat.AddItem "5"

cboSeat.AddItem "6"

cboSeat.AddItem "7"

cboSeat.AddItem "8"

cboSeat.AddItem "09"

cboSeat.AddItem "10"

cboSeat.AddItem "11"

cboSeat.AddItem "12"

cboSeat.AddItem "13"

cboSeat.AddItem "14"

cboSeat.AddItem "15"

cboSeat.ListIndex = 0

 

cboMeal.AddItem "Mango"

cboMeal.AddItem "Banana"

cboMeal.AddItem "Jackfrut"

cboMeal.AddItem "Apple"

cboMeal.AddItem "Olive"

cboMeal.Text = "[Blank]"

End Sub

 

Private Sub cmdAssign_Click()

Dim Message As String

Message = "Destination: " + lstCities.Text + vbCr

Message = Message + "Seat Location: " + cboSeat.Text + vbCr

Message = Message + "Meal: " + cboMeal.Text + vbCr

MsgBox Message, vbOKOnly + vbInformation, "Your Assignment """

End Sub

 Example: 28  {AddNew}

Private Sub Command1_Click()

Data1.Recordset.AddNew

Text1.SetFocus

End Sub

 Example: 29  {MovePrevious}

Private Sub Command2_Click()

Data1.Recordset.MovePrevious

End Sub

 Example: 30  {Update}

Private Sub Command3_Click()

Data1.Recordset.Update

End Sub

 Example: 31  {MoveNext}

Private Sub Command4_Click()

Data1.Recordset.MoveNext

End Sub

 Example: 32  {Delete}

Private Sub Command5_Click()

Data1.Recordset.Delete

End Sub

 Example: 33 {Exit}

Private Sub Command1_Click()

End

End Sub

 

Private Sub Command1_Click()

msg = MsgBox("Confirm If you want to Exit ?", vbYesNo) = vbYes

If msg = True Then

End

End If

End Sub

 

Private Sub Command1_Click()

Dim sExit As Integer

sExit = MsgBox("Confirm If you want to Exit ?", vbQuestion + vbYesNo, "Employee Managment System")

If sExit = vbYes Then

Unload Me

End If

End Sub 

 

 

 

 

 

 

 

 

Post a Comment

0 Comments