The calculation of distances is of fundamental importance in extragalactic astronomy and cosmology. However, no practical implementation for the general case has previously been available. We derive a second-order differential equation for the angular size distance valid not only in all homogeneous Friedmann-Lemaitre cosmological models, parametrised by $lambda_{0}$ and $Omega_{0}$, but also in inhomogeneous 'on-average' Friedmann-Lemaitre models, where the inhomogeneity is given by the (in the general case redshift-dependent) parameter $eta$. Since most other distances can be obtained trivially from the angular size distance, and since the differential equation can be efficiently solved numerically, this offers for the first time a practical method for calculating distances in a large class of cosmological models. We also briefly discuss our numerical implementation, which is publicly available.