Hi guys, I have some fundamental holes in my understanding of programming, so help would be appreciated, I’ve always had a problem getting my head around it. I don't have a very strong mental model of how the code flows. My main problem is i think i understand the syntax, but not really its application. Any links people found useful would be great.

Couple of questions. The code below doesn't make sense to me (written by someone else) the application is basically a csv reader, but manipulates the data.

Public Sub entryType()
    IsEntry = entryType.Other
    entryID = choiceType.Unknown
    If entryId = entryIdentifier.issue AndAlso Data IsNot Nothing Then
        For Each x In Data
                Dim ss As List(Of String) = x.Split(",").ToList()  'does this split the data incoming into array entities?

            For Each s As String In ss
                If s.Contains("entry:") Then
                    s = s.Replace("entry:", "").Trim()
                    Dim n As Integer = Val(s)
                    Select Case s
                        Case 0, 1
                            IsAnnotation = NotificationType.Issue      'where do the assignments go for all cases? 
                            AnnotationType = DirectCast(n, choiceType) 'my understanding here is they are assigned locally?
                        Case 3, 4
                            IsAnnotation = NotificationType.Action
                            AnnotationType = DirectCast(n, choiceType)
                        Case Else

                    End Select
                End If
            Next
        Next
    End If
End Sub

The below, actually returns a string of data, but i don't understand how if nothing is passed in? surely rep is local and declared as a new list?! Confused.

Public Function ReportSummary() As List(Of String)
        Dim rep As New List(Of String)



        Return rep

    End Function

Help would be much appreciated guys.

Dani AI

Generated

Brief, practical clarifications tied to the snippets posted by (and echoing ’s request for clearer intent):

  • Splitting: calling Split returns an array (or list) of substrings. Use the char overload (for clarity) and prefer Integer.TryParse over Val for numeric parsing. A simple Split(",") will break on every comma and does not handle quoted fields; use a CSV-aware reader for real CSV files.
  • Assignments: if IsAnnotation, AnnotationType, etc. are declared at class scope, assigning to them inside a Sub changes the object's state (the values persist after the Sub returns). VB is case-insensitive, so entryID and entryId refer to the same variable.
  • Select Case / casting: compare the correct type (Select Case on the parsed Integer), and convert integers to enums with CType (not DirectCast). Option Strict On will catch many implicit-conversion bugs.

Example pattern for parsing a line safely:

Public Sub DetermineEntryType()
    If Data Is Nothing Then Exit Sub
    For Each line As String In Data
        Dim parts = line.Split(","c)
        For Each token In parts
            Dim ix = token.IndexOf("entry:", StringComparison.OrdinalIgnoreCase)
            If ix >= 0 Then
                Dim raw = token.Substring(ix + 6).Trim()
                Dim n As Integer
                If Integer.TryParse(raw, n) Then
                    Select Case n
                        Case 0, 1
                            IsAnnotation = NotificationType.Issue
                            AnnotationType = CType(n, choiceType)
                        Case 3, 4
                            IsAnnotation = NotificationType.Action
                            AnnotationType = CType(n, choiceType)
                    End Select
                End If
            End If
        Next
    Next
End Sub

ReportSummary: creating Dim rep As New List(Of String) is correct; that local object is returned by reference. If the caller gets an empty list it means no items were added before Return. Populate rep from class fields or the parsed data before returning.

Quick tips: enable Option Strict On, use Integer.TryParse, prefer a CSV parser (Microsoft.VisualBasic.FileIO.TextFieldParser or a dedicated library) for quoted fields, and step through the routine with a breakpoint to inspect variable values.

There's a lot missing from your code. It would help if you explain what it is you want to accomplish.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.