3 added 31 characters in body edited Jun 18 at 15:51 kglr 218k1010 gold badges248248 silver badges499499 bronze badges Since your Last @Reap[...] returns {"zmax" -> 1.} you should use "zmax" in ReplaceAll: smaxrule = "zmax" /. Last@Reap[ NDSolveValue[Last@Reap[NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}], _, #1 -> First@#2 &]&]; smax = "zmax" /. rule  1. Alternatively, you can use one-argument form of Reap and simply get Part (2,1,1) of Reap[...] output: smaxout = Reap[NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}]][[2]]; smax = out[[2, 1, 1]]  1. Since your Last @Reap[...] returns {"zmax" -> 1.} you should use "zmax" in ReplaceAll: smax = "zmax" /. Last@Reap[ NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}], _, #1 -> First@#2 &]  1. Alternatively, you can use one-argument form of Reap and simply get Part (2,1,1) of Reap[...] output: smax = Reap[NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}]][[2, 1, 1]]  1. Since your Last @Reap[...] returns {"zmax" -> 1.} you should use "zmax" in ReplaceAll: rule = Last@Reap[NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}], _, #1 -> First@#2 &]; smax = "zmax" /. rule  1. Alternatively, you can use one-argument form of Reap and simply get Part (2,1,1) of Reap[...] output: out = Reap[NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}]]; smax = out[[2, 1, 1]]  1. 2 added 40 characters in body edited Jun 18 at 13:55 kglr 218k1010 gold badges248248 silver badges499499 bronze badges Since your Last @Reap[...] returns {"zmax" -> 1.} you should use "zmax" in ReplaceAll: smax = "zmax" /. Last@Reap[ NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}], _, #1 -> First@#2 &]  1. Alternatively, you can use one-argument form of Reap and simply get Part (2,1,1) of Reap[...] output: smax = Reap[NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}]][[2, 1, 1]]  1. Since your Last @Reap[...] returns {"zmax" -> 1.} you should use "zmax" in ReplaceAll: smax = "zmax" /. Last@Reap[ NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}], _, #1 -> First@#2 &]  1. Alternatively, you can simply Part (2,1,1) of Reap[...] output: smax = Reap[NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}]][[2, 1, 1]]  1. Since your Last @Reap[...] returns {"zmax" -> 1.} you should use "zmax" in ReplaceAll: smax = "zmax" /. Last@Reap[ NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}], _, #1 -> First@#2 &]  1. Alternatively, you can use one-argument form of Reap and simply get Part (2,1,1) of Reap[...] output: smax = Reap[NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}]][[2, 1, 1]]  1. 1 answered Jun 18 at 13:49 kglr 218k1010 gold badges248248 silver badges499499 bronze badges Since your Last @Reap[...] returns {"zmax" -> 1.} you should use "zmax" in ReplaceAll: smax = "zmax" /. Last@Reap[ NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}], _, #1 -> First@#2 &]  1. Alternatively, you can simply Part (2,1,1) of Reap[...] output: smax = Reap[NDSolveValue[{int'[z] == (Exp[z] - 1) h[z], int[smin] == 0, WhenEvent[int[z] == 0, {"StopIntegration", Sow[z, "zmax"]}]}, int, {z, smin, Infinity}]][[2, 1, 1]]  1.