jeudi 4 mai 2017

Trying to make a random entry gird in Visual Basic

I am trying to make a random data grid, to give each entry a random name(from a csv file), ID and a random integer value.

Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    ' Initialize the random-number generator
    Randomize()

    DataGridView1.Rows.Clear()

    For ix As Integer = 1 To 1000

        Dim intValue As Integer = CInt(Int((5000 * Rnd()) + 1))
        Dim intRandomNumber As Integer

        intRandomNumber = (100 * Rnd())

        Dim sr As New IO.StreamReader("firstNames.csv")
        Dim dt As New DataTable
        Dim newline() As String = sr.ReadLine.Split(","c)
        dt.Columns.AddRange({New DataColumn(newline(0)),
                     New DataColumn(newline(1))})
        While (Not sr.EndOfStream)
            newline = sr.ReadLine.Split(","c)
            DataGridView1.Rows.Add(Format(ix, "00000"), newline, "", "", "", intValue)
        End While

    Next
End Sub

End Class




Aucun commentaire:

Enregistrer un commentaire