Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Array Left$

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

    Array Left$

    Currently I try to find a fast method to scan some dynamic string-array for just a part of the string to create some auto-complete-stuff.

    So I have a dynamic string-array containing all the keywords.

    Now when the user types for example the letters "func" - it's obvious that he wants to type either "Function", "Function_CParams" or something like that so i want my script make to suggest this.

    The solution were some Array-method that works a little bit as Array Scan myArray, Collate Ucase, = "func" but i imagine more like

    Dim sourceArray() As String
    Dim destinationArray() As String
    
    Dim sFile as String = "c:\thinBasic\thinAir\Syntax\thinBasic\thinBasic_Keywords.ini"
    Dim nKeywords, nMatches As Long
    
    nKeywords = Parse File sFile, sourceArray, $CRLF
    '...
    
    nMatches = Array sourceArray,  Left$ = "FUNC" [, Collate Ucase] To destinationArray
    
    where it performs a complete array scan on sourceArray() and all members of sourceArray that match "FUNC" will be collected in destinationArray().
    Array-members thats length is less then "FUNC" should not cause error.
    Syntax above is just for better understanding what i mean.
    Instead of "Left$" it could be named however you like

    nMatches = Array Select sourceArray, StartsWith "FUNC", Collate Ucase To destinationArray
    
    alternative it could return an array of indexes - or just work as the current Array Scan-way

    Long lStart, lPos
    Do
      lPos = Array Scan sourceArray(lStart+1), Collate Ucase, StartsWith "FUNC"
      If lPos = 0 Then Exit Do
    '... do something with matching element
    '... go for the next one....
      lStart += lPos
    Loop
    
    StartsWith/EndsWith (both are keywords already) in that case were only a switch as "=", "<=" etc.
    Of course only valid to scan for strings.
    If possible it could also Array Scan Ptr for elements that StartsWith/EndsWith
    i just care for functionality
    Last edited by ReneMiner; 29-10-2015 at 23:50.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    It's on the go.
    I like it in both the syntax you suggested.

    I'm just thinking what's the best way to implement.
    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. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    What about the following syntax:

    nItems = ARRAY EXTRACT mainArray(), StartsWith | EndsWith | Like (regular expression string) [, Collate ...] InTo destinationArray
    
    nItems will contain the number of elements found
    mainArray will be automatically sorted
    destinationArray will automatically free and re-dimensioned

    Like comparison will use regular expressions already valid for REGEXPR$. Anyway still to think how to do this one.
    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

  4. #4
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    reads good

    Into


    a keyword with a bright future... should make more use of it.

    inMyPockets = [Module]_PutStuff [source [,condition1 [, condition2...]]] Into myPockets()
    Last edited by ReneMiner; 29-10-2015 at 23:48.
    I think there are missing some Forum-sections as beta-testing and support

  5. #5
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    Quote Originally Posted by ErosOlmi View Post
    ...
    mainArray will be automatically sorted
    ...
    i'm not sure if this is necessary to sort the keywords again on each call.
    Perhaps suggest in help to sort the array previously for best results, but if it's sorted once...
    I think there are missing some Forum-sections as beta-testing and support

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Development done.
    New functionality will be present in next 1.9.16 version that I will publish by tomorrow (or before if I finish few things)

    Syntax will be the following:

    ARRAY EXTRACT MainArray, [COLLATE UCASE,] {StartsWith | EndsWith | Contains} ComparisonStringExpression InTo DestinationArray
    
    Example:

    Uses "Console"
    
    Dim sourceArray() As String
    Dim destinationArray() As String
    Dim nKeywords, nMatches, nCount As Long
     
    nKeywords = Parse APP_ListKeywords($CRLF), sourceArray, $CRLF
    
    nMatches = Array extract sourceArray(), Collate Ucase, StartsWith "FUNC" inTo destinationArray
    
    PrintL "Found:", nMatches
    For nCount = 1 To nMatches
      PrintL nCount, destinationArray(nCount)
    Next
    
    WaitKey
    
    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

  7. #7
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    nnnnnnice

    Quote Originally Posted by ErosOlmi View Post
    Development done.
    New functionality will be present in next 1.9.16 version that I will publish by tomorrow (or before if I finish few things)

    Syntax will be the following:

    ARRAY EXTRACT MainArray, [COLLATE UCASE,] {StartsWith | EndsWith |  Contains} ComparisonStringExpression InTo DestinationArray
    
    Would it also be possible to do this:
    ARRAY EXTRACT pArray PTR , [COLLATE UCASE,] {StartsWith | EndsWith |  Contains} ComparisonStringExpression InTo DestinationArray
    
    ?
    the chair i'm sitting on seems to burn
    Last edited by ReneMiner; 31-10-2015 at 11:52.
    I think there are missing some Forum-sections as beta-testing and support

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Not in this release but if it is working fine with standard string arrays, it is quite easy to add arrays of pointers.
    So first check this and soon I will add the PTR version.

    Updated 1.9.16 is already into the link you know.

    Just test it and if OK I will work for the tomorrow public release.
    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

  9. #9
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    bad news: scripts don't run no more - an optional function-parameter gets lost within a function:

    this one of my type-functions:
    '-------------------------------------------------------------------
    Function TextSet(ByVal sText As String, _
            Optional ByVal lLine As Long    _
                     ) As String 
    '-------------------------------------------------------------------
    
    the variable lLine is used a few times succesfully...
    100 lines of code further, in same function follows this
    '...
           If lLine < 1 Then
    ' ...
    
    Error Code 30
    Variable not defined or misspelled Keyword

    Token found: lLine

    - script as is was running a few minutes ago using the previous tB 1.9.16 alpha
    Last edited by ReneMiner; 31-10-2015 at 14:05.
    I think there are missing some Forum-sections as beta-testing and support

  10. #10
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Strange, here optional parameters seems working just fine.
    I did'n change anything on that matter.

    I worked on FOR/NEXT maybe is in this area.

    I will check but I need a simple example showing the problem.
    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 1 of 3 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
  •