The Shulhan Aruch (Orah Haim 328) codifies the prohibition enacted by the Sages against taking medications on Shabbat. This enactment was made out of the concern that people might prepare medications on Shabbat by grinding together herbs and other ingredients ("Shehikat Samemanim"). Grinding on Shabbat constitutes a Torah violation ("Tohen"), and so as a safeguard against this violation, the Sages forbade taking medicine on Shabbat.
However, this prohibition is limited to cases where a person is "Holech Ke’bari" – meaning, he generally feels healthy, but experiences some discomfort which he wishes to alleviate through some medication. In such a situation, one may not take medicine on Shabbat. If, however, a person is "Nofel Le’mishkab" ("bedridden"), feeling sick to the point where he cannot function properly and needs to lie down, then he is allowed to take medication. The prohibition was enacted only for people who generally feel well and suffer some minor discomfort. It goes without saying that if a person is dangerously ill, then all necessary medical care is permitted, even that which entails Torah violations of Shabbat.
In this context, the Shulhan Aruch presents a solution for one who knows before Shabbat that he will want to use on Shabbat "Kilorin" – a kind of paste which people would apply to their eye to soothe irritation. The Shulhan Aruch writes that one may mix the paste with water before Shabbat, and then spritz the eye with it on Shabbat. This is permissible because of the combination of two factors: 1) since the paste was mixed with water before Shabbat, one understands that preparing medicine is forbidden on Shabbat, and he will thus not make the mistake of preparing medicine on Shabbat; 2) since he does not apply the paste, but rather spritzes his eye with water mixed with the paste, people will think he is just washing his eyes, and not applying medication.
The contemporary application of this Halacha, as noted by Rav Moshe Feinstein (Russia-New York, 1895-1986) in his Iggerot Moshe, would be mixing medication with water before Shabbat. If one anticipates needing medicine during Shabbat, then before Shabbat he may mix the medicine with some water (ensuring that the proportion of water is low enough so the medicine will still have the desired effect), and he may then drink the mixture when the medication is needed on Shabbat.
Summary: One who on Shabbat feels generally healthy but experiences some discomfort may not take medication. Medication is allowed on Shabbat only if one feels sick and cannot function properly. If one anticipates requiring medicine for some discomfort on Shabbat, then before Shabbat he may mix the medicine with some water and then drink the mixture when he needs the medicine on Shabbat.