Page 170 - The Unofficial Guide to Lego Mindstorms Robots
P. 170
159
8
Using Spirit.ocx with Visual Basic
In this chapter:
• You May Alr eady Have
V isual Basic
• About Spirit.ocx
• Calling Spirit.ocx Functions
• Immediate and De layed
Gratification
• Programs, Tasks, and
S ubroutines
• Tips
• Retrieving the Datalog
• Online Resources
P art of the appeal of the programming environments described in Chapter 4, Not Quite C, and Chapter 6, pbFORTH, is that
they don't tie you down to using Windows on your development PC. The programming environment that comes with RIS,
RCX Code, is a Windows-only solution, which is distressing to people who prefer other operating systems. Aside from
providing better capabilities than RCX Code, NQC and pbFORTH also allow you to develop RCX software using your
o perating system of choice.
In this chapter, I'll describe a Windows-only solution— programming your robots using Visual Basic (VB). Visual Basic is a
language developed by Microsoft and included with many of their other products. The link between Visual Basic and your
robots is a file called Spirit.ocx, which is installed as part of the standard RIS software. In this chapter, I'll show you how to use
Visual Basic and Spirit.ocx to control and program your robots.
If you are running windows, chances are good that you already have Visual Basic somewhere, as I'll describe in the next
section. Because VB is so widespread in the Windows world, I won't attempt to describe the language itself. There are several
good online tutorials, including information and examples at Microsoft's site. (See the "Online Resources" section at the end of
this chapter for references.) Instead, this chapter focuses on how you can use VB to write programs for your RCX.
You May Already Have Visual Basic
Visual Basic is a programming language made by Microsoft. You can purchase it as a separate product. The "Learning
Edition" is $109US. A "Professional Edition,"