Results 1 to 1 of 1

Thread: Ideas for dynamic Array-constructor on the fly

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

    Ideas for dynamic Array-constructor on the fly

    the idea came up in this discussion already and was continued in several others...

    As I remember there is some use of Brackets to assign values to multidimensional arrays in a matrix-way somehow like this:

    Dim A(2,3) As Long = [ 1, 2, 3] ,_
                        [ 4, 5, 6]
    
    but might be I'm wrong here and messed something up because I can not find it in the help any more, where I thought I read this... or it was in some example of Petr?

    Anyway- the idea is to use brackets as an array-constructor on the fly in a few different ways. Most usual would be this:
    Dim A() As Long = [1, 2, 3, 4, 5]
    'as a replacement for
    Dim A(5) As Long = 1, 2, 3, 4, 5
    
    which does not seem to be of any use at all on the first sight
    Maybe sense grows in this example:
    Dim B() As Double = [ 1.23, 2.34, 3.45, [ 4.56, 5.67, 6.78 ]]  
    ' to replace
    Dim B(3,2) As Double = ...
    
    still not very convinient. Imagine passing a few different values to some function as passing some array as function parameters alike this:
    Sub demonstrate1( ByVal S() as String )
    '...
    End Sub
    
    ' prepare some variable-content:
    String xx = "test"
    Dim yy(123) As String ' fill this somehow in your imagination
    
    ' and call this way now:
    
    demonstrate1( ["Hi", xx, yy(7), yy(9)] )
    
    ' would create/pass local String-array S(4) with 
    ' these values to the sub above
    
    '...
    
    Sub demonstrate2( ByRef S() as String )
    
    ' the single variable-references get treated inside this sub 
    ' as if it was a local array S() in one row so one could
    ' perform thinBasic-Array-methods on them now - and even
    ' could Sort content of different variables
     ' of course this way will not accept a simple "Hi" as above
    
    End Sub
    
    to differentiate this from that:

    Sub demonstrate3( S1() As String, S2() As String )
    '...
    End Sub
    'passing this:
    demonstrate3(["I", "am", "S1", ["Second", "Dimension", "S1"]], ["First", "Dimension", "S2", "Here"] )
    
    will create local array S1(3, 2) and S2(4)

    more dimensions perhaps
    Dim a() as String = [ "1.1.1","2.1.1","3.1.1",["1.2.1","2.2.1","3.2.1",["1.3.1","2.3.1","3.3.1",["1.4.1","2.4.1","3.4.1"]]], _
                          "1.1.2","2.1.2","3.1.2",["1.2.2","2.2.2","3.2.2",["1.3.2","2.3.2","3.3.2",["1.4.2","2.4.2","3.4.2"]]], _  
                          "1.1.3","2.1.3","3.1.3",["1.2.3","2.2.3","3.2.3",["1.3.3","2.3.3","3.3.3",["1.4.3","2.4.3","3.4.3"]]], _
                          "1.1.4","2.1.4","3.1.4",["1.2.4","2.2.4","3.2.4",["1.3.4","2.3.4","3.3.4",["1.4.4","2.4.4","3.4.4"]]], _  
                          "1.1.5","2.1.5","3.1.5",["1.2.5","2.2.5","3.2.5",["1.3.5","2.3.5","3.3.5",["1.4.5","2.4.5","3.4.5"]]] ]  
    
    equals
    Dim a(3,4,5) as String ' and fill it
    
    Last edited by ReneMiner; 16-07-2013 at 11:53.
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. Redim non-dynamic array?
    By ReneMiner in forum thinBasic General
    Replies: 3
    Last Post: 11-05-2013, 00:05
  2. 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
  3. Oh wow, got it working, dynamic textures
    By kryton9 in forum TBGL General
    Replies: 16
    Last Post: 22-06-2007, 01: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
  •