Let $x$ and $y$ be real numbers with $x>y$ such that $x^2y^2+x^2+y^2+2xy=40$ and $xy+x+y=8$.  Find the value of $x$.
1. Let \( xy = a \) and \( x + y = b \). We are given two equations:
   \[
   a + b = 8
   \]
   \[
   x^2 y^2 + x^2 + y^2 + 2xy = 40
   \]

2. From the first equation, we can express \( b \) in terms of \( a \):
   \[
   b = 8 - a
   \]

3. Substitute \( x^2 y^2 = a^2 \) and \( x^2 + y^2 = (x+y)^2 - 2xy = b^2 - 2a \) into the second equation:
   \[
   a^2 + (b^2 - 2a) + 2a = 40
   \]
   Simplifying, we get:
   \[
   a^2 + b^2 = 40
   \]

4. Substitute \( b = 8 - a \) into the equation \( a^2 + b^2 = 40 \):
   \[
   a^2 + (8 - a)^2 = 40
   \]
   Expanding and simplifying:
   \[
   a^2 + 64 - 16a + a^2 = 40
   \]
   \[
   2a^2 - 16a + 64 = 40
   \]
   \[
   2a^2 - 16a + 24 = 0
   \]
   Divide by 2:
   \[
   a^2 - 8a + 12 = 0
   \]

5. Solve the quadratic equation \( a^2 - 8a + 12 = 0 \) using the quadratic formula \( a = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \):
   \[
   a = \frac{8 \pm \sqrt{64 - 48}}{2}
   \]
   \[
   a = \frac{8 \pm \sqrt{16}}{2}
   \]
   \[
   a = \frac{8 \pm 4}{2}
   \]
   \[
   a = 6 \quad \text{or} \quad a = 2
   \]

6. For \( a = 6 \), we have \( b = 8 - 6 = 2 \). For \( a = 2 \), we have \( b = 8 - 2 = 6 \).

7. Consider the case \( a = 6 \) and \( b = 2 \):
   \[
   xy = 6 \quad \text{and} \quad x + y = 2
   \]
   Solve the quadratic equation \( t^2 - 2t + 6 = 0 \):
   \[
   t = \frac{2 \pm \sqrt{4 - 24}}{2}
   \]
   \[
   t = \frac{2 \pm \sqrt{-20}}{2}
   \]
   \[
   t = 1 \pm i\sqrt{5}
   \]
   This case gives no real solutions.

8. Consider the case \( a = 2 \) and \( b = 6 \):
   \[
   xy = 2 \quad \text{and} \quad x + y = 6
   \]
   Solve the quadratic equation \( t^2 - 6t + 2 = 0 \):
   \[
   t = \frac{6 \pm \sqrt{36 - 8}}{2}
   \]
   \[
   t = \frac{6 \pm \sqrt{28}}{2}
   \]
   \[
   t = \frac{6 \pm 2\sqrt{7}}{2}
   \]
   \[
   t = 3 \pm \sqrt{7}
   \]

9. Since \( x > y \), we have:
   \[
   x = 3 + \sqrt{7}
   \]

The final answer is \(\boxed{3 + \sqrt{7}}\).