Wednesday, April 30, 2008

[oopic] oopic array index starts at 0 or 1, and why confusion?

hi all,
the document on the website at http://www.oopic.com/pgchap3.htm says
that an array of objects always start at 1. however the compiler
6.1.1 shows that index starts from 0.

eg. declare: Dim Leg(6) as New oServo in the oopic IDE it says i have
7 oServo objects

but then why is it when I declare for it to start at 1, the array
seems to start at 0 instead? why is this not consistent? in my
program below, after I call SetUp, when I want to move my Leg(1) whose
IOLine is at 28, it moves the servo at IOLine 30, which is Leg(2)(!!!)
Similarly (also in the Main), i call Leg(5) it moves the one that is
supposed to be Leg(6). Everything is off by 1: change position of
Leg(0) would show at Leg(1) and Leg(6) didn't do anything. I had to
get around by naming the servos Leg1, Leg2, ..., Leg6 instead. But
it's convenience to expand my code. Has anybody had a similar problem?

thanks in advance for your help and guidance,
HT

Code:

Dim Leg(6) as New oServo

Sub Main()
Call Setup
Leg(1)=10

End Sub

Sub SetUp()
leg(2).InvertOut = cvTrue 'The servos on the right side
leg(4).InvertOut = cvTrue ' need to turn in reverse.
leg(6).InvertOut = cvTrue

leg(1).Center = 24
leg(2).Center = 36
leg(3).Center = 27
leg(4).Center = 45
leg(5).Center = 33
leg(6).Center = 37

leg(1).IOLine = 30
leg(2).IOLine = 28
leg(3).IOLine = 14
leg(4).IOLine = 12
leg(5).IOLine = 10
leg(6).IOLine = 8

leg(1).Operate = cvTrue 'Turn the servos on.
leg(2).Operate = cvTrue
leg(3).Operate = cvTrue
leg(4).Operate = cvTrue
leg(5).Operate = cvTrue
leg(6).Operate = cvTrue
End Sub


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:

http://groups.yahoo.com/group/oopic/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:

http://groups.yahoo.com/group/oopic/join

(Yahoo! ID required)

<*> To change settings via email:
mailto:oopic-digest@yahoogroups.com
mailto:oopic-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
oopic-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:

http://docs.yahoo.com/info/terms/

No comments:

Post a Comment