Guest User

Untitled

a guest
May 20th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.  
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         Dim i, j, min, temp As Integer
  5.         Dim v(0 To 6) As Integer
  6.  
  7.         Randomize()
  8.         ListBox1.Items.Clear()
  9.  
  10.         'Gerar Numeros
  11.        v(0) = Rand(50)
  12.         v(1) = Rand(50)
  13.         While (v(0) = v(1))
  14.             v(1) = Rand(50)
  15.         End While
  16.         v(2) = Rand(50)
  17.         While (v(0) = v(2) Or v(1) = v(2))
  18.             v(2) = Rand(50)
  19.         End While
  20.         v(3) = Rand(50)
  21.         While (v(0) = v(3) Or v(1) = v(3) Or v(2) = v(3))
  22.             v(3) = Rand(50)
  23.         End While
  24.         v(4) = Rand(50)
  25.         While (v(0) = v(4) Or v(1) = v(4) Or v(2) = v(4) Or v(3) = v(4))
  26.             v(4) = Rand(50)
  27.         End While
  28.  
  29.         'Ordenar Numeros
  30.        For i = 0 To 3
  31.             min = i
  32.             For j = i + 1 To 4
  33.                 If v(j) < v(min) Then min = j
  34.             Next
  35.             temp = v(i)
  36.             v(i) = v(min)
  37.             v(min) = temp
  38.         Next
  39.  
  40.         'Gerar Estrelas
  41.        v(5) = Rand(10)
  42.         v(6) = Rand(10)
  43.         While (v(5) = v(6))
  44.             v(6) = Rand(10)
  45.         End While
  46.  
  47.         'Ordenar Estrelas
  48.        If v(5) > v(6) Then
  49.             temp = v(6)
  50.             v(6) = v(5)
  51.             v(5) = temp
  52.         End If
  53.  
  54.         'Escrever Resultado
  55.        For i = 0 To 6
  56.             If i = 0 Then ListBox1.Items.Add("Numeros:")
  57.             If i = 5 Then ListBox1.Items.Add("Estrelas:")
  58.             ListBox1.Items.Add(v(i))
  59.         Next
  60.  
  61.  
  62.  
  63.     End Sub
  64.  
  65.     Private Function Rand(ByRef max As Integer) As Integer
  66.         Return Math.Round((max * Rnd()) + 1)
  67.     End Function
  68.  
  69. End Class
Add Comment
Please, Sign In to add comment