×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ARRAY FUNCTION

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

RE: ARRAY FUNCTION

Dim Ans()=ArrayFunct(InputArray())
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

While you are using dynamic arrays be carefull with using ReDim statment. This statment always clear all your array. To keep your array use following. The following code show how to increase your array with protecting all array data.

'ReDim Preserve MyArray(UBound(MyArray)+1)'


Vlado

RE: ARRAY FUNCTION

(OP)
Friends,
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

Not sure about using a Function but you can certainly have a sub with an input and an output array, eg this works


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

A function should be able to handle it. Try something like this:

CODE

Private Function MatrixFunction(ByVal incoming As Variant) As Double()

  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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close