I assume that you mean 1840 not 1940?
They are at Gowan Glen, Larkhall, Dalserf in 1841: Thomas Neilson, 30, carter; Mary, 30; Thomas, 6; John, 4; William, 2; James and Robert, 8 months. All except Thomas born in Lanarkshire.
In 1851 they are in Westquarter, Glassford: Mary Neilson, wife, 39, weaver's wife; Thomas, son, 16, hand loom weaver; William, 12, hand loom weaver; James and Robert, 10; Janet, 7; Isabella, 5. All born in Dalserf except Thomas and William, who were born in Kirkintilloch.
No listing of Thomas with the family in 1851, but also in Westquarter village are Thomas Neilson, 40, hand loom weaver; wife Christian, 40; and stepdaughters Margaret, Christian, Bethia and Janet Ballantine. This Thomas doesn't quite fit the one in 1841, because he was born in Glassford, which is in Lanarkshire, but I have so far failed to find any record of a marriage or of the baptisms of the Ballantine girls, and I am wondering if perhaps Mary's husband has deserted her and set up home with Christian instead?
The 1861 census has yet to be transcribed by FreeCEN, but if I were you I think my next step would be to look for Mary in the 1861 census, to see whether she is with Thomas and, if not, how she is described (wife or widow?). However I don't see a death of a Mary Neilson, other surname Stuart, in the SP index, so she could have emigrated or died between 1851 and 1854.
I don't see a likely baptism of Mary Stuart in Dalserf around 1811/1812, however.