Solved

VB.net arrays

Posted on 2014-02-12
7
388 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

12 Experts available now in Live!

Get 1:1 Help Now