Results 1 to 5 of 5

Thread: Multi-type parameters

  1. #1

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479

    Multi-type parameters

    VB Code:
    1. Private Sub Form_Load()
    2.    
    3.     Dim myArray() As Single
    4.    
    5.     MsgBox getSize(myArray)
    6.    
    7. End Sub
    8.  
    9. Private Function getSize(inArray() As Variant) As Integer
    10.    
    11.     On Error Resume Next
    12.    
    13.     getSize = 0
    14.    
    15.     getSize = UBound(inArray)
    16.    
    17. End Function
    This won't work because the getSize function expects a Variant array.
    Apart from a great long list of optional paramaters and loads of ElseIf statements is there any way to write a function that will accept any data type array? Any data type actually.
    This really bugs me.

  2. #2
    WALDO
    Guest
    VB Code:
    1. Private Function getSize(inArray() As ParamArray) As Integer
    2.    
    3.     On Error Resume Next
    4.    
    5.     getSize = 0
    6.    
    7.     getSize = UBound(inArray)
    8.    
    9. End Function

  3. #3
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    This also worked for me (I guess for the same reasons)

    VB Code:
    1. Private Function getSize(inArray As Variant) As Integer
    This world is not my home. I'm just passing through.

  4. #4

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    VB Code:
    1. Private Function getsize(ParamArray inArray()) As Integer
    2.    
    3.     On Error Resume Next
    4.    
    5.     getsize = 0
    6.    
    7.     getsize = UBound(inArray)
    8.    
    9. End Function
    Thanks WALDO, I had to put ParamArray first to get it to work like above, don't know why.
    I wish I'd asked before making loads of copies of functions for working with arrays.

  5. #5

    Thread Starter
    Hyperactive Member GlenW's Avatar
    Join Date
    Nov 2001
    Location
    Gateshead, England
    Posts
    479
    Its not working
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.    
    5.     Dim myArray() As Single
    6.     Dim i As Integer
    7.     i = 9
    8.     ReDim Preserve myArray(i)
    9.    
    10.     MsgBox getSize(myArray)
    11.    
    12. End Sub
    13.  
    14. Private Function getSize(ParamArray inArray()) As Integer
    15.    
    16.     On Error Resume Next
    17.    
    18.     getSize = 0
    19.    
    20.     getSize = UBound(inArray)
    21.    
    22. End Function
    returns 0

Posting Permissions

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



Click Here to Expand Forum to Full Width