Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

vb.net pass structure filed into function

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

0
jramshur
Asked:
jramshur
  • 4
  • 2
1 Solution
 
TommySzalapskiCommented:
You created data as an array of SWEvents. Take out the (0) or do data(1).diff.
0
 
TommySzalapskiCommented:
Oh, wait, I see what you are doing. Hang on.
0
 
TommySzalapskiCommented:
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

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
jramshurAuthor Commented:
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

.
0
 
TommySzalapskiCommented:
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
Next

Open in new window

0
 
jramshurAuthor Commented:
Thanks. That works, but I'm disappointed that there isn't more array/matrix support in vb.net.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now