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

Wednesday, July 13, 2011

VB-37 : Displaying triangle using given measurements

Write an event procedure to display the type of triangle,given the measurements of its 3 sides by the user.

Note : 

  • Equilateral Triangle    :   3 sides are equal
  • Isosceles Triangle      :   2 sides are equal
  • Scalene Triangle        :   All sides are unequal
Design a very interactive user interface.

A)    Program Design : 

ASSUMPTION :
  •       Mouse click on picture box select a point for Triangle
  •        Analyze button is enabled only after completion of Triangle
  •        Line Size is calculated in centimeter for 1 decimal point

(B) Property(Controls Used) :
  •        5 Labels and change their CAPTIONS as : Canvas : Click to select point for drawing a triangleTriangle,Line Size 1-2,Line Size 2-3,Line Size 3-1.
  •       3 more Labels with no CAPTIONS and name is lbl.
  •       Picture Box - Picture-none,Autodraw-True,ScaleMode-7 cm.
  •       3 Command Buttons - and change their CAPTIONS as : Reset,Analyze and Exit.
(C) Attaching Code to the Object :


Dim PX(3) As Single
Dim PY(3) As Single
Dim size(3) As Single
Dim i As Integer
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Command1_Click()
Picture1.Cls
Command2.Enabled = False
i = 0
For j = 0 To 2
lbl(j).Caption = ""
Next
End Sub
Private Sub Command2_Click()
For j = 0 To 2
NextJ = (j + 1) Mod 3
xdist = PX(NextJ) - PX(j)
ydist = PY(NextJ) - PY(j)
size(j) = Sqr((xdist * xdist) + (ydist * ydist))
size(j) = Round(size(j), 1)
lbl(j).Caption = size(j)
Next j
If size(0) = size(1) Then
If size(1) = size(2) Then
Label1.Caption = "EQUILATERAL TRIANGLE"
Else
Label1.Caption = "ISOSCELES TRIANGLE"
End If
ElseIf (0) = size(2) Then
Label1.Caption = "ISOSCELES TRIANGLE"
ElseIf size(1) = size(2) Then
Label1.Caption = "ISOSCELES TRIANGLE"
Else
Label1.Caption = "SCALENE TRIANGLE"
End If
Private Sub Form_Load()
Picture1.DrawWidth = 2
i = 0
End Sub
Private Sub picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If i < 3 Then
PX(i) = X
PY(i) = Y
picture1.Circle((PX(i),PY(i)),0.1,vbRed
If i > 0 Then
picture1.line((PX(i-1)&(PY(i-1))-(PX(i)&PY(i))
End If
If i = 2 Then
picture1.Line((PX(2),PY(2))-(PX(0),PY(0))
End If
i = i + 1
End If
If i = 3 Then
Command1.Enabled = True
End If
End Sub
      • ====================================================================
        Back to Home   &  VB
    ===========================================================

    No comments: