  This paper presents a general procedure based on using the method of types to
calculate the box dimension of sets. The approach unifies and simplifies
multiple box counting arguments. In particular, we use it to generalize the
formula for the box dimension of self-affine carpets of Gatzouras-Lalley and of
Bara\'nski type to their higher dimensional sponge analogues. In addition to a
closed form, we also obtain a variational formula which resembles the
Ledrappier-Young formula for Hausdorff dimension.
