This has me stumped.
Here is some code (attached) I pulled out of my program and dropped it into a separate file so I could try to find the problem.
I'm using two pointers here,
#pIndex
#pIndexTo
The value of #pIndexTo[1].Range[inw,inl,1] cannot be > 30.
After - AND ONLY after Next a (line 124) there are many range values way over 30 which is incorrect.
If I comment out line 117
'#pIndex[1].Entry[inw,inl,ina] = a
#pIndexTo[1].Range[inw,inl,1] is correct.
The question is why? I need both pointers.
Help!!
Andy.
Hi Andy,
There's a few things I can spot:
- A name collision inside BuildWordSize(), 'a' is being used as an array and as the FOR / NEXT variable counter.
- Array indices start at 0, so to be able to use Range[inw,inl,1] -> int Range[30,30,2] needs to be declared.
- the pointers:
pointer pIndex = NEW(MYUD2,1)
pointer pIndexTo = NEW(MYUD3,1)
are scalar pointers (instead of arrays) so
#pIndex[1].Entry[inw,inl,ina] = a
#pIndexTo[1].Range[inw,inl,1] = ina
you can remove the square brackets
#pIndex.Entry[inw,inl,ina] = a
#pIndexTo.Range[inw,inl,1] = ina
or index = 0.
Fasecero,
Thanks for looking at this problem, turns out one of the pointer array sizes wasn't large enough - a simple answer in the end after trying everything else of course.
Now in my main program (not this one attached) I have other pointers, when I dropped them into this program (and vice versa with my main program) the programs(s) crash while building the pointer arrays (BuildWordSize) sub.
Is there a limit to how many pointers we can use per program? or am I missing anything again?
The attached program works, but un-commenting any of the other pointers causes the crash.
Thanks,
Andy.
pointer pRange
TYPE newudp
int Range[29,100,1]
ENDTYPE
pRange = NEW(newudp,1)
SETTYPE pRange,newudp
pointer pRangeAt
TYPE newudp2
int Range[29,100,1]
ENDTYPE
pRangeAt = NEW(newudp2,1)
SETTYPE pRangeAt,newudp2
Andy,
No limit at all for pointers. But again, remember, array indices start at 0. Your "Range" arrays are out of range ;) these lines
#pRangeAt.Range[inw,inl,1] = ina
...
#pRange.Range[inw,inl,1] = ina
are out of bounds.
What will happen if an array goes out of bounds? anything might happen. The application may crash, it may freeze, it may eject your CD-ROM drive. It may even, if you are really unlucky, appear to work correctly, and corrupt something else on your program later on.
You need to use:
#pRangeAt.Range[inw,inl,0] = ina
...
#pRange.Range[inw,inl,0] = ina
Fasecero,
Yes, as always you are right, guess it's just down to tiredness, just having a heck of a few days work wise.
Amended my main program to ,0's and all is well!
Thanks you again for your time on this!
Andy.
:)