# VBA math triangle problem

**URL:** <https://forum.kirupa.com/t/vba-math-triangle-problem/273754>\
**Category:** programming\
**Created:** [October 20, 2008, 12:48pm UTC](https://forum.kirupa.com/t/vba-math-triangle-problem/273754 "2008-10-20T12:48:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![spectator](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@spectator](https://forum.kirupa.com/u/spectator)\
**Post date:** [October 20, 2008, 12:48pm UTC](https://forum.kirupa.com/t/vba-math-triangle-problem/273754/1 "2008-10-20T12:48:51Z")

</div>

Hi all :). I faced up a problem. I have written this code, but it doesn’t work. No matter what values I enter it shows me that Such triangle doesn’t exist. The point is to create a program that shows the biggest side and tells us whether the triangle exists or not. I am new in VBA.

```auto
Sub example()
Dim Message, Title, Default, MyValue
Dim s(3)
max = 0 ' the biggest side
sum = 0 ' sum of all the sides
s2 = 0 ' sum of the other 2 sides
For i = 1 To 3
Message = "Enter value:"
Title = "Side Values"
Default = "0"
MyValue = InputBox(Message, Title, Default)
' we put MyValue into the array
s(i) = MyValue
' here we find which of the sides is the biggest
If (s(i) > max) Then
max = s(i)
End If
' we sum all the sides
sum = sum + s(i)
Next i
' we show the biggest one
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.TypeText Text:="The biggest side is: "
Selection.TypeText Text:=max
' We show the sum of all the sides
Selection.TypeParagraph
Selection.TypeText Text:="Sum of all the sides is: "
Selection.TypeText Text:=sum
' here we find the sum of the other 2 sides(not including the max)
s2 = sum - max
' we show the sum of the 2 sides
Selection.TypeParagraph
Selection.TypeText Text:="Sum of the two sides: "
Selection.TypeText Text:=s2
'Again we show the max just to be sure it is the same
Selection.TypeParagraph
Selection.TypeText Text:=max
' We check whether a triangle exists
' if it exists then its max side must be smaller than the sum of the other two
If (s2 > max) Then
' it exists
Selection.TypeParagraph
Selection.TypeText Text:="It exists such a triangle"
Else
' it doesn't exist
Selection.TypeParagraph
Selection.TypeText Text:="It doesn't exist"
End If
End Sub

```

Please help me 🙂 I was not able to find where the mistake is.
