Results 1 to 3 of 3

Thread: redim byref passed array-variable

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    55
    Posts
    1,554
    Rep Power
    174

    redim byref passed array-variable

    i want to know something

    see the small example:
    Uses "console"
    
    Function fTest( ByRef a(), ByVal newDims As Long ) As Long
    
    ' this function shall redim some array a and return new ubound
    
      ReDim Preserve a(newDims)
      
      Function = UBound(a)
      
    End Function
    
    
    Dim foo() As Long ' the real, global array
    
    PrintL Str$( fTest( foo, 123) )
    
    PrintL "now:" & UBound(foo) ' i want it to print 123 too :(
    
    
    WaitKey
    
    thinBasic itself has a few functions that can do this as Dir_ListArray or Parse - where the passed variable to redim is mandatory a string.
    But is it possible from script-side to do similar and redim any array passed by user like that?

    Any ideas- hints?
    Last edited by ReneMiner; 24-01-2015 at 10:13.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736
    It is simple, just specify the type in the generic array parameter:
    Uses "console"
    
    Long laurel() ' the global array
    
    Function TBMain()
    
      Long hardy() ' the local array 
      
      PrintL fTest( laurel, 128)
      PrintL "now:" & UBound(laurel)   
      PrintL
      PrintL fTest( hardy, 256)                                      
      PrintL "now:" & UBound(hardy) 
      
      WaitKey
    
    End Function
     
    Function fTest( ByRef a() As Any, ByVal newDims As Long ) As Long
     
      ReDim Preserve a(newDims)                                      
      Return UBound(a)
       
    End Function
    

    Petr
    Last edited by Petr Schreiber; 24-01-2015 at 10:31.
    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

  3. #3
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    55
    Posts
    1,554
    Rep Power
    174
    Thank you
    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. byref or not byref that is the question.
    By Michael Clease in forum Module SDK (Power Basic version)
    Replies: 2
    Last Post: 04-11-2010, 02:55

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
  •