Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

[PYTANIE] Generator


Rekomendowane odpowiedzi

Opublikowano

Ostatnio zacząłem bawić się z VB 2010.

Zrobiłem taki prosty generator, który po naciśnięciu przycisku "generate" generuje liczby od 1 do 3.

Jest w tym generatorze tak, że jak wygeneruje np. liczbe 1, to następną liczbą też może być jeden, czyli np. generuje tak:

1-1-2-3-1-2-2

Jak przekształcić kod tak, żeby po wygenerowaniu jakiejś liczby, następna liczba nie mogła być taka sama, czyli tak:

1-3-2-1-2-3-1-2

Chce też, żeby było tak że liczba wyskakuje dopiero po załadowaniu prograssbara, a nie po jego uruchomieniu przyciskiem generate.

A to mój kod:

Public Class Form1

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim key As Integer
        key = (Rnd() * 3)
        Select Case key
            Case 1
                TextBox1.Text = "1"
            Case 2
                TextBox1.Text = "2"
            Case 3
                TextBox1.Text = "3"
        End Select
        Timer1.Start()
        ProgressBar1.Value = ProgressBar1.Minimum
    End Sub


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ProgressBar1.Increment(1)
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Timer1.Stop()
            Dim key As Integer
            key = (Rnd() * 3)
            Select Case key
                Case 1
                    TextBox1.Text = "1"
                Case 2
                    TextBox1.Text = "2"
                Case 3
                    TextBox1.Text = "3"
            End Select
        End If
    End Sub
End Class


 

 

1398258449-U383457.png

Opublikowano

 

Public Class Form1
dim old_key as integer = 0



Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim key As Integer
a:
key
= (Rnd() * 3)
if old_key == key then goto a
old_key = key

Select Case key
Case 1
TextBox1.Text = "1"
Case 2
TextBox1.Text = "2"
Case 3
TextBox1.Text = "3"
End Select
Timer1.Start()
ProgressBar1.Value = ProgressBar1.Minimum
End Sub


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Increment(1)
If ProgressBar1.Value = ProgressBar1.Maximum Then
Timer1.Stop()
a:
key
= (Rnd() * 3)
if old_key == key then goto a
old_key = key

Select Case key
Case 1
TextBox1.Text = "1"
Case 2
TextBox1.Text = "2"
Case 3
TextBox1.Text = "3"
End Select
End If
End Sub
End Class

 

7j66.png
Opublikowano

Popatrz na mój kod:

Public Class Form1
    Dim old_key As Integer = 0, key As Integer = 0

    Private Function GetKey() As Integer
a:
        key = (Rnd() * 3)
        If old_key = key Xor key = 0 Then GoTo a
        old_key = key
        TextBox1.AppendText(key.ToString)
        Return key
    End Function

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        GetKey()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button1.Enabled = False
        Button2.Enabled = True
        Timer1.Start()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button1.Text = "Start"
        Button2.Text = "Stop"
        Button2.Enabled = False
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Button2.Enabled = False
        Button1.Enabled = True
        Timer1.Stop()
    End Sub
End Class
7j66.png

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...