Getting an ultrasonic sensor to tell if distance is increasing or decreasing

How would I get an ultrasonic sensor to measure the distance between it and another moving object, and then tell if it's increasing or decreasing? Would I just create an oldvalue and a value, and if( old value<value), then it would be an increasing distance??

Thanks

Right, you compare the distances to find out whether and how much they change.

to measure the distance between it and another moving object

A lot depends on the relative speed of the two objects, that technique works for slow movement but for fast movement you might have to look at Doppler shift on the returned signal.