Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Sunday, July 24, 2011

VB-64 : Simple Calculator



Develop an application to design a simple calculator that performs the operations +,-,*,/, % , and Modulo operation.


To get an idea , Click  Simple Programs(3)


Refer The four calculations Calculations using Grid control  and Basic Mathematical functions also.



(A)Program Design : 


(B) Property(Controls Used) :
  • One TextBox (Name-Text1) to input values as well as calculated output
  • 4 Command Buttons with Captions as  .(Name-cmd_dot) , +/-(Name-cmd_sign)  , =(Name-com_equal)  , C(Name-com_cancel) 
  • 10 Command Buttons with Name-Command1, Captions from 0 to 9 , Index from 0 yo 9
  • 6 Command Buttons with Index from 0 to 5 , Text Property as /* ,+ mod ,  % respectively and Name as com_op 
Note that , there is only one Text Box and 20 Command Buttons.



 (C) Attaching Code to the Object :


                
Dim old As String
Dim old2 As String
Dim op As String
Dim op2 As String
Dim f As Integer
 Private Sub calc_per()
If op2 = "%" Then
old_value = Val(old)
Text1.Text = Val(old_value * (Val(Text1.Text) / 100))
f = 1
End If
End Sub


Private Sub calc_text()
Dim ans As Double
Dim old_val As Double
old_value = Val(old)
Select Case op
Case "+"
ans = old_value + Val(old2)
Case "-"
ans = old_value - Val(old2)
Case "*"
ans = old_value * Val(old2)
Case "/"
Case "mod"
ans = old_value - (CInt(old_value / Val(old2)) * Val(old2))
End Select
Text1 = Str(ans)
old = Text1
End Sub


Private Sub cmd_dot_Click()
Text1 = Text1 & "."
End Sub


Private Sub cmd_sign_Click()
Text1.Text = -1 * Val(Text1.Text)
End Sub


Private Sub com_cancel_Click()
Text1.Text = ""
old = ""
op = ""
op2 = ""
End Sub


Private Sub com_equal_Click()
If op2 = "=" Then
Else
old2 = Text1.Text
End If
calc_text
f = 1
op2 = "="
End Sub


Private Sub cmd_op_Click(Index As Integer)
If com_op(Index).Caption = "%" Then
op2 = "%"
calc_per
Else
If op <> "" And op2 <> "=" Then
old2 = Text1.Text
calc_text
End If
old = Text1.Text
op = com_op(Index).Caption
f = 1
End If
op2 = ""
End Sub


Private Sub Command1_Click(Index As Integer)
If f = 1 Then
Text1 = Command1(Index).Caption
Else
Text1 = Text1 & Command1(Index).Caption
End If
f = 0
End Sub


Private Sub Form_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii
End Sub




Private Sub Form_Load()
old = ""
old2 = ""
op = ""
f = 0
End Sub



Private Sub Text1_KeyPress(KeyAscii As Integer)
If ((KeyAscii >= 48 And KeyAscii <= 57) Or KeyAscii = 8 Or KeyAscii = 46 Or
                                                                                                          KeyAscii = 27) Then                                                         
Else
KeyAscii = 8
End If
End Sub


      • ====================================================================
        Back to Home   &  VB
    ===========================================================

    VB-63 : Sum of the first n terms of the series

    Develop an application to compile the Sum of the first n terms of the series :
    S=1-3+5-7+9- .......

    (A)Program Design : 


    (B) Property(Controls Used) :
    • 3 labels with Captions as S=1-3+5-7+9- ....... , Terms & Generate
    • 2 Text Boxes
    • One Command Button with Caption Generate

    (C) Attaching Code to the Object :

    Private Sub Command1_Click()
    Dim sum, j, i As Integer
    On Error GoTo error
    Text2 = ""
    sum = 0
    j = 1
    For i = 1 To Int(Text1.Text)
    sum = sum + j
    If (j > 0) Then
    If (i <> 1) Then
    Text2 = Text2 + "+" + Str(j)
    Else
    Text2 = Text2 + " " + Str(j)
    End If
    j = -(j + 2)
    Else
    Text2 = Text2 + " " + Str(j)
    j = -j + 2
    End If
    Next
    Text2 = "Series is..." + vbCrLf + Str(sum) + "=" + Text2
    error:
    End Sub


    (D) Output :




    Also refer Sum of n numbers .

    =================================================================
    =========================================================

    VB-62 : Convert Text from Lower case to Upper case

    Develop an application to convert a given Text from Lower case to Upper case

    Refer Convert Text from Upper case to Lower case .


    The only difference lies in the code.


    (Don't forget to change the Program Design as given):






    Private Sub Text1_Change(0
    Text2 = UCase(Text1)
    End Sub






    ==================================================================
    =========================================================

    VB-61 : Displaying Current Date and Time

    Develop an application to display current date and time on a form

     Refer Displaying Day for a given date also.

    (A)Program Design : 



    (B) Property(Controls Used) :
    • 2 Labels with Captions Date & Time
    • 3 TextBoxes  : Locked - True,BackColor-Gray,Text Property-Blank
    • One Command Button (Caption - Current Time)
    (C) Attaching Code to the Object :


    Private Sub Command1_Click()
    Text1 = Format(Date, "dd/MM/yy")
    Text2 = Format(Date, "dddd,mmmm, d yyyy")
    Text3 = Time
    End Sub
    Private Sub Form_Load()
    Call Command1_Click
    End Sub


    (D) Output :



    ====================================================================


    =========================================================

    Vb-60 : Count +ve & -ve from a list of number


    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









    Here, I entered 2 ,  2 is Positive , so it goes to the text box of positive numbers.
    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 :


    ====================================================================
    =========================================================