Results 1 to 2 of 2

Thread: For X At pStart To pEnd Step Sizeof(X)

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170

    For X At pStart To pEnd Step Sizeof(X)

    idea to use For-At-Syntax to push virtual variables along a row of data.

    For X [As <Type>] At <pStart> To <pEnd> [Step <lSize>] [{While | Until | When} <TRUE>]
    
      ...
    
     {statements}
    
     [Exit For]
    
     [Iterate For]
    
     {statements}
    
      ...
    
    Next
    
    Don't know if instant declaration [As <Type>] were possible - since not always numeric type here...
    pStart & pEnd would await memory-pointer
    lSize were the amount to push the variable, default Step-size were +1
    Iterate For were probably complicated?

    A while ago i posted some suggestion to support-section about to improve SetAt when pushing a "virtual surfing variable" along a row of data-elements...

    Here the -in current tB-syntax running - example i've posted:
    ' #Filename "SetAt_surfer.tBasic"
    Uses "console"
     
    ' data could be an array or a row of pointers or whatever anywhere
     
    String data = "abcdefghijklmnopqrstuvwxyz" 
    
    
    ' --------------------------------
    ' i want to avoid doing this:
    ' --------------------------------
    ' LOCAL I AS LONG ' avoid another local I !  
    ' Local char(StrPtrLen(StrPtr(data))/SizeOf(Byte)) As Byte At StrPtr(data)
    ' For i = 1 to CountOf(char)
    '   Print Chr$(char(I))   ' avoid always indexing the same element
    ' Next
    ' --------------------------------
    
     
    ' type of data-elements in this case be Byte (chr$)
    ' so prepare a "surfer" at start of data:
     
    Local char As Byte At StrPtr(data)
    
    ' As long our surfing variable is in valid area:
    While GetAt(char) < StrPtr(data) + StrPtrLen(StrPtr(data)) 
       
      ' do something with current element of data
      Print Chr$(char)        
       
      ' move on to next element:
      ' SetAtNext(char)
      SetAt( char, GetAt(char) + SizeOf(char) )
    Wend
     
    PrintL
     
    ' Now lets go backward:          
    
    Do
    
      ' move to previous element:
      ' SetAtPrevious(char)
      SetAt( char, GetAt(char) - SizeOf(char) )
     
      ' do something with current element of data
      Print Chr$(char)        
       
     
    Loop Until GetAt(char) <= StrPtr(data)
    
    PrintL
    PrintL "key to future"
    WaitKey
    
    Now this is my new idea:

    still same variables as above, but not running yet:
    ' change data to be heap, could be String as well:
    DWord pData = HEAP_AllocByStr(data) 
    
    For char At pData To HEAP_End(pData)  
      Print Chr$(char)
    Next
    PrintL
    
    For char At HEAP_End(pData) To pData Step -SizeOf(char) 
      Print Chr$(char)
    Next
    PrintL
    PrintL "key to get happy"
    WaitKey
    
    Last edited by ReneMiner; 19-02-2016 at 10:18.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    one more running example:
    ' #Filename "For_At_example.tBasic"
    
    Uses "console"
     
    
    Function TBMain()
    
      ' create memory-pointer to an array of memory-pointers:
      DWord pArray = HEAP_AllocByStr( MKDWD$(HEAP_AllocByStr("data of line 1"), _ 
                                             HEAP_AllocByStr("data of line 2"), _
                                             HEAP_AllocByStr("data of line 3"), _
                                             HEAP_AllocByStr("data of line 4")) )
      
      ' prepare a surfing variable to read array-members:
      Local pLine As DWord At 0
      
      ' current syntax:
      
      For pos As DWord = pArray To HEAP_End(pArray) Step SizeOf(pLine)
        SetAt(pLine, pos)
        PrintL HEAP_Get(pLine)
      Next
    
      ' desired syntax:
    /*
      For pLine At pArray To HEAP_End(pArray) Step SizeOf(pLine)
        PrintL HEAP_Get(pLine)
      Next
    */
      PrintL
      PrintL "key to end"
      WaitKey 
    End Function
    
    Last edited by ReneMiner; 14-02-2016 at 11:09.
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. SizeOf(<stringexpression>)
    By ReneMiner in forum Suggestions/Ideas discussions
    Replies: 0
    Last Post: 15-09-2015, 09:04
  2. single step execution for debugging
    By chliu in forum thinBasic General
    Replies: 5
    Last Post: 10-03-2012, 08:24
  3. Little little, step by step :)
    By ErosOlmi in forum Shout Box Area
    Replies: 11
    Last Post: 23-08-2010, 10:44
  4. I step back, no more project leader. (Former Should we go on?)
    By Michael Hartlef in forum CM contest 2009
    Replies: 15
    Last Post: 15-10-2008, 01:12

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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