Advertisement
Guest User

wow

a guest
Nov 21st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim FirstVar, SecondVar, ThirdVar, FourthVar, valueA, valueB, valueC As String
  2. Dim discriminant, i, PosFirstMult As Integer
  3. Dim x1, x2 As Double
  4.  
  5. ' Поиск a, b, c
  6.  
  7. PosFirstMult = InStr(1, ActiveDocument.Content, "*")
  8.  
  9. FirstVar = Mid(ActiveDocument.Content, 1, 1)
  10. SecondVar = Mid(ActiveDocument.Content, InStr(1, ActiveDocument.Content, "^") + 2, 1)
  11. ThirdVar = Mid(ActiveDocument.Content, InStr(PosFirstMult + 1, ActiveDocument.Content, "*") + 2, 1)
  12.  
  13. For i = 2 To InStr(1, ActiveDocument.Content, "*") - 1
  14.     FirstVar = FirstVar + Mid(ActiveDocument.Content, i, 1)
  15. Next i
  16.  
  17. For i = InStr(1, ActiveDocument.Content, "^") + 3 To InStr(PosFirstMult + 1, ActiveDocument.Content, "*") - 1
  18.    SecondVar = SecondVar + Mid(ActiveDocument.Content, i, 1)
  19. Next i
  20.  
  21. For i = InStr(PosFirstMult + 1, ActiveDocument.Content, "*") + 3 To InStr(1, ActiveDocument.Content, "=") - 1
  22.     ThirdVar = ThirdVar + Mid(ActiveDocument.Content, i, 1)
  23. Next i
  24.  
  25. ' Перевод строковых значений в числовые
  26.  
  27. valueA = CInt(FirstVar)
  28. valueB = CInt(SecondVar)
  29. valueC = CInt(ThirdVar)
  30.  
  31. ' Решение квадратного уравнения
  32.  
  33. discriminant = ((valueB ^ 2) - (4 * valueA * valueC))
  34.  
  35. x1 = (-valueB + Sqr(discriminant)) / (2 * valueA)
  36. x2 = (-valueB - Sqr(discriminant)) / (2 * valueA)
  37.  
  38. ' Вывод ответов
  39.  
  40. With ActiveDocument.Paragraphs(1).Range
  41.  .InsertAfter "x1 = " & x1
  42.  .InsertParagraphAfter
  43. End With
  44.  
  45. With ActiveDocument.Paragraphs(2).Range
  46.  .InsertAfter "x2 = " & x2
  47.  .InsertParagraphAfter
  48. End With
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement