?
Solved

VB.net arrays

Posted on 2014-02-12
7
Medium Priority
?
394 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 1000 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 1000 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

752 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