Results 1 to 10 of 25

Thread: some arrays goodies

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    some arrays goodies

    some array goodies
    some features available only in thinbasic
    Dim SomethingValue(500) As Long
    SomethingValue(31)=31,32,33,34,35,36,37,38,39,40

    the array from item 31 to 40 filled with these numbers
    we can also use :
    Array Assign SomethingValue(31)=31,32,33,34,35,36,37,38,39,40

    Dim TextMatrix() As String 'dynamic string array
    myText = "12_345_6789"
    nLines = Parse(myText, TextMatrix, "_")
    For i=1 To UBound(TextMatrix)
    PrintL TextMatrix(i)
    Next

    the parse results fill the array items neatly without any extra code: note this :nLines = Parse(myText, TextMatrix, "_")

    there are too many other goodies i will post from time to time
    If you have other goodies about arrays you can add here
    the complete example:
    Uses "console"
    
    Dim TextMatrix(), myText, nLines As String
    Dim SomethingValue(500) As Long 
    Long i
    SomethingValue(1)=1,2,3,4,5,6,7,8,9,10
    SomethingValue(31)=31,32,33,34,35,36,37,38,39,40
    Array Assign SomethingValue(401)=401,402,403,404,405
    For i = 1 To 20
    PrintL "index = "+Str$(i)+" "+SomethingValue(i)
    Next 
    PrintL "******************************************"
    For i = 31 To 40
    PrintL "index = "+Str$(i)+" "+SomethingValue(i)
    Next
    PrintL "******************************************"  
    For i = 401 To 405
    PrintL "index = "+Str$(i)+" "+SomethingValue(i)
    Next
    PrintL "******************************************"  
    myText = "12_345_6789"
    nLines = Parse(myText, TextMatrix, "_") 
    For i=1 To UBound(TextMatrix)
    PrintL TextMatrix(i)
    Next
      
    WaitKey
    
    Last edited by primo; 20-02-2017 at 17:30.

  2. #2
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    121
    Rep Power
    21
    Hi,
    Thanks for introducing these features in TB.

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Primo,

    did you know you can easily list array values without for cycle? Check this:
    long SomethingValue(500)
    
    SomethingValue(1)=1,2,3,4,5,6,7,8,9,10
    SomethingValue(31)=31,32,33,34,35,36,37,38,39,40
    SomethingValue(401)=401,402,403,404,405
    
    msgbox 0, join$(SomethingValue, ",", "0", 1, 10)
    msgbox 0, join$(SomethingValue, ",", "0", 31, 40)
    msgbox 0, join$(SomethingValue, ",", "0", 401, 405)
    
    Petr
    Last edited by Petr Schreiber; 23-02-2017 at 11:05.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

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


    I like those ... challenges

    Here we have "virtual variable" usage. Fill an array, read data as a matrix using a "virtual" variable
    Virtual variable are variable that do not allocate/deallocate any memory but use memory allocated for other variables to read/write data (also in different ways)
    '---An array of 9 elements
    Long SomeValue_Array(9)
    '---A matrix of 9 elements that share the same memory of the memory allocated for the array
    Long SomeValue_Matrix(3, 3) At VarPtr(SomeValue_Array(1))
    
    '---Fill the array
    SomeValue_Array(1)=1,2,3,4,5,6,7,8,9                                                          
    
    '---Read as matrix
    MsgBox 0, Join$(SomeValue_Matrix, ",", $CRLF)
    
    Have fun.
    Eros
    Last edited by ErosOlmi; 23-02-2017 at 13:49.
    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. #5
    Thanks Petr and Eros, i was sure there are many golden eggs in thinbasic.
    the classic programmer (like me) who are grown with QB or VB find these shortcuts and tips very strange, but it is in fact very useful and handy and time saving.
    thanks

  6. #6
    Yes absolutly true. Many many thanks

    Kind regards,

    Axel

Similar Threads

  1. 3d arrays?
    By JosephE in forum thinDebug
    Replies: 2
    Last Post: 08-08-2010, 23:21
  2. Arrays
    By Charles Pegge in forum O2h Compiler
    Replies: 0
    Last Post: 17-03-2009, 16:09

Members who have read this thread: 3

Posting Permissions

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