Results 1 to 1 of 1

Thread: why this limitation ? SWAP function

  1. #1

    Lightbulb why this limitation ? SWAP function

    Hi,

    I come across this issue:

    '---Script created on 12-20-2018 16:59:40 by
    
    ' help page : https://www.thinbasic.com/public/products/thinBasic/help/html/index.html?swap.htm
    
    
    uses "console"
    
      Type POINTAPI
          x As Long
          y As Long
    End Type
    
      type desk
          dstart as POINTAPI
          dstop as POINTAPI
    end type
    
      dim lab(10) as desk
      dim uu as Long Value = 555
      dim vv as Long Value = 111
    
      lab(1).dstart.x=555
      lab(2).dstart.x=111
    
    'Simple swap of two variables, ok
      printl "swap simple variables using swap"
      printl uu,vv
      printl "swapping"
    
      swap uu,vv
    
      PrintL uu,vv
      printl "Press a key to next"
      printl ""
      WaitKey
    
    'This was not working back in 2013 according to https://www.thinbasic.com/community/project.php?issueid=420#note2514
    'But now it is ok
      printl "swap UDT array element using swap"
      printl lab(1).dstart.x , lab(2).dstart.X
      printl "swapping"
    
      swap lab(1),lab(2)
    
      printl lab(1).dstart.x , lab(2).dstart.X
      printl "Press a key to next"
      printl ""
      WaitKey
    
    'This works thanks https://www.thinbasic.com/community/project.php?issueid=420#note2514
      printl "swap udt variables using Memory_Swap"
      printl lab(1).dstart.x , lab(2).dstart.X
      printl "swapping"
    
      Memory_Swap(VarPtr(lab(1).dstart.x), VarPtr(lab(2).dstart.x), SizeOf(Long))
    
      printl lab(1).dstart.x , lab(2).dstart.X
      printl "Press a key to next"
      printl ""
      WaitKey
    
    'So why not this ? swap lab(1).dstart.x , lab(2).dstart.X
      printl "swap udt variables using swap"
      printl lab(1).dstart.x , lab(2).dstart.X
      printl "swapping : here raise an error: Expected comma ',' but found something else."
      printl "Press a key to error"
      waitkey
      
      swap(lab(1).dstart.x, lab(2).dstart.x)
    
      printl lab(1).dstart.x , lab(2).dstart.X
      printl "Press a key to next"
    
      WaitKey
    
    so, as seen, it is possible with memory_swap, then why swap comes with this limitation ?




    https://www.thinbasic.com/community/...ll=1#post89255 this simple (1st post) order / rorder is a pleasant idea.
    Last edited by DirectuX; 20-12-2018 at 19:54.
    ThinBasic 1.11.6.0 ALPHA - Windows 8.1 x64

Similar Threads

  1. Replies: 5
    Last Post: 30-07-2020, 10:53
  2. [Q]: Function f() PTR?
    By ReneMiner in forum thinBasic General
    Replies: 3
    Last Post: 18-07-2013, 20:29
  3. Idea for ordered SWAP
    By Robert Hodge in forum Suggestions/Ideas discussions
    Replies: 7
    Last Post: 15-07-2013, 20:54
  4. function returned value
    By sandyrepope in forum thinBasic General
    Replies: 4
    Last Post: 07-12-2007, 22:54

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •