Solved

VB.net arrays

Posted on 2014-02-12
7
393 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
[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
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 143

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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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