0% found this document useful (0 votes)
61 views

Design A Form To Show Working of Command Buttons and Msgbox Function

The document contains the code for 11 different Visual Basic programs that design forms to implement various functions: 1) A form with command buttons and message boxes 2) A form that finds the largest number from user input 3) A form that determines a student's grade from their marks 4) A form that calculates the price of pens purchased by the dozen 5) A form that calculates the mean of user-input numbers using arrays 6) An application form with textboxes, options, lists, and buttons 7) A stopwatch form with timers 8) A form that demonstrates listbox methods 9) A basic notepad form with copy, cut, paste functions 10) A

Uploaded by

Gurpreet Gaba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Design A Form To Show Working of Command Buttons and Msgbox Function

The document contains the code for 11 different Visual Basic programs that design forms to implement various functions: 1) A form with command buttons and message boxes 2) A form that finds the largest number from user input 3) A form that determines a student's grade from their marks 4) A form that calculates the price of pens purchased by the dozen 5) A form that calculates the mean of user-input numbers using arrays 6) An application form with textboxes, options, lists, and buttons 7) A stopwatch form with timers 8) A form that demonstrates listbox methods 9) A basic notepad form with copy, cut, paste functions 10) A

Uploaded by

Gurpreet Gaba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Design a form to show working of command buttons and msgbox function.

Private Sub cmdblue_Click()


MsgBox (" This is Blue colour ")
End Sub

Private Sub cmdgreen_Click()


MsgBox (" This is Green colour ")
End Sub

Private Sub cmdred_Click()


MsgBox (" This is Red colour ")
End Sub

Private Sub cmdexit_Click()


End
End Sub

Form Design:

Output:

Design a form to find largest number among n numbers.


Dim num(1 To 20) As Integer
Dim large As Double
Dim i As Integer
Dim n As Integer
Private Sub cmdlargest_Click()
n = Val(InputBox("Enter Total Numbers"))
Print
Print "Total Numbers Are " & n
Print
For i = 1 To n
num(i) = Val(InputBox("Enter Number" & i))
Print " Number " & i & " is " & num(i)
Next
large = num(1)
For i = 1 To n
If large < num(i) Then
large = num(i)
End If
Next
Print
Print " Largest Number is
End Sub

" & large

Private Sub cmdexit_Click()


End
End Sub

Form Design:

Output:

Design a form to find grade of a student.

Private Sub cmdgrade_Click()


Dim marks As Integer
Dim grade As String
marks = Val(Text1.Text)
Select Case marks
Case 80 To 100
grade = "A"
Case 60 To 79
grade = "B"
Case 50 To 59
grade = "C"
Case 40 To 49
grade = "D"
Case 0 To 39
grade = "E"
End Select
MsgBox ("Grade is " & grade)
End Sub

Private Sub cmdexit_Click()


End
End Sub

Form Design:

Output:

Design a form to calculate price of N dozen Pens.

Private Sub cmdcal_Click()


Dim qty As Integer
Dim cost As Single
qty = Val(Text1.Text)
cost = 125 * qty
If qty > 10 Then cost = cost * 0.9
iblresult.Caption = "Price of Pens is " & Str(cost)
End Sub

Private Sub cmdexit_Click()

End
End Sub

Form Design:

Output:

Design a form to calculate mean by using array and input box function.

Dim num(1 To 20) As Integer


Dim mean As Double
Dim sum As Double
Dim i As Integer
Dim n As Integer
Private Sub cmdmean_Click()
n = Val(InputBox("Enter Total Numbers"))
Print
Print "Total Numbers Are " & n
Print
sum = 0
For i = 1 To n
num(i) = Val(InputBox("Enter Number" & i))
sum = sum + num(i)
Print " Number " & i & " is " & num(i)
Next
mean = sum / n
Print
Print " Average is " & mean
End Sub
Private Sub cmdexit_Click()
End
End Sub

Form Design:

Output:

Design a form to implement an application form.

Private Sub Cmdclear_Click()


Text1.Text = " "
Text2.Text = " "
Option1.Value = False
Option2.Value = False
Option3.Value = False
List1.Text = "10th"
Combo1.Text = " "
Check1.Value = False
Check2.Value = False
Check3.Value = False
Check4.Value = False
End Sub

Private Sub Cmdsubmit_Click()


MsgBox (Text1.Text & " Your application form has been submitted")
End Sub

Form Design:

Output:

Design a form to implement a stopwatch.

Private Sub cmdset_Click()


Timer1.Enabled = False
lblss.Caption = "00"
lblmm.Caption = "00"
lblhh.Caption = "00"

End Sub

Private Sub cmdstart_Click()


If Timer1.Enabled = False Then
Timer1.Enabled = True
End If
End Sub

Private Sub cmdstop_Click()


Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()

lblss.Caption = Val(lblss.Caption) + Val(1)


If lblss.Caption = 60 Then
lblmm.Caption = Val(lblmm.Caption) + Val(1)
lblss.Caption = 0
ElseIf lblmm.Caption = 60 Then
lblhh.Caption = Val(lblhh.Caption) + Val(1)
lblmm.Caption = 0
End If
End Sub

Private Sub cmdexit_Click()


End
End Sub

Form Design:

Output:

Design a form to show working of different methods of a Listbox.

Private Sub cmdadd_Click()


List1.AddItem Text1.Text
Text1.Text = " "
Text1.SetFocus
End Sub

Private Sub Cmdclear_Click()


List1.Clear
End Sub

Private Sub cmddelete_Click()


Dim pos As Integer
pos = List1.ListIndex
If (pos >= 0) Then
List1.RemoveItem pos
End If
End Sub

Private Sub Cmdexit_Click()


End
End Sub

Form Design:

Output:

Design a form to implement notepad.

Private Sub copy_Click()


Clipboard.Clear
Clipboard.SetText Text1.SelText
End Sub

Private Sub cut_Click()


Clipboard.Clear
Clipboard.SetText Text1.SelText
Text1.SelText = ""

End Sub

Private Sub paste_Click()


Text1.SelText = Clipboard.GetText
End Sub
Private Sub exit_Click()
End
End Sub

Form Design:

Output:

Design a form to implement popup menu.

Private Sub lblvb_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As


Single)
If Button = vbRightButton Then
PopupMenu mnuFormatPopUp
End If
End Sub

Private Sub mnuBold_Click()


If mnuBold.Checked Then
lblvb.FontBold = False
mnuBold.Checked = False
Else
lblvb.FontBold = True
mnuBold.Checked = True
End If
End Sub

Private Sub mnuItalic_Click()


If mnuItalic.Checked Then
lblvb.FontItalic = False
mnuItalic.Checked = False
Else
lblvb.FontItalic = True
mnuItalic.Checked = True

End If
End Sub

Private Sub mnuCancel_Click()


End
End Sub

Form Design:

Output:

Design a form to implement calculator using control arrays.

Dim op1 As Double


Dim op2 As Double
Dim operator As String
Dim result As Double

Private Sub cmd_Click(Index As Integer)


Text1.Text = Text1.Text & cmd(Index).Caption
op1 = Val(Text1.Text)
End Sub

Private Sub cmdc_Click()


op2 = 0
op1 = 0
Text1.Text = " "
End Sub

Private Sub cmdce_Click()


op1 = 0
Text1.Text = " "
End Sub

Private Sub cmddecimal_Click()


If InStr(Text1.Text, ".") Then
Exit Sub
Else
Text1.Text = Text1.Text + "."
End If
End Sub

Private Sub cmdequal_Click()


Select Case operator
Case "+"
result = op2 + op1
Text1.Text = result
Case "-"
result = op2 - op1
Text1.Text = result
Case "*"
result = op2 * op1
Text1.Text = result
Case "/"
If (op1 = 0) Then
MsgBox ("can't divided by zero")
Else
result = op2 / op1

Text1.Text = result
End If
End Select
op1 = result
End Sub

Private Sub cmdop_Click(Index As Integer)


Text1.Text = " "
op2 = op1
op1 = 0
operator = cmdop(Index).Caption
End Sub

Private Sub cmdsqr_Click()


Text1.Text = Val(Sqr(opl))
End Sub

Form Design:

Output:

INDEX

Sr.no.

Programs Name

1.

Design a form to show working of command buttons


and msgbox function.

2.

Design a form to find largest number among n


numbers.

3.

Design a form to find grade of a student.

4.

Design a form to calculate price of N dozen Pens.

5.

Design a form to calculate mean by using array and


input box function.

6.

Design a form to implement an application form.

Date

Sign

7.

Design a form to implement Stopwatch.

8.

Design a form to show working of different methods


of a Listbox.

9.

Design a form to implement notepad.

10.

Design a form to implement PopUp Menu.

11.

Design a form to implement calculator using control


arrays.

A
Practical File
On
Visual Basic

Submitted To:

Submitted By:

Mr. Rajinder Kumar

Vikram

Assistant Professor

B.Sc(CS)2nd Year

(Comp. Sci. Department)

Roll No: 14108440039

You might also like