Solved

vb.net pass structure filed into function

Posted on 2010-11-12
6
357 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…

856 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