ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Use static arrays (https://www.excelbanter.com/excel-programming/334783-use-static-arrays.html)

François

Use static arrays
 
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

Bob Phillips[_7_]

Use static arrays
 
This worked for me

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


--
HTH

Bob Phillips

"François" wrote in message
...
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




keepITcool

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



All times are GMT +1. The time now is 10:04 PM.

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