Randomize( )を実行しても・・・

解決


MELEE  2007-05-26 23:03:20  No: 136529

Randomize()
Dim check As Integer
           For check = 1 To 100
                If hit / 5 = check Then
                    Dim rndcheck As Integer
                    rndcheck = Int(Rnd() * 10) + 1
                    If rndcheck = 1 Or 2 Then
                        Label1.ForeColor = Color.Red
                    End If
                    If rndcheck = 3 Or 4 Then
                        Label1.ForeColor = Color.Yellow
                    End If
                    If rndcheck = 5 Or 6 Then
                        Label1.ForeColor = Color.Aqua
                    End If
                    If rndcheck = 7 Or 8 Then
                        Label1.ForeColor = Color.YellowGreen
                    End If
                    If rndcheck = 9 Or 10 Then
                        Label1.ForeColor = Color.Salmon
                    End If
                    GoTo jump1
                End If
                Label1.ForeColor = Color.White
            Next
jump1:

上のようにhitが5の倍数のときだけ、Label1の色を白以外に設定しようと思ったのですが、なぜかそのときにColor.Salmonしか色が適用されません。
rndcheck = Int(Rnd() * 10) + 1
でrndcheckに1〜10の乱数は代入できているのですが、なぜでまた9と10の色しか当たらないのでしょうか?
よろしくお願いします。


MELLE  2007-05-26 23:31:46  No: 136530

一応ソースのせときます。長くなりますがすいません。(スクリーンセーバーです)

Public Class From1
    Inherits System.Windows.Forms.Form
    Dim MousePosX As Integer
    Dim MousePosY As Integer
    Dim VectorX As Integer
    Dim VectorY As Integer
    Dim VectorA As Integer
    Dim VectorB As Integer
    Dim hit As Integer
+フォームデザイナで作成されたコード
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '移動量
        VectorX = 1
        VectorY = 2
        VectorA = -2
        VectorB = -1
        'ラベル表示位置設定
        Dim Rect As Rectangle
        Rect = Screen.PrimaryScreen.Bounds
        Label1.Top = Rect.Height - Label1.Height - 20

        Label1.Left = Rect.Width - Label1.Width - 20
        'マウス座標
        MousePosX = MousePosition.X
        MousePosY = MousePosition.Y
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Randomize() 'ランダム
        If PictureBox1.Right > Size.Width Or PictureBox1.Left = 0 Then '画面外にはみ出たとき
            VectorX = -VectorX
            If hit >= 1000 Then 'もし1000まであがっていればリセット
                hit = 0
            End If
            hit = hit + 1 'ヒット数をカウント
            Label1.Text = CStr(hit) + "HIT" '文字列に変換して表示
            Dim check As Integer
            For check = 1 To 200 'hitを5で割ると必ず1〜200の整数になる
                If hit / 5 = check Then '5の倍数であれば
                    Dim rndcheck As Integer '←色をランダムに設定するための変数
                    rndcheck = Int(Rnd() * 10) + 1 '1〜10までの乱数をセット
                    If rndcheck = 1 Or 2 Then '1か2の場合red
                        Label1.ForeColor = Color.Red
                    End If
                    If rndcheck = 3 Or 4 Then '3か4の場合yellow
                        Label1.ForeColor = Color.Yellow
                    End If
                    If rndcheck = 5 Or 6 Then '5か6の場合aqua
                        Label1.ForeColor = Color.Aqua
                    End If
                    If rndcheck = 7 Or 8 Then
                        Label1.ForeColor = Color.YellowGreen '7か8の場合yellowgreen
                    End If
                    If rndcheck = 9 Or 10 Then
                        Label1.ForeColor = Color.Salmon '9か10の場合salmon
                    End If
                    GoTo jump1 '色が決定したらjump1へ抜ける
                End If
                Label1.ForeColor = Color.White '最終的に5の倍数でないときは白に設定
            Next
jump1:
        End If
        If PictureBox1.Bottom > Size.Height Or PictureBox1.Top = 0 Then
            VectorY = -VectorY
            If hit >= 1000 Then
                hit = 0
            End If
            hit = hit + 1
            Label1.Text = CStr(hit) + "HIT"
            Dim check As Integer
            For check = 1 To 200
                If hit / 5 = check Then
                    Dim rndcheck As Integer
                    rndcheck = Int(Rnd() * 10) + 1
                    If rndcheck = 1 Or 2 Then
                        Label1.ForeColor = Color.Red
                    End If
                    If rndcheck = 3 Or 4 Then
                        Label1.ForeColor = Color.Yellow
                    End If
                    If rndcheck = 5 Or 6 Then
                        Label1.ForeColor = Color.Aqua
                    End If
                    If rndcheck = 7 Or 8 Then
                        Label1.ForeColor = Color.YellowGreen
                    End If
                    If rndcheck = 9 Or 10 Then
                        Label1.ForeColor = Color.Salmon
                    End If
                    GoTo jump2
                End If
                Label1.ForeColor = Color.White
            Next
jump2:
        End If
        If PictureBox2.Right > Size.Width Or PictureBox2.Left = 0 Then
            VectorA = -VectorA
            If hit >= 1000 Then
                hit = 0
            End If
            hit = hit + 1
            Label1.Text = CStr(hit) + "HIT"
            Dim check As Integer
            For check = 1 To 200
                If hit / 5 = check Then
                    Dim rndcheck As Integer
                    rndcheck = Int(Rnd() * 10) + 1
                    If rndcheck = 1 Or 2 Then
                        Label1.ForeColor = Color.Red
                    End If
                    If rndcheck = 3 Or 4 Then
                        Label1.ForeColor = Color.Yellow
                    End If
                    If rndcheck = 5 Or 6 Then
                        Label1.ForeColor = Color.Aqua
                    End If
                    If rndcheck = 7 Or 8 Then
                        Label1.ForeColor = Color.YellowGreen
                    End If
                    If rndcheck = 9 Or 10 Then
                        Label1.ForeColor = Color.Salmon
                    End If
                    GoTo jump3
                End If
                Label1.ForeColor = Color.White
            Next
jump3:
        End If
        If PictureBox2.Bottom > Size.Height Or PictureBox2.Top = 0 Then
            VectorB = -VectorB
            If hit >= 1000 Then
                hit = 0
            End If
            hit = hit + 1
            Label1.Text = CStr(hit) + "HIT"
            Dim check As Integer
            For check = 1 To 200
                If hit / 5 = check Then
                    Dim rndcheck As Integer
                    rndcheck = Int(Rnd() * 10) + 1
                    If rndcheck = 1 Or 2 Then
                        Label1.ForeColor = Color.Red
                    End If
                    If rndcheck = 3 Or 4 Then
                        Label1.ForeColor = Color.Yellow
                    End If
                    If rndcheck = 5 Or 6 Then
                        Label1.ForeColor = Color.Aqua
                    End If
                    If rndcheck = 7 Or 8 Then
                        Label1.ForeColor = Color.YellowGreen
                    End If
                    If rndcheck = 9 Or 10 Then
                        Label1.ForeColor = Color.Salmon
                    End If
                    GoTo jump4
                End If
                Label1.ForeColor = Color.White
            Next
jump4:
        End If
        PictureBox1.Top = PictureBox1.Top + VectorY
        PictureBox1.Left = PictureBox1.Left + VectorX
        PictureBox2.Top = PictureBox2.Top + VectorB
        PictureBox2.Left = PictureBox2.Left + VectorA
    End Sub

    Private Sub From1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        Close()
    End Sub

    Private Sub From1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
        If e.X <> MousePosX Or e.Y <> MousePosY Then
            Close()
        End If
    End Sub
End Class


MELLE  2007-05-26 23:41:44  No: 136531

連稿すいません
よく分からない方は下の実行ファイルをDLしてください
http://www.uploda.net/cgi/uploader3/index.php?dlpas_id=0000003169.zip


MELLE  2007-05-26 23:44:27  No: 136532

パスはbasic


黒頭巾  2007-05-26 23:54:03  No: 136533

×rndcheck = 1 Or 2
○rndcheck = 1 Or rndcheck = 2
じゃないですか?

後、if〜then  の連続よりも  select case の方がスッキリするかも


MELLE  2007-05-28 02:04:01  No: 136534

ありがとうございました。
解決しました


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加