Change a spread on a bang

I have following problem. I have two IO boxes. One (value box) ranging from 0 to, lets say 20, and another one (declaration box) changing between the values 1 and 0 (True and False). I want the resulting IO box to change the value simultaneously with the value box, but only when the declaration box is True. If the Declaration box is 0, it should freeze at the value it has been at the last “true”.
I hope you can understand what i’m trying to say.

hello , probably you look for S+H (Animation)

s+h.v4p (4.2 kB)