IonicWind Software

IWBasic => General Questions => Topic started by: RitchieF on February 09, 2016, 08:35:08 AM

Title: How to iterate a LL using the LL class ?
Post by: RitchieF on February 09, 2016, 08:35:08 AM
I'm about writing a cnc tool and want to store the calculated values in a linked list for later use.

Using some sample code from the help file I'm able to fill a linked list using LarryMc's LL class.

But iterating through the list from the beginning to end to read the values I have no success.

Any help appreciated

Richard

Quote$use "LList.lib"
$include "LList.inc"

openconsole
Def temp as POINTER
Def testpos as POINTER

Def MyList as LList
MyList.Create()


int I
TYPE foo
  def num as int
  DEF sinus as double
  DEF cosinus as double
ENDTYPE

'some sample values
double startAngle = 90
double endAngle = 0
float radius = 50
int clockwise = 1  '// <-- G02 is clockwise
float geometryDeviation = 0.2
float OfChordAngle = 0
float chordAngle = 0


for I = 1 to 10
If MyList.AddEnd(NEW(foo,1))=0
  MyList.#<foo>m_pCurData.num = I
  MyList.#<foo>m_pCurData.sinus = (sind(I*9))* radius
  MyList.#<foo>m_pCurData.cosinus = (cosd(I*9))* radius
  print "fill the LL number => ",MyList.#<foo>m_pCurData.num
  print "fill the LL Sinus => ",MyList.#<foo>m_pCurData.sinus
  print "fill the LL Cosinus => ",MyList.#<foo>m_pCurData.cosinus
else
   print MyList.ErrMsg()
endif
Next I

testpos=MyList.getFirst()

print MyList.#<foo>m_pCurData.num," "

for I = 2 to MyList.Count()
   testpos=MyList.#<foo>m_pCurpos
   temp = MyList.ReadDataPos(testpos)
   print MyList.#<foo>m_pCurData.num," "
next I




MyList.ClearAll(TRUE)

print " Any key to end"
do:until inkey$<>""
closeconsole
Title: Re: How to iterate a LL using the LL class ?
Post by: RitchieF on February 09, 2016, 11:01:59 AM
Okay, now I have this solution :
QuoteIf MyList.GetFirst() = 0
   print MyList.#<foo>m_pCurData.num," Sinus ",MyList.#<foo>m_pCurData.sinus," Cosinus ",MyList.#<foo>m_pCurData.cosinus
else
   print MyList.ErrMsg()
endif
for I = 2 to MyList.Count()
   If MyList.GetNext() = 0
      print MyList.#<foo>m_pCurData.num," Sinus ",MyList.#<foo>m_pCurData.sinus," Cosinus ",MyList.#<foo>m_pCurData.cosinus
   else
      print MyList.ErrMsg()
   endif
next i

But isn't there a way to have a loop starting at 1 instead starting at 2 ??

Richard 
Title: Re: How to iterate a LL using the LL class ?
Post by: LarryMc on February 09, 2016, 12:25:42 PM
$use "LList.lib"
$include "LList.inc"

openconsole
Def temp as POINTER
Def testpos as POINTER

Def MyList as LList
MyList.Create()


int I
TYPE foo
  def num as int
  DEF sinus as double
  DEF cosinus as double
ENDTYPE

'some sample values
double startAngle = 90
double endAngle = 0
float radius = 50
int clockwise = 1  '// <-- G02 is clockwise
float geometryDeviation = 0.2
float OfChordAngle = 0
float chordAngle = 0


for I = 1 to 10
If MyList.AddEnd(NEW(foo,1))=0
  MyList.#<foo>m_pCurData.num = I
  MyList.#<foo>m_pCurData.sinus = (sind(I*9))* radius
  MyList.#<foo>m_pCurData.cosinus = (cosd(I*9))* radius
  print "fill the LL number => ",MyList.#<foo>m_pCurData.num
  print "fill the LL Sinus => ",MyList.#<foo>m_pCurData.sinus
  print "fill the LL Cosinus => ",MyList.#<foo>m_pCurData.cosinus
else
   print MyList.ErrMsg()
endif
Next I
/* Original Code
If MyList.GetFirst() = 0
   print MyList.#<foo>m_pCurData.num," Sinus ",MyList.#<foo>m_pCurData.sinus," Cosinus ",MyList.#<foo>m_pCurData.cosinus
else
   print MyList.ErrMsg()
endif
for I = 2 to MyList.Count()
   If MyList.GetNext() = 0
      print MyList.#<foo>m_pCurData.num," Sinus ",MyList.#<foo>m_pCurData.sinus," Cosinus ",MyList.#<foo>m_pCurData.cosinus
   else
      print MyList.ErrMsg()
   endif
next i
*/
/* new code *************************************************************************************************************/
If MyList.GetFirst() = 0
   print MyList.#<foo>m_pCurData.num," Sinus ",MyList.#<foo>m_pCurData.sinus," Cosinus ",MyList.#<foo>m_pCurData.cosinus
while MyList.GetNext() = 0
print MyList.#<foo>m_pCurData.num," Sinus ",MyList.#<foo>m_pCurData.sinus," Cosinus ",MyList.#<foo>m_pCurData.cosinus
endwhile
else
print MyList.ErrMsg()
endif
print "That's all folks!"
/* end of new code ******************************************************************************************************/


MyList.ClearAll(TRUE)

print " Any key to end"
do:until inkey$<>""
closeconsole
Title: Re: How to iterate a LL using the LL class ?
Post by: RitchieF on February 10, 2016, 09:23:11 AM
Thanks Larry!

Exactly what I meant.

Richard