How were the first molecular formulas determined?
Lavoisier burned hydrogen and oxygen together and found that water was produced.  Dalton incorporated this information into his thinking that the most stable arrangement of any two atoms involved a 1:1 combination, therefore water would be "OH".  

In slightly more recent times, but prior to modern-day spectroscopy, chemists would chemically chop molecules into identifiable fragments.  They would also combust the molecule and get a C,H,N,O ratio.  Putting all of this together they would (often) come up with remarkably accurate molecular formulas.