The only way to tell if your dog has heartworms is to see the vet for a blood test. If your dog is a high positive, he might show symptoms like having a heart murmur or have labored breating and a general lack of energy.
What you are seeing in the vomit is a parasite. It is impossible to know what kind of worm it is without seeing it. I suggest that you see your vet for a fecal exam to determine which worm it is and so that you can get the appropriate medication. I don't suggest that you buy an over the counter wormer because different wormers work for different worms. Without a test from your vet, you might not actually do any good.
Let me know if you need more help.
