Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

vb.net pass structure filed into function

Posted on 2010-11-12
6
Medium Priority
?
361 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

609 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