1-add & subtract



1- Addition and Subtraction of the entered numbers.

[pic]

1-Code for Addition and Subtraction of the entered numbers.

Private Sub Command1_Click()

Text3.Text = ""

Text3.Text = Val(Text1.Text) + Val(Text2.Text)

End Sub

Private Sub Command2_Click()

Text4.Text = ""

Text4.Text = Val(Text1.Text) - Val(Text2.Text)

End Sub

Private Sub Command3_Click()

End

End Sub

Private Sub Text1_Change()

Text3.Text = ""

Text4.Text = ""

End Sub

Private Sub Text2_Change()

Text3.Text = ""

Text4.Text = ""

End Sub

2- To check if a number is Armstrong or not.

[pic]

2-Code to check if a number is Armstrong or not.

Private Sub Command1_Click()

Dim a, b, c, sum As Integer

a = Val(InputBox("ENTER THE NUMBER TO BE CHECKED FOR ARMSTRONG"))

c = a

sum = 0

While c > 0

b = c Mod 10

sum = sum + (b ^ 3)

c = c - (c Mod 10)

c = c / 10

Wend

If sum = a Then

MsgBox ("THE ENTERED NUMBER IS ARMSTRONG")

Else

MsgBox ("THE ENTERED NUMBER IS NOT ARMSTRONG")

End If

End Sub

Private Sub Command2_Click()

End

End Sub

3- To make a simple calculator.

[pic]

3-Code to make a simple calculator.

Dim a, d As Double

Dim b As String

Private Sub Command1_Click(Index As Integer)

Text1.Text = Text1.Text + Command1(Index).Caption

If Command1(Index).Caption = "." Then

Command1(10).Enabled = False

End If

End Sub

Private Sub Command2_Click(Index As Integer)

a = Val(Text1.Text)

Text1.Text = ""

b = Command2(Index).Caption

Command1(10).Enabled = True

End Sub

Private Sub Command3_Click()

If b = "+" Then

Text1.Text = a + Val(Text1.Text)

End If

If b = "-" Then

Text1.Text = a - Val(Text1.Text)

End If

If b = "*" Then

Text1.Text = a * Val(Text1.Text)

End If

If b = "/" Then

Text1.Text = a / Val(Text1.Text)

End If

If b = "%" Then

Text1.Text = a * 100 / Val(Text1.Text)

End If

End Sub

Private Sub Command4_Click()

If Text1.Text = "0" Then

Text1.Text = ""

End If

If Text1.Text = "" Then

Exit Sub

End If

Dim l As Integer

Dim d As String

d = Text1.Text

l = Len(d)

l = l - 1

If Right(Trim(d), 1) = "." Then

Command1(10).Enabled = True

End If

d = Left(Trim(d), l)

Text1.Text = d

End Sub

Private Sub Command5_Click()

Text1.Text = ""

Command1(10).Enabled = True

End Sub

Private Sub Command6_Click()

End

End Sub

Private Sub Form_Load()

Text1.Text = ""

End Sub

4- To open and save files using common dialog box.

[pic]

4-Code to open and save files using common dialog box.

Private Sub Command1_Click()

CommonDialog1.ShowOpen

RichTextBox1.LoadFile CommonDialog1.FileName

End Sub

Private Sub Command2_Click()

CommonDialog1.ShowSave

RichTextBox1.SaveFile CommonDialog1.FileName

End Sub

Private Sub Command4_Click()

End

End Sub

5- To change background color of a form using horizontal and vertical scrolls.

[pic]

5-Code to change background color of a form using horizontal and vertical scrolls.

Private Sub col()

Form1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)

End Sub

Private Sub col1()

Form1.BackColor = RGB(VScroll1.Value, VScroll2.Value, VScroll3.Value)

End Sub

Private Sub HScroll1_Change()

col

End Sub

Private Sub HScroll2_Change()

col

End Sub

Private Sub HScroll3_Change()

col

End Sub

Private Sub VScroll1_Change()

col1

End Sub

Private Sub VScroll2_Change()

col1

End Sub

Private Sub VScroll3_Change()

col1

End Sub

6- To display the capital present in list2 of the selected state in list1.

[pic]

[pic]

6-Code to display the capital present in list2 of the selected state in list1.

Private Sub Command1_Click()

Dim d As Integer

d = List1.ListIndex

If d = 0 Then

Text2.Text = List2.List(1)

End If

If d = 1 Then

Text2.Text = List2.List(2)

End If

If d = 2 Then

Text2.Text = List2.List(3)

End If

If d = 3 Then

Text2.Text = List2.List(0)

End If

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Form_Load()

List1.Clear

List2.Clear

List1.AddItem "U.P."

List1.AddItem "M.P."

List1.AddItem "MAHARASHTRA"

List1.AddItem "WEST BENGAL"

List2.AddItem "KOLKOTA"

List2.AddItem "LUCKNOW"

List2.AddItem "BHOPAL"

List2.AddItem "MUMBAI"

End Sub

Private Sub List1_Click()

Text1.Text = " "

Text2.Text = " "

Text1.Text = List1.Text

End Sub

7- To move the selected/all the contents of one list to another.

[pic]

[pic]

7-Code to move the selected/all the contents of one list to another.

Private Sub Command1_Click()

d = List1.ListIndex

If d = -1 Then

Exit Sub

End If

List2.AddItem List1.List(d)

List1.RemoveItem (d)

If List1.ListCount = 0 Then

Exit Sub

End If

End Sub

Private Sub Command2_Click()

d = List1.ListCount

For i = 0 To d - 1

List2.AddItem List1.List(0)

List1.RemoveItem (0)

Next

End Sub

Private Sub Command3_Click()

d = List2.ListIndex

If d = -1 Then

Exit Sub

End If

List1.AddItem List2.List(d)

List2.RemoveItem (d)

If List2.ListCount = 0 Then

Exit Sub

End If

End Sub

Private Sub Command4_Click()

d = List2.ListCount

For i = 0 To d - 1

List1.AddItem List2.List(0)

List2.RemoveItem (0)

Next

End Sub

Private Sub Command5_Click()

End

End Sub

Private Sub Form_Load()

List1.Clear

List2.Clear

List1.AddItem "delhi"

List1.AddItem "kolkatta"

List1.AddItem "bangalore"

List1.AddItem "new york"

List1.AddItem "london"

List1.AddItem "hongkong"

End Sub

8- To swap the contents of two lists.

[pic]

[pic]

8-Code to swap the contents of two lists.

Private Sub Command1_Click()

a = List1.ListCount

b = List2.ListCount

For i = 0 To a - 1

List2.AddItem List1.List(0)

List1.RemoveItem (0)

Next i

For j = 0 To b - 1

List1.AddItem List2.List(0)

List2.RemoveItem (0)

Next j

End Sub

Private Sub Form_Load()

List1.Clear

List2.Clear

List1.AddItem "agartala"

List1.AddItem "lucknow"

List1.AddItem "hyderabad"

List1.AddItem "kolkatta"

List1.AddItem "bangalore"

List1.AddItem "calicut"

List2.AddItem "london"

List2.AddItem "new york"

List2.AddItem "bangkok"

List2.AddItem "washington"

List2.AddItem "karachi"

List2.AddItem "new jersey"

End Sub

9- To make a mark sheet to accept name, branch of study, marks in six subjects and calculate the total and average marks obtained.

[pic]

9-Code to make a mark sheet to accept name, branch of study, marks in six subjects and calculate the total and average marks obtained.

Dim i, sum, average, percentage, arr(0 To 5) As Integer

Private Sub Command1_Click()

average = sum / 6

Text4.Text = sum

End Sub

Private Sub Command2_Click()

Text5.Text = average

End Sub

Private Sub Command3_Click()

For i = 0 To 5

Text3(i) = " "

Next i

Text4.Text = " "

Text5.Text = " "

sum = 0

For i = 0 To 5

arr(i) = Val(InputBox("enter the marks of SUB" & i + 1))

Text3(i) = arr(i)

sum = sum + arr(i)

Next i

End Sub

Private Sub Command4_Click()

End

End Sub

10- Use shell command to open calculator and notepad available on the computer.

[pic]

10-Code to open calculator and notepad available on the computer using shell command.

Private Sub Command1_Click()

Shell "c:\windows\system32\calc.exe", vbNormalFocus

End Sub

Private Sub Command2_Click()

Shell "c:\windows\system32\notepad.exe", vbNormalFocus

End Sub

Private Sub Command3_Click()

End

End Sub

11- To display the selected information of a particular students.

[pic]

11-Code to display the selected information of a particular students.

Private Sub COMMAND1_Click()

List1.Clear

If Option1.Value = True Then

Text1.Text = Option1.Caption

End If

If Option2.Value = True Then

Text1.Text = Option2.Caption

End If

If DATA.Value = 1 Then

List1.AddItem DATA.Caption

End If

If Check2.Value = 1 Then

List1.AddItem Check2.Caption

End If

If Check3.Value = 1 Then

List1.AddItem Check3.Caption

End If

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Form_Load()

List1.Clear

End Sub

12- To implement a traffic signal light using timer.

[pic]

12-Code to implement a traffic signal light using timer.

Private Sub Command1_Click()

Timer1.Enabled = True

Timer2.Enabled = False

Timer3.Enabled = False

End Sub

Private Sub Command2_Click()

End

End Sub

Private Sub Command3_Click()

Timer1.Enabled = False

Timer2.Enabled = False

Timer3.Enabled = False

Shape1.BackColor = vbWhite

Shape2.BackColor = vbWhite

Shape3.BackColor = vbWhite

End Sub

Private Sub Form_Load()

Timer1.Enabled = False

Timer2.Enabled = False

Timer3.Enabled = False

End Sub

Private Sub Timer1_Timer()

Shape1.BackColor = vbRed

Shape2.BackColor = vbWhite

Shape3.BackColor = vbWhite

Timer2.Enabled = True

Timer1.Enabled = False

Timer3.Enabled = False

End Sub

Private Sub Timer2_Timer()

Shape1.BackColor = vbWhite

Shape2.BackColor = vbYellow

Shape3.BackColor = vbWhite

Timer1.Enabled = False

Timer3.Enabled = True

Timer2.Enabled = False

End Sub

Private Sub Timer3_Timer()

Shape1.BackColor = vbWhite

Shape2.BackColor = vbWhite

Shape3.BackColor = vbGreen

Timer2.Enabled = False

Timer1.Enabled = True

Timer2.Enabled = False

End Sub

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download