ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   templated array as function parameters (https://www.excelbanter.com/excel-programming/315701-templated-array-function-parameters.html)

Steven Deng

templated array as function parameters
 
Hello, I am writing some code to test whether an array is undefined (See
code below). I am passing an array of integers to the function right now,
and I am wondering if i can extend this so that it can be apply to array of
any type (even user defined type). Something like a function template.




Public Function isUndefArray(ByRef a() As integer) As Boolean
Dim l As Long
On Error Resume Next
l = UBound(a)
If Err.Number = 9 Then
Debug.Print Err.Description

isUndefArray = True
Exit Function
End If
isUndefArray = False
End Function



Jim Rech

templated array as function parameters
 
I think this will work for any type of array:

''Returns True is the passed array has been dimensioned else False
Function ArrayDimmed(vntArray As Variant) As Boolean
On Error Resume Next
ArrayDimmed = IsNumeric(UBound(vntArray))
End Function


--
Jim Rech
Excel MVP
"Steven Deng" wrote in message
news:99cid.107442$%k.6341@pd7tw2no...
| Hello, I am writing some code to test whether an array is undefined (See
| code below). I am passing an array of integers to the function right now,
| and I am wondering if i can extend this so that it can be apply to array
of
| any type (even user defined type). Something like a function template.
|
|
|
|
| Public Function isUndefArray(ByRef a() As integer) As Boolean
| Dim l As Long
| On Error Resume Next
| l = UBound(a)
| If Err.Number = 9 Then
| Debug.Print Err.Description
|
| isUndefArray = True
| Exit Function
| End If
| isUndefArray = False
| End Function
|
|



Steven Deng

templated array as function parameters
 
Thanks Jim. i tried but it is not working with user defined types

Sincerely,
Steven Deng


"Jim Rech" 写入消息新闻
...
I think this will work for any type of array:

''Returns True is the passed array has been dimensioned else False
Function ArrayDimmed(vntArray As Variant) As Boolean
On Error Resume Next
ArrayDimmed = IsNumeric(UBound(vntArray))
End Function


--
Jim Rech
Excel MVP
"Steven Deng" wrote in message
news:99cid.107442$%k.6341@pd7tw2no...
| Hello, I am writing some code to test whether an array is undefined

(See
| code below). I am passing an array of integers to the function right

now,
| and I am wondering if i can extend this so that it can be apply to

array
of
| any type (even user defined type). Something like a function template.
|
|
|
|
| Public Function isUndefArray(ByRef a() As integer) As Boolean
| Dim l As Long
| On Error Resume Next
| l = UBound(a)
| If Err.Number = 9 Then
| Debug.Print Err.Description
|
| isUndefArray = True
| Exit Function
| End If
| isUndefArray = False
| End Function
|
|






All times are GMT +1. The time now is 01:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com