Hi, im having trouble reading in lines of data using arrays and a structure. I believe my main problem is figuring out how to keep track of the lines read in, even if the whole array size isnt used up. Also, To break up each line I am trying to use the split function to seperate spaces, but dont know if im doing so correctly.

1 line of data looks like this:

Doug Blandon 407 202.00 102.00 104.00 105.00 207.00

My code so far:

Public Class Form1
    Dim sr As IO.StreamReader = IO.File.OpenText("comiss.txt")
    Structure Records
        Dim first As String
        Dim last As String
        Dim ID As Integer
        Dim monSales, tuesSales, wedSales, _
            thurSales, friSales As Double
    End Structure

    Private Sub btnClick_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClick.Click
        Const MAXARRAY = 39
        Dim Records(MAXARRAY) As Records
        Dim counter As Integer = 0
        Dim split() As String = IO.File.ReadAllLines("comiss.txt")
        Dim aline As String
        Dim data() As String
        Dim lineCounter as String

        Do
            aline = split(counter)
            data = aline.Split(" "c)
            lineCounter += 1
    
                With Records(counter)
                    .first = data(0)
                    .last = data(1)
                    .ID = data(2)
                    .monSales = data(3)
                    .tuesSales = data(4)
                    .wedSales = data(5)
                    .thurSales = data(6)
                    .friSales = data(7)
                End With

                counter += 1
                lstReport.Items.Add(Records(counter).first) 'Add the rest?
       
        Loop Until counter = lineCounter


    End Sub
End Class

Edited 6 Years Ago by xcarbonx: n/a

I'm not sure but I think you want to show records into ListView control.

...
        Dim Records As New List(Of Records)
        Dim rec As Records
        Dim counter As Integer = 0
        Dim split() As String = IO.File.ReadAllLines("comiss.txt")

        Dim data() As String

        ListView1.Columns.Add("A1")
        ListView1.Columns.Add("A2")
        ListView1.Columns.Add("A3")
        ListView1.Columns.Add("A4")

        ListView1.View = View.Details

        For Each aline As String In split

            data = aline.Split(" "c)

            If counter < split.Length Then

                With Rec
                    .First = data(0)
                    .Last = data(1)
                    .ID = data(2)
                    .monSales = data(3)
                    .tuesSales = data(4)
                    .wedSales = data(5)
                    .thurSales = data(6)
                    .friSales = data(7)
                End With

                counter += 1
                ListView1.Items.Add(New ListViewItem(data))

            End If

        Next
...

im not familiar with listview, I want to output each line from the file into a list box formatted such as:

John Herman 607 400.00 300.00 450.00 690.00 200.00

the first column would be first name, second column last name, third is the employee id number, etc..

Why are you using an Array, anyways? Why not just use a List(Of Records)? You can just keep adding records using the Add() method.

This question has already been answered. Start a new discussion instead.