June 25, 2024, 06:09:14 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


How to iterate a LL using the LL class ?

Started by RitchieF, February 09, 2016, 08:35:08 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

RitchieF

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

RitchieF

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 

LarryMc

$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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

RitchieF