The Schr\"odinger equation for a crystalline slab of finite thickness is separated under certain assumptions into a one-dimensional equation in the coordinate perpendicular to the slab surface and a two-dimensional band-structure problem. The independent solution of both problems yields zero-order wave functions for the electrons in the slab. Weyl's theory for second-order differential equations is used to solve the one-dimensional Schr\"odinger equation numerically for arbitrary potentials using square integrability as the only boundary condition. The behavior of the solutions for a particular model potential is studied in detail emphasizing the effect of the potential in the surface region on the surface states.