Forgive yet another set of answers-BUT
You ask "Could I replace the hard drive with a 40GB or would I have to upgrade the memory and other stuff?
The simple answer is Yes.......... Your operating system is the main problem, I assume it is Win98?
You are able to run on 3.2 Gb so you know a thing or two about economical use of that HDD.
Add your new HDD as a secondary HD without disturbing your o/s on the present HD.
When you add the new HD you will have to partition and format it, so use the opportunity to make at least 2 partitions a smaller one first say not over 5 or at most 10Gb for later use as your primary C: drive.
If you divide the rest into 2 partitions of less than 20Gb you will not have trouble with your "old" computer recognising the new drives.
There are lots of things you can do later when your new HDD is installed but for the moment all you are seeking is more file space and that is what you will get.
No need to add to RAM for this. More RAM will speed things better than you could believe but this has nothing to do with file space.
Transferring your operating system is another excercise altogether, but made much easier once you have a new working HD to receive it.