Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem Exception and Random number
    primarykey
    data
    text
    <p>i make a lottery in VB.NET</p> <p>i got an error when i simulate the thing. To write in a file any "billet" generate the error is : </p> <blockquote> <p>Invalid CastException was unhandled: The conversion of the chain "[" in 'Double' was invalid</p> </blockquote> <p>Also, i don't know how to make a series of random number between 1 to 49 for each number of a Billet object</p> <p>Here's my code</p> <pre><code>Public Class Billet Dim _num1, _num2, _num3, _num4, _num5, _num6 As Integer Dim rand As Random Sub New(ByVal _num1 As Integer, ByVal _num2 As Integer, ByVal _num3 As Integer, ByVal _num4 As Integer, ByVal _num5 As Integer, ByVal _num6 As Integer) Me.Num1 = _num1 Me.Num2 = _num2 Me.Num3 = _num3 Me.Num4 = _num4 Me.Num5 = _num5 Me.Num6 = _num6 End Sub Public Property Num1() As Integer Get Return _num1 End Get Set(ByVal Value As Integer) _num1 = Value End Set End Property Public Property Num2() As Integer Get Return Num2 End Get Set(ByVal Value As Integer) _num2 = Value End Set End Property Public Property Num3() As Integer Get Return _num3 End Get Set(ByVal Value As Integer) _num3 = Value End Set End Property Public Property Num4() As Integer Get Return Num4 End Get Set(ByVal Value As Integer) _num4 = Value End Set End Property Public Property Num5() As Integer Get Return _num5 End Get Set(ByVal value As Integer) End Set End Property Public Property Num6() As Integer Get Return _num6 End Get Set(ByVal value As Integer) End Set End Property Public Overrides Function ToString() As String Return "[" + Num1 + "]" &lt;----- ERROR :Invalid CastException : La conversion de la chaîne "[" en type 'Double' n'est pas valide. End Function End Class </code></pre> <hr> <pre><code>Imports System.Random Imports Microsoft.VisualBasic.FileIO Imports System.IO Public Class Simulation Dim tabBillet As New ArrayList Dim billetGagnant(5) As Integer Sub GenerateBillet(ByVal nbmin As Integer, ByVal nbmax As Integer) Randomize() Dim value As Integer = CInt(Int((nbmax * Rnd()) + nbmin)) For i As Integer = 0 To value For j As Integer = 0 To 6 Dim num As Integer = CInt(Int((49 * Rnd()) + 1)) tabBillet.Add(New Billet(num, num, num, num, num, num)) Next Next ecrireFic(tabBillet) End Sub Function GenerateGagnant() Randomize() For i As Integer = 0 To 5 Dim numero As Integer = CInt(Int((49 * Rnd()) + 1)) billetGagnant(i) = numero Next Return billetGagnant End Function Public Sub ecrireFic(ByVal tabBillet As ArrayList) Dim path As String = "H:\test.txt" Dim sw As StreamWriter If File.Exists(path) = False Then sw = File.CreateText(path) End If sw = File.AppendText(path) For i As Integer = 0 To 3 sw.WriteLine(tabBillet.Item(i).ToString()) Next sw.Flush() sw.Close() ' Open the file to read from.' Dim sr As StreamReader = File.OpenText(path) Dim s As String Do While sr.Peek() &gt;= 0 s = sr.ReadLine() Console.WriteLine(s) Loop sr.Close() End Sub End Class </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload