Like many common errors, this one is described in the article What does this error mean, and how do I fix it? from our Classic VB FAQs (in the FAQ forum, which is shown near the top of our home page)

The problem is that you are trying to use an object that you haven't set up yet.. and on that line you have a few objects: MainFont, D, D3DDevice, and MainFontDesc
  • MainFont is not the issue, as that is the one you are trying to Set.
  • MainFontDesc is not an issue either, as that has been Set on the previous line.
  • Assuming that the Init() routine has run, D3DDevice also will have been Set already.

That leaves us with D, and I can't see any code which sets it - so that is almost certainly the cause. I haven't used DirectX enough to know how it should be set up, but hopefully you will be able to find out from whatever source(s) you have built the other code from (or via a search of this forum).