The user enters three numbers and the program shows the window that what kind of triangle can be with the input sides: isosceles, rectangular, equilateral, or it does not exist at all.

Sub tri() Dim a, b, c As Integer If a = b Then MsgBox ("равнобедренный") End If If a And b Then MsgBox ("Прямоугольник") End If End Sub 
  • As I understand it, you need to enter 3 numbers, and the program must determine what type there can be a triangle with the entered sides? - E1mir
  • @KryTer_NexT to the point, this is exactly what software should do - user220682
  • Implied not a rectangle, but a triangle with a right angle? Need a function (Function) or procedure (Sub) - vikttur
  • @vikttur macro function - user220682
  • 2
    @coder - you have sides - integers. A triangle with such sides cannot be both rectangular and isosceles. - Igor

2 answers 2

Enter the formula in the cell:

 =tri(A1:C1) 

where A1: C1 is the range of cells

Code in common module:

 Function tri(Rng As Range) As String Dim sStr As String Dim a As Long, b As Long, c As Long If Rng.Cells.Count <> 3 Then tri = "значений<>3": Exit Function a = Rng(1).Value b = Rng(2).Value c = Rng(3).Value ' a=0 - обходим ошибку при a=b=c=0 If a = 0 Or a + b < c Or a + c < b Or b + c < a Then sStr = "не существует" Else If a = b And a = c Then sStr = "равносторонний" Else If a = b Or a = c Or b = c Then sStr = "равнобедренный" Else If a ^ 2 = b ^ 2 + c ^ 2 Or _ b ^ 2 = a ^ 2 + c ^ 2 Or _ c ^ 2 = b ^ 2 + a ^ 2 Then sStr = "прямоугольный" Else sStr = "разносторонний" End If End If End If End If tri = sStr End Function 

    Here is the sequence of actions:

    1. User entered 3 numbers;
    2. Create the first condition: if ( (a < c + b) и (b < a + c) и (c < a + b) ) then the triangle exists
    3. Inside the first condition we create embedded conditions where we will recognize the type of a triangle:

      3.1 if ( (a == b) и ( a == c ) и (c == b) ) then : The triangle is equilateral

      3.2 if ( (a == b) или ( a == c ) или (c == b) ) then : Isosceles triangle

      3.3 if ( (c^2 == a^2 + b^2 ) или (b^2 == a^2 + c^2) или (b^2 == c^2 +a^2) ) then : Rectangle triangle

      3.4 if ( ( (a == b) или ( a == c ) или (c == b) ) и ( (c^2 == a^2 + b^2 ) или (b^2 == a^2 + c^2) или (b^2 == c^2 +a^2) ) ) then : The rectangular isosceles triangle

    4. Add to the FIRST condition otherwise : Triangle does not exist

    • underlined this line if ((c^2 = a^2 + b^2 ) Or (b^2 = a^2 + c^2) or (b^2 = c^2 +a^2) )Then and this If (( a = b or ( a = c ) or (c = b) ) and ( (c^2 = a^2 + b^2 ) or (b^2 = a^2 + c^2) or (b^2 = c^2 +a^2) ) )then - user220682
    • Checked in the editor - does not emphasize, does not paint over, does not swear - vikttur
    • Note: if you pre-sort the entered numbers in ascending order (well, or descending), then the conditions for the checks will be significantly simplified. :) - Yaant