Solved pass structure filed into function

Posted on 2010-11-12
Last Modified: 2012-05-10
I want to pass the data.diff field into the function. This works in Matlab. :) The IDE says that " 'diff' is not a member of 'system.array' ". The data structure is redim'ed and filled with data in code not shown. How do you get the field into the function?

'create structure to hold switch event data
Structure SWEvent
     Dim switch As String
     Dim time As Double
     Dim diff As Double
End Structure

'create data structure
Private data(0) As SWEvent

'my function
Public Function ArrayAverage(ByVal NumericArray() As Double) As Double
End Function

'trying to pass filed to function
dim mean as Double
mean = ArrayAverage(data.diff)

Open in new window

Question by:jramshur
  • 4
  • 2
LVL 37

Expert Comment

ID: 34118773
You created data as an array of SWEvents. Take out the (0) or do data(1).diff.
LVL 37

Expert Comment

ID: 34118793
Oh, wait, I see what you are doing. Hang on.
LVL 37

Expert Comment

ID: 34118854
Okay, pass the whole thing into the function ArrayAverage(data) and do this
'my function
Public Function ArrayAverage(ByVal EventArray() As SWEvent) As Double
...For Each e in EventArray blah blah sum = sum + e.diff
End Function

Open in new window

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.


Author Comment

ID: 34119125
I was considering that solution, but wanted to pass the field so that I can use other functions I have. Trying to keep from modifying several functions. Let me ask another question: how do you assign a numeric array to a structure field as below? This could solve my issues.

dim d() as double
d = data.diff

Open in new window

LVL 37

Accepted Solution

TommySzalapski earned 500 total points
ID: 34119139
No you can't. The array does not have a .diff property ever for anything.
If you really want just the .diff members you'll have to pull them out into a new array.
Something like:
Dim numericArray(UBound(data)) As Integer

For i = 1 To UBound(data)

  numericArray(i) = data(i).diff


Open in new window


Author Comment

ID: 34128112
Thanks. That works, but I'm disappointed that there isn't more array/matrix support in

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now