Problem Returning an array from a method (resolved)
Greg LaPolla
Posts: 323
Here is the method
calling this method as follows
myVals := Mget
myVals is declared as long myVals[noparse][[/noparse]10]
mVals[noparse][[/noparse]X] is always corrupted. Is this not the correct way to return an array ? or is it not possible at all ?
I have even tried accessing as long[noparse][[/noparse]myVals][noparse][[/noparse]X] that doesn't seem to work either.
Any Ideas or thoughts on this ?
Thanks
Greg
Post Edited (Greg LaPolla) : 7/7/2009 1:24:46 AM GMT
PUB Mget | R[noparse][[/noparse]10], X meter.Init(RC_PIN, HL_PIN, CAP_VAL, COR_FACTR) output.tx(output#CLS) waitcnt(clkfreq + cnt) repeat until ina[noparse][[/noparse]24] == 1 R[noparse][[/noparse]0] := meter.Resistance / 1066 waitcnt(clkfreq/10 + cnt) output.tx(output#HOME) output.Str(String("Steps = ")) output.Str(num.decf(R[noparse][[/noparse]0],3)) output.tx(output#CLREOL) repeat X from 1 to R[noparse][[/noparse]0] output.tx(output#CLS) waitcnt(clkfreq + cnt) repeat until ina[noparse][[/noparse]24] == 1 R[noparse][[/noparse]X] := meter.Resistance / 9 waitcnt(clkfreq/10 + cnt) output.tx(output#HOME) output.Str(String("Step ")) output.Str(num.decf(X,1)) output.Str(String(" = ")) output.Str(num.decf(R[noparse][[/noparse]X],3)) output.tx(output#CLREOL) Result := @R
calling this method as follows
myVals := Mget
myVals is declared as long myVals[noparse][[/noparse]10]
mVals[noparse][[/noparse]X] is always corrupted. Is this not the correct way to return an array ? or is it not possible at all ?
I have even tried accessing as long[noparse][[/noparse]myVals][noparse][[/noparse]X] that doesn't seem to work either.
Any Ideas or thoughts on this ?
Thanks
Greg
Post Edited (Greg LaPolla) : 7/7/2009 1:24:46 AM GMT
Comments
-Phil
e.g.
Var
··············· Long MyVals[noparse][[/noparse]10]
·
The MGet method should be declared like this
Pub MGet(ArrayAddress)
··············· ‘some code
··············· ‘code to fill array elements (maybe in a loop)
··············· Long[noparse][[/noparse]ArrayAddress][noparse][[/noparse]i] := someexpression
·
Then when you call the method use this
··············· MGet(@MyVals)
By the way if you want the type could be Word or Byte.....
Sam
·
Thanks for the input the problem is resolved.