Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 23

Thread: Array Left$

  1. #11
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171

    example

    exactly that:

    Uses "console"
     
    
    Type tBase 
      pText As DWord
    
      '-------------------------------------------------------------------
      Function TextSet(ByVal sText As String, _
              Optional ByVal lLine As Long    _
                     ) As String 
      '-------------------------------------------------------------------
      
      ' set either all text (no line-number)
      ' or replace a certain line if lLine exists
     ' negative lLine = simply append text  
      
      Local pLine()    As DWord At 0
      Local sLine()    As String
      Local i, nLines  As Long
      
      nLines = Parse sText, sLine, $CRLF
      
          
      If Not lLine Then
        ' no line-number, so sText is completely new text
      
        If HEAP_Size(Me.pText) >= 4 Then
          ReDim pLine(HEAP_Size(Me.pText)/4) At Me.pText
          For i = 1 To UBound(pLine)
            HEAP_Free(pLine(i))
          Next
        EndIf
        
        If nLines Then
          Me.pText = HEAP_ReAllocByStr(Me.pText, Repeat$(nLines, MKDWD$(0)) )
          ReDim pLine(nLines) At Me.pText
          For i = 1 To nLines
            pLine(i) = HEAP_AllocByStr(sLine(i))  
          Next
        Else
          HEAP_Free(Me.pText)
          Me.pText = 0
        EndIf
      Else 
        If HEAP_Size(Me.pText) >= 4 Then
          ReDim pLine(HEAP_Size(Me.pText)/4) At Me.pText
        
          If Between(lLine, 1, UBound(pLine)) Then
            ' replace lLine with new sText
            Select Case nLines
              Case 0
                HEAP_Free(pLine(lLine))
                pLine(lLine) = 0
                
              Case 1
                pLine(lLine) = HEAP_ReAllocByStr(pLine(lLine), sLine(1))
             
              Case Else 
                If lLine + (nLines - 1) > UBound(pLine) Then
                  Me.pText = HEAP_ReAllocByStr(Me.pText, HEAP_Get(Me.pText) & Repeat$(lLine + (nLines - 1) - UBound(pLine), MKDWD$(0))  )
                  ReDim pLine(HEAP_Size(Me.pText)/4) At Me.pText
                EndIf
                For i = 1 To nLines 
                  pLine(i + lLine - 1) = HEAP_AllocByStr(sLine(i))  
                Next
            End Select
          Else
            ' lLine is out of current range
            If lLine < 1 Then
            ' simply append it
              
              lLine = UBound(pLine)
              Me.pText = HEAP_ReAllocByStr(Me.pText, HEAP_Get(Me.pText) & Repeat$(nLines, MKDWD$(0)))  
              ReDim pLine(HEAP_Size(Me.pText)/4) At Me.pText
              For i = 1 To nLines
                pLine(i + lLine) = HEAP_AllocByStr(sLine(i))  
              Next
            Else 
            ' insert empty lines until all available  
              Me.pText = HEAP_ReAllocByStr(Me.pText, HEAP_Get(Me.pText) & Repeat$(lLine + (nLines - 1) - UBound(pLine), MKDWD$(0)) ) 
              ReDim pLine(HEAP_Size(Me.pText)/4) At Me.pText
              For i = 1 To nLines
                pLine(i + lLine - 1) = HEAP_AllocByStr(sLine(i))  
              Next
            EndIf  
          
          EndIf
        Else
          ' Me.pText is empty
          Me.pText = HEAP_AllocByStr(Repeat$(nLines, MKDWD$(0)) )
          ReDim pLine(HEAP_Size(Me.pText)/4) At Me.pText
          For i = 1 To nLines
            pLine(i) = HEAP_AllocByStr(sLine(i))  
          Next
            
        EndIf  
      EndIf
      
      Function = sText
    End Function
    
    
    End Type
    
    Function TBMain()
      Local x As tBase
      
      PrintL x.TextSet( "Hello" & $CRLF _
                       & "this" & $CRLF _
                       & "is a" & $CRLF _
                       & "test" )
     
      PrintL
      PrintL "---Press a key to finish---"
      WaitKey
    End Function
    
    EDIT: missing parenthesis corrected (2 times, lines 60, 73 or 80)
    Last edited by ReneMiner; 31-10-2015 at 14:26.
    I think there are missing some Forum-sections as beta-testing and support

  2. #12
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,781
    Rep Power
    10
    OK, got example and able to reproduce the problem.
    I'm checking.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #13
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    i'm going to visit my girlfriend in hospital now... be back in the evening
    I think there are missing some Forum-sections as beta-testing and support

  4. #14
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,781
    Rep Power
    10
    Thanks for helping me.
    It will be a bit long to solve this, it is related to IF/ELSE/END IF nesting level.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #15
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,781
    Rep Power
    10
    I think I've fixed the problem.
    Uploaded an updated 1.9.16.0
    Let me know.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #16
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    came not far enough to test Array Extract yet but thinAir bugs again (see mail from last week)
    I think there are missing some Forum-sections as beta-testing and support

  7. #17
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,781
    Rep Power
    10
    Yes, didn't had time to see all your reports but will check next days.
    Work load will be a little lower next few weeks so I think to have some time to go on to fix and develop new features.

    Actually I'm interested to know if today bug is solved.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  8. #18
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    todays bug seems solved. Also Array Extract works really nice & fast

    btw. Found duplicate keyword in thinBasic_Keywords.ini

    ACCELAPI
    I think there are missing some Forum-sections as beta-testing and support

  9. #19
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,781
    Rep Power
    10
    Great.

    It is a predefined UDT: http://www.thinbasic.com/public/prod...l?accelapi.htm
    Maybe I've defined twice.
    I will check where

    If more UDT having the same name are defined in different places but they are are structured the same, thinBasic does not complain.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  10. #20
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,781
    Rep Power
    10
    I need your opinion.

    Regarding PTR option (it means mainArray is an array of pointers to string) ...
    do you think also DestinationArray MUST be a PTR array or only source should be?
    Last edited by ErosOlmi; 31-10-2015 at 22:31.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Idea for LEFT$/RIGHT$ variable that work in reverse
    By Robert Hodge in forum Suggestions/Ideas discussions
    Replies: 6
    Last Post: 30-06-2013, 10:26
  2. TBGL_GetWindowKeyState - left Alt-key sucks
    By ReneMiner in forum TBGL module by Petr Schreiber
    Replies: 1
    Last Post: 23-02-2013, 21:10
  3. copy array of UDT to another array in one step?
    By ReneMiner in forum thinBasic General
    Replies: 3
    Last Post: 02-11-2012, 01:15
  4. Be left in awe :)
    By kryton9 in forum General
    Replies: 8
    Last Post: 19-05-2008, 21:49
  5. Usage of the LEFT$ MID$ RIGHT$ Keywords
    By Michael Clease in forum Samples for help file
    Replies: 1
    Last Post: 28-05-2007, 11:45

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
  •