Solved

VB.net arrays

Posted on 2014-02-12
7
389 Views
Last Modified: 2014-02-13
Hi,

 im currently strongting the output of my loop in a string but have been told it would be better to store it in an array

 Public Shared Function Getthestats(ByVal thedataview As DataView, ByVal hometeam As String, ByVal awayteam As String) As String
        '' dataview-> dtRecords2
        'need to loop through the results in datview and get all results for it 
        Dim hometeamscoresingle As String = ""
        For Each dv2 As DataRowView In thedataview
            If dv2.Row.Item("HomeTeam") = hometeam Then
                hometeamscoresingle += dv2.Row.Item("FTHG") & "|"
            ElseIf dv2.Row.Item("AwayTeam") = hometeam Then
                hometeamscoresingle += dv2.Row.Item("FTAG") & "|"
            End If

        Next

        Return hometeamscoresingle
    End Function

Open in new window



How would i store the above as an array?
0
Comment
Question by:runnerjp2005
7 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 250 total points
ID: 39853815
Given the dynamic nature, I would suggest a List instead of array. Example below


 Public Shared Function Getthestats(ByVal thedataview As DataView, ByVal hometeam As String, ByVal awayteam As String) As List(Of String)
        '' dataview-> dtRecords2
        'need to loop through the results in datview and get all results for it 
        Dim hometeamscoresingle As New List(Of String)
        For Each dv2 As DataRowView In thedataview
            If dv2.Row.Item("HomeTeam") = hometeam Then
                hometeamscoresingle.Add(dv2.Row.Item("FTHG"))
            ElseIf dv2.Row.Item("AwayTeam") = hometeam Then
                hometeamscoresingle.Add(dv2.Row.Item("FTAG"))
            End If

        Next

        Return hometeamscoresingle
    End Function

Open in new window



You will need to change the calling code as well so it can handle the list.
0
 
LVL 22

Assisted Solution

by:plusone3055
plusone3055 earned 250 total points
ID: 39853825
Public Shared Function Getthestats(ByVal thedataview As DataView, ByVal hometeam As String, ByVal awayteam As String) As String
        '' dataview-> dtRecords2
        'need to loop through the results in datview and get all results for it
        dim list as new Arraylist
        For Each dv2 As DataRowView In thedataview
            If dv2.Row.Item("HomeTeam") = hometeam Then
                listadd.add(dv2.Row.Item("FTHG") & "|")
            ElseIf dv2.Row.Item("AwayTeam") = hometeam Then
                listadd.add(dv2.Row.Item("FTAG") & "|")
            End If

        Next

       Return list
    End Function
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 39853832
sorry codecruiser.. you typed it out faster than I did :(
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39853835
It really depends on what you need to do with the data later on....
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39853968
Just an aside.
Based on this and your other questions I have a horrible suspicion you do not understand databases and how to design tables and relations (or just collections of data in memory).
There are numerous things which you seem to be attempting to do (and have problems with) which ought to be really trivial if the storage of the data was well designed.
0
 

Author Comment

by:runnerjp2005
ID: 39855873
Without shooting me down to much to retrieve the list would be

Dim scoretest As ArrayList = Getthestats(dtRecords2, dv2.Row.Item("hometeam").Trim(), "")

Open in new window

0
 

Author Closing Comment

by:runnerjp2005
ID: 39855905
Did it 50/50 :)

Figured out my last question also.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 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

17 Experts available now in Live!

Get 1:1 Help Now