Develop a small application that reads list of "n" numbers and makes a count of the number of negatives and non-negatives in it and displays them separately.
(A)Program Design :
(B) Property(Controls Used) :
- 3 Text Boxes (Name-Text1,Text2 & Text3) , Multiline-True, Locked-True.
- 3 Labels with Captions Input Numbers,Negative Numbers & Non-Negative Numbers
- 3 more Labels needed near to each Text Box to show the total number of input values , -ve numbers and +ve numbers (Name - lbl_total , lbl_neg & lbl_pos) , and Captions Zero.
- One Command Button with Caption "Read a Number"
(C) Attaching Code to the Object :
Private Sub Command1_Click() no = InputBox("Enter A Number", "Input") On Error GoTo Error n1 = CSng(no) Text1 = Text1 + " " + no lbl_total = Int(lbl_total) + 1 If (n1 >= 0) Then Text3 = Text3 + " " + no p = p + 1 lbl_pos.Caption = Str(p) Else Text2 = Text2 + " " + no n = n + 1 lbl_neg.Caption = Str(n) End If Error: End Sub |
Private Sub Form_Load() n = 0 p = 0 lbl_total = 0 lbl_pos = 0 lbl_neg = 0 End Sub |
(D) Output :
Click the Command Button Read A Number
And enter any number in the dialog box appeared
Again , Click the Read A Number command Button , and repeat the process..
Here, I entered numbers 3 times ( 2 , -6 , 80 ) And see the output below :
====================================================================
No comments:
Post a Comment