We present a formula for the number of line segments connecting \(q+1\) points of an \(n_1 \times \cdots \times n_k\) rectangular grid. As corollaries, we obtain formulas for the number of lines through at least \(k\) points and, respectively, through exactly \(k\) points of the grid. The well-known case \(k = 2\) is thus generalized. We also present recursive formulas for these numbers assuming \(k = 2, n_1 = n_2\). The well-known case \(q = 2\) is thus generalized.