ARRAY FUNCTION
ARRAY FUNCTION
(OP)
Dear Friends,
Can any one tell me about a function which receives a dynamic array(multi dimensional) and returns also an array(multi dimensional) . I tries to use VARIANT but could not be successful.
Dim Ans() as Double, InputArray() as Double
Dim Ans()=ArrayFunct(InputArray())
Function ArrayFunct (ReceiveingArray()) as double ()
Dim IntermediateArray() as double
....
....
...
ArrayFunct = IntermediateArray
End Function
The above is the example of my problem.
Can anyone give solution
Shakildor
Can any one tell me about a function which receives a dynamic array(multi dimensional) and returns also an array(multi dimensional) . I tries to use VARIANT but could not be successful.
Dim Ans() as Double, InputArray() as Double
Dim Ans()=ArrayFunct(InputArray())
Function ArrayFunct (ReceiveingArray()) as double ()
Dim IntermediateArray() as double
....
....
...
ArrayFunct = IntermediateArray
End Function
The above is the example of my problem.
Can anyone give solution
Shakildor
RE: ARRAY FUNCTION
This is not syntactically correct. You cannot call a function inside of a dim statement. Nor will the Redim statment work in this construct either. However, you may be able to do the following, as you've assigned some dimentions to InputArray
Ans = ArrayFunct(InputArray)
Inside your function, it will be necessary to assign dimensions to IntermediateArray before you can use it as a return value.
To provide examples, and/or suggestion to help you get the job done, it would helpful to know what the job is.
RE: ARRAY FUNCTION
'ReDim Preserve MyArray(UBound(MyArray)+1)'
Vlado
RE: ARRAY FUNCTION
Let me put my problem once again. I am programming a problem requiring matric operation. the size of matrix is not known and size of output matrix is also not known. So it will be like
Dim InputMatrix() as double
Dim Output() as double
Sub Main()
Dim NOE as integer
'....
'......
'Determination of a variable NOE
'.....
ReDim InputMatrix(NOE, NOE) as double
'Now matrix operation function is called as
OutputMatrix=MatrixFunction(InputMatrix)
'......
'....
End Sub
Function MatrixFunction(ABC as variant) as Double()
'Now the result of this function will depend upon
'the size of input matrix or ABC variant
' I tried this
Dim NOS as integer
NOS=2*ubound(ABC,1)
Redim IntermediateMat(NOS,NOS,NOS)
'Calculation of intermediateMat
'Now the problem is how to assign this intermediateMat
'as the result of this function
End Function
RE: ARRAY FUNCTION
Private Sub Command1_Click()
Dim ABC(), DEF() As Double
ReDim ABC(3, 4)
MatrixFunction ABC(), DEF()
Debug.Print ABC(UBound(DEF, 1), UBound(DEF, 2))
End Sub
Sub MatrixFunction(ABC() As Variant, DEF() As Double)
ReDim DEF(UBound(ABC, 1), UBound(ABC, 2))
End Sub
RE: ARRAY FUNCTION
CODE
Dim temp() As Double
Dim j As Integer
Dim k As Integer
Dim size As Integer
size = UBound(incoming, 1)
ReDim temp(size, size)
For j = 0 To size
For k = 0 To size
'example calculation: add 2 to each element
temp(j, k) = incoming(j, k) + 2
Next k
Next j
MatrixFunction = temp
End Function