Page 172 - The Unofficial Guide to Lego Mindstorms Robots
P. 172

161


          Like NQC, Spirit.ocx uses the default firmware that is loaded on the RCX and makes more features of the bytecode interpreter
          av ailable than RCX Code. Unlike NQC, Spirit.ocx is a Windowsspecific piece of software.

          Calling Spirit.ocx Functions

          T he goal of this chapter is to enable you to call Spirit.ocx functions directly from VB or VBA with code like this:

              .InitComm
              .PlayTone 440,    10
              .SetWatch Hour (Now), Minute (Now)
              .On "01"

          All you need to do is let VB know about the  Spirit.ocx control. This process is described in the next few sections.

          First Things First

          To begin with, you should enter your VB o r VBA environment. If you have a full version of VB installed, just start it up. If
          you have any of the Microsoft O ffice appli cations, you can use VBA. In Word, for example, choose Tools > Macro > Visual
          Basic Editor.

          S howing Spirit.o cx in the Tool Palette

          To reference Spirit.ocx we first need to  put it in a user form. Create a new form by choosing Insert > UserForm. A  new  form
          a ppears, along with a tool palette labeled Toolbox.

          Spirit.ocx does not appear in the tool palette. To add  it, choose Tools > Additional Controls. In the window that appears,
          scroll down to find Spirit Con trol in the list of available controls.∗ Click on the box to its left to select it, then click on OK.
          You only have to follow this procedure  once. When you use VB again later, the Spirit.ocx control will automatically show up
          in your tool palette, as shown in Figure 8-2.

          A new item with the familiar LEGO logo should  now be in your tool palette. Select this item and place it on the form you just
          created. We won't use the form for anything ex cept as a place to keep the Spirit.ocx control. Change the name to something
          like DummySpiritForm. The control itself has  a default name of Spiritil, which is just fine for our purposes.

          ∗ The Spirit Control item appears in the list on ly if you have already installed the LEGO MINDSTORMS software. During
          this installation, Spirit.ocx is regi stered with the system in such a way that VB or VBA can find it later.
   167   168   169   170   171   172   173   174   175   176   177