ikantspelwurdz
Well-known member
- Joined
- Dec 8, 2009
- Messages
- 49
- Programming Experience
- 1-3
Here's the code for a program that rolls a 20-sided die 1,001 times, and then saves the list of rolls to an Access database using a very simple strongly typed dataset table adapter.
This works, but it works quite slowly, taking about three minutes to complete. Am I even doing this right? Is there a way to make this faster? My solution is attached.
VB.NET:
Module Module1
Sub Main()
Dim rolls As New List(Of Integer)
Dim r As New Random
For i As Integer = 0 To 1000
rolls.Add(r.Next(20) + 1)
Next
Dim DiceAdapter As New DiceDataSetTableAdapters.rollsTableAdapter
Dim rollsInserted As Integer = 0
For Each roll As Integer In rolls
DiceAdapter.Insert(roll)
rollsInserted += 1
If rollsInserted Mod 10 = 0 Then
Dim p As Integer = 100 * rollsInserted / rolls.Count
Console.Clear()
Console.WriteLine(p & "%")
End If
Next
End Sub
End Module
This works, but it works quite slowly, taking about three minutes to complete. Am I even doing this right? Is there a way to make this faster? My solution is attached.