View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default Use static arrays


try like:

Option Explicit
Const TOTAL_MODULES = 3

Public Function KeysResult(Optional aInput)
Static saResult() As Boolean
On Error GoTo errH
If Not IsMissing(aInput) Then
If IsArray(aInput) Then
If UBound(aInput) = TOTAL_MODULES Then
saResult = aInput
Else
Err.Raise 13
End If
Else
Err.Raise 9
End If
End If

KeysResult = saResult
Exit Function
errH:
KeysResult = CVErr(Err)
End Function

Sub test()
ReDim aiok(1 To TOTAL_MODULES) As Boolean
ReDim aier(1 To 2) As Boolean
Dim v
v = KeysResult(aiok)
Stop
v = KeysResult
Stop
v = KeysResult(aier)
Stop

End Sub





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


François wrote :

Hello,

I would like to use the static declaration for an array. However I
have some difficulties on the subject.

Public Function KeysResult(aPResult, bSet As Boolean) As Variant
'---------------------------------------------------------------------
----' If bSet Then
Static aResult(conTotalModules) As Boolean
aResult = aPResult
Else
KeysResult = aResult
End If
End Function
Public Function KeysDLine(aPDLines, bSet As Boolean) As Variant
'---------------------------------------------------------------------
---' If bSet Then
Static aDLines(conTotalModules) As Variant
aDLines = aPDLines
Else
KeysResult = aDLines
End If
End Function

This give an error like : <can't assign to array. Any idean how to
solve this ?

Many thanks