Consulting

Results 1 to 4 of 4

Thread: How do I add Certain items in a array

  1. #1
    VBAX Newbie
    Joined
    Aug 2016
    Posts
    2
    Location

    How do I add Certain items in a array

    I got about 7 hours left to finish this code so any help is welcome.

    I am using Microsoft Visual Basic 2015, and I need it to pull out everyone in an array with the same username, and tally their points up, than insert that information into another array with their First Name and Last Name and Gender and Agegroup. I'm pulling the first arrays info from a csv.
    ---------------------------------------------------------------------------------------------------------------------------------------------------
    Module modArray
        Public Structure Athletes
            Public UserName As String
            Public LastName As String
            Public FirstName As String
            Public Gender As String
            Public Points As String
            Public AgeGroup As String
    End Structure
    Public TopAthletes(20) As Athletes
    Public Sub ReadAthletesArray()
            'Find csv file
            Dim FILE_NAME As String = "C:\Users\Jurid\Desktop\TopAthletes\LoadArray.csv"
            Dim RecordPosition As Integer = 0
            'How to read csv
            If System.IO.File.Exists(FILE_NAME) = True Then
    Dim objReader As New System.IO.StreamReader(FILE_NAME)
    Do While objReader.Peek() <> -1
                    Call LoadWaitingList(objReader.ReadLine(), RecordPosition)
    RecordPosition = RecordPosition + 1
                Loop
                objReader.Close()
                ReDim Preserve TopAthletes(RecordPosition)
    Else
    MsgBox("File Does Not Exist")
    End If
    End Sub
        
    Public AthleteArray() As String
        Public Sub LoadWaitingList(ByVal Newrecord As String, ByVal IndexPosition As Integer)
            AthleteArray = Split(Newrecord, ",", 6)
    With TopAthletes(IndexPosition)
                .UserName = AthleteArray(0)
                .Points = AthleteArray(1)
                .LastName = AthleteArray(2)
                .FirstName = AthleteArray(3)
                .Gender = AthleteArray(4)
                .AgeGroup = AthleteArray(5)
    End With
    End Sub
    
    Public Function StringValue(ByVal IndexValue As Integer) As String
            With TopAthletes(IndexValue)
                StringValue = .UserName & "," & .Points & "," & .LastName & "," & .FirstName & "," & .Gender & "," & .AgeGroup
            End With
        End Function
    
    Public Sub AthletePoints()
            Dim UserName As String
            Dim UserPoints() As Integer
    For i = 0 To TopAthletes.GetUpperBound(0) - 1
                UserName = TopAthletes(i).UserName
                For o = 0 To TopAthletes.GetUpperBound(0) - 1
                    If UserName = TopAthletes(o).UserName Then
                        UserPoints(i) = TopAthletes(o).Points + UserPoints(i - 1)
                    End If
                Next
            Next
        End Sub
    
    End Module
    ----------------------------------------------------------------------------------------------------
    That's the current code.
    Ask if you need anymore

  2. #2
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    Why are you using the VB.net library?

    In Access it should be a simple job to link the CSV file as a table and write SQL to return a recordset of the info you need.

  3. #3
    VBAX Newbie
    Joined
    Aug 2016
    Posts
    2
    Location
    Quote Originally Posted by jonh View Post
    Why are you using the VB.net library?

    In Access it should be a simple job to link the CSV file as a table and write SQL to return a recordset of the info you need.
    Hmmm how does one do that? How do I do the whole, add certain values together?
    Last edited by Jurid; 08-18-2016 at 06:16 PM.

  4. #4
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    To sum rows you use grouping and sum().
    To sum columns you just add them together.

    SELECT ID, Sum(Value1), Sum(Value2), Sum([Value1]+[Value2]) AS Total
    FROM Table1
    GROUP BY ID

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •