copyright 1999 - 2014 by heinz prelle - hannover  - lenbachstraße 42 - www.visual-basic5.de | impressum
Beispiel: VB .Net - Lottozahlen
'
Option Explicit On
Option Strict On

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles Button1.Click
        Me.TextBox1.Text = LotteryNumbers(49)
    End Sub

    Private Function LotteryNumbers(ByVal Max As Integer, Optional ByVal ReturnNumbers As Integer = 6) As String
        Dim Result As String = Nothing
        Const Min As Integer = 1
        Dim arr(Max) As Integer
        Try
            For n As Integer = Min To Max
                arr(n) = n
            Next
            Dim Shuffle As Integer
            Dim rnd As New Random
            Dim tmp As Integer
            For n As Integer = Min To Max
                Shuffle = rnd.Next(Min, Max)
                tmp = arr(Shuffle)
                arr(Shuffle) = arr(n)
                arr(n) = tmp
            Next
            For n As Integer = Min To ReturnNumbers
                Result &= arr(n).ToString() & "   "
            Next
        Catch
            Throw
        End Try
        Return Result
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles MyBase.Load
        With Me
            .CenterToScreen()
            .Text = "Lottozahlen"
            .Button1.Text = "Test"
            .TextBox1.TextAlign = HorizontalAlignment.Center
        End With
    End Sub

End Class
Sourcecode Visual Basic