Solved

vb.net pass structure filed into function

Posted on 2010-11-12
6
358 Views
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

0
Comment
Question by:jramshur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 37

Expert Comment

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

Expert Comment

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

Expert Comment

by:TommySzalapski
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

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jramshur
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

.
0
 
LVL 37

Accepted Solution

by:
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
Next

Open in new window

0
 

Author Comment

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

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

730 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