Write an event procedure to round a value to ceil(up),floor(down) or near to another value.All the values should be displayed in the corresponding text boxes once the submit button is pressed,Design a good interface with appropriate controls.
A) Program Design :
(B) Property(Controls Used) :
- Label1 : Caption - Enter a number
- Label2 : Caption - Rounded to Ceil
- Label3 : Caption - Rounded toFloor
- Label4 : Caption - Rounded to 2 digit
- TextBox1 : Text Property - (Blank)
- TextBox2: Text Property - (Blank)
- TextBox3 : Text Property - (Blank)
- TextBox4 : Text Property - (Blank)
- Command Button : Caption - Round
C) Attaching Code to the Object :
Output :
Enter a number : 3.256
Click Round
Rounded to Ceil : 3
Rounded to Floor :4
Rounded to2 digit :3.26
Private Sub Command1_Click() Dim num As Single num = Val(Text1.Text) If num = 0 Then MsgBox "Enter a non-zero number only" Text1.SetFocus GoTo endp Else Text2.Text = Int(num) If Int(num) = num Then Text2.Text = num Else Text3.Text = Int(num) + 1 End If End If Text4.Text = Math.Round(num, 2) endp: End Sub |
Output :
Enter a number : 3.256
Click Round
Rounded to Ceil : 3
Rounded to Floor :4
Rounded to2 digit :3.26
================================
===========================================================
No comments:
Post a Comment