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, August 7, 2011

VB-82 : Basic Mathematical functions

Develop a small application to use the basic mathematical functions on the numbers.
The user interface of  the application should appear as the given figure:


Refer  Simple Programs(3) to get an idea about Calculation



Sum
Subtract
 Multiply
Divide
 Square
Cube
sin N1
cos N1
N1
N2
èPress

          Answer
     Cancel




When square like operations is selected , the N2 should become inactive. You should use horizontal scroll bar to set the maximum values of N1 and N2.


Refer Simple Calculator also.



(A)Program Design : 





(B) Property(Controls Used) :
  • 4 Labels for proper headings
  • 3 TextBoxes
  • 2 Command Buttons ( ==>> : Command1 and Cancel :Command2)
  • 9 OptionButtons
  • Horizontal ScrollBar

(C) Attaching Code to the Object :


Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Command1_Click()
Dim n1, n2
If Text1.Text <> "" Then
    n1 = CInt(Text1.Text)
End If
If Text2.Text <> "" Then
    n2 = CInt(Text2.Text)
End If
If Option1.Value = True Then
   Text3.Text = n1 + n2
Else
    If Option2.Value = True Then
    Text3.Text = n1 - n2
    Else
        If Option3.Value = True Then
        Text3.Text = n1 * n2
        Else
            If Option4.Value = True Then
              If n2 <> 0 Then
                Text3.Text = n1 / n2
              Else
                Text3.Text = "Error"
              End If
            Else
                If Option4.Value = True Then
                Text3.Text = n1 Mod n2
                Else
                    If Option6.Value = True Then
                    Text3.Text = n1 * n2
                    Else
                        If Option7.Value = True Then
                        Text3.Text = n1 * n1 * n1
                        Else
                            If Option8.Value = True Then
                            Text3.Text = Math.Sin(n1)
                            Else
                                If Option9.Value = True Then
                                Text3.Text = Math.Cos(n1)
                                End If
                            End If
                        End If
                    End If
                End If
            End If
        End If
    End If
End If
End Sub
Private Sub Option1_Click()
Option2.Value = False
Option3.Value = False
Option4.Value = False
Option5.Value = False
Option6.Value = False
Option7.Value = False
Option8.Value = False
Option9.Value = False
Text2.Enabled = True
End Sub
Private Sub Option2_Click()
Option1.Value = False
Option3.Value = False
Option4.Value = False
Option5.Value = False
Option6.Value = False
Option7.Value = False
Option8.Value = False
Option9.Value = False
Text2.Enabled = True
End Sub
Private Sub Option3_Click()
Option1.Value = False
Option2.Value = False
Option4.Value = False
Option5.Value = False
Option6.Value = False
Option7.Value = False
Option8.Value = False
Option9.Value = False
Text2.Enabled = True
End Sub
Private Sub Option4_Click()
Option1.Value = False
Option2.Value = False
Option3.Value = False
Option5.Value = False
Option6.Value = False
Option7.Value = False
Option8.Value = False
Option9.Value = False
Text2.Enabled = True
End Sub
Private Sub Option5_Click()
Option1.Value = False
Option2.Value = False
Option3.Value = False
Option4.Value = False
Option6.Value = False
Option7.Value = False
Option8.Value = False
Option9.Value = False
Text2.Enabled = True
End Sub
Private Sub Option6_Click()
Text2.Enabled = False
Option1.Value = False
Option2.Value = False
Option3.Value = False
Option4.Value = False
Option5.Value = False
Option7.Value = False
Option8.Value = False
Option9.Value = False
End Sub
Private Sub Option7_Click()
Text2.Enabled = False
Option1.Value = False
Option2.Value = False
Option3.Value = False
Option4.Value = False
Option5.Value = False
Option6.Value = False
Option8.Value = False
Option9.Value = False
End Sub
Private Sub Option8_Click()
Text2.Enabled = False
Option1.Value = False
Option2.Value = False
Option3.Value = False
Option4.Value = False
Option5.Value = False
Option6.Value = False
Option7.Value = False
Option9.Value = False
End Sub
Private Sub Option9_Click()
Text2.Enabled = False
Option1.Value = False
Option2.Value = False
Option3.Value = False
Option4.Value = False
Option5.Value = False
Option6.Value = False
Option7.Value = False
Option8.Value = False
End Sub



(D) Output :


(E) Errors :


If found any errors while running your VB program, please click Comment section.

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

No comments: