Staredit Network

Staredit Network -> Computers and Technical -> Need Help With a VB Program
Report, edit, etc...Posted by Slyence on 2006-04-23 at 23:20:06
CODE
Option Explicit

Private Sub cmdFind_Click()
Dim dblA, dblB, dblC As Double

dblA = Val(txtA.Text)
dblB = Val(txtB.Text)
dblC = Val(txtC.Text)
Call TriangleType(dblA, dblB, dblC) 'ERROR
lblArea.Caption = "The area of the triangle is " + Area(dblA, dblB, dblC)
If IsRight(dblA, dblB, dblC) Then
lblRight.Caption = "The triangle is a right triangle"
Else
lblRight.Caption = "The triangle is not a right triangle"
End If
End Sub

Private Sub TriangleType(SideA As Double, SideB As Double, SideC As Double)
If SideA = SideB And SideA = SideC Then
lblType.Caption = "The triangle is equilateral"
ElseIf Not SideA = SideB And Not SideA = SideC And Not SideB = SideC Then
lblType.Caption = "The triangle is scalene"
Else
lblType.Caption = "The triangle is isosceles"
End If
End Sub

Private Function Area(SideA As Double, SideB As Double, SideC As Double) As Double
Dim dblS As Double

dblS = (SideA + SideB + SideC) / 2
Area = (dblS * (dblS - SideA) * (dblS - SideB) * (dblS - SideC)) ^ 0.5
End Function

Private Function IsRight(SideA As Double, SideB As Double, SideC As Double) As Boolean
If SideA ^ 2 + SideB ^ 2 = SideC ^ 2 Or SideA ^ 2 + SideC ^ 2 = SideB ^ 2 Or _
SideB ^ 2 + SideC ^ 2 = SideA ^ 2 Then
IsRight = True
Else
IsRight = False
End If
End Function

For some reason, it won't let me call the TriangleType sub. Please help!!!
Report, edit, etc...Posted by saibaman8 on 2006-04-24 at 19:11:39
You need to pass them by value. Example: Private Sub TriangleType(ByVal SideA as Double, ByVal SideB as Double, ByVal SideC as Double). Use that for all of the methods.

Also, you have an error when setting lblArea.Caption. There should be a & instead of a +.
Report, edit, etc...Posted by MindArchon on 2006-04-25 at 00:37:53
QUOTE(saibaman8 @ Apr 24 2006, 04:11 PM)
You need to pass them by value. Example: Private Sub TriangleType(ByVal SideA as Double, ByVal SideB as Double, ByVal SideC as Double). Use that for all of the methods.

Also, you have an error when setting lblArea.Caption. There should be a & instead of a +.
[right][snapback]472056[/snapback][/right]


Neither of those matter. You can use & or +.
Report, edit, etc...Posted by saibaman8 on 2006-04-25 at 17:34:22
QUOTE(MindArchon @ Apr 25 2006, 12:37 AM)
Neither of those matter. You can use & or +.
[right][snapback]472275[/snapback][/right]

Cool. I never knew that.

But after running the program, it works with & but not +.
Next Page (1)