CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: help with loop

  1. #1
    Join Date
    Mar 2015
    Posts
    8

    help with loop

    Im trying to make a game that keeps track of a players wins. can anyone tell me why my counter or loop wont work?

    Option Strict On
    Option Explicit On

    Public Class Form1
    Private Player1 As String
    Private Player2 As String

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
    Me.Close()
    End Sub




    Private Sub frmMainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Player1 = InputBox("Enter Player 1's Name: ")
    lblPlayer1.Text = (Player1 + "'s Score:")

    Player2 = InputBox("Enter Player 2's Name:")
    lblPlayer2.Text = (Player2 + "'s Score:")


    End Sub


    Private Sub btnRoll_Click(sender As Object, e As EventArgs) Handles btnRoll.Click
    ' game of rolling dice

    Dim randGen As New Random
    Dim intNum1 As Integer
    Dim intNum2 As Integer
    Dim intNum3 As Integer
    Dim intNum4 As Integer
    Dim intTotal As Integer
    Dim intTotal2 As Integer




    ' make random integer from 1 through 6
    intNum1 = randGen.Next(1, 7)
    intNum2 = randGen.Next(1, 7)
    intNum3 = randGen.Next(1, 7)
    intNum4 = randGen.Next(1, 7)


    ' display the right image in picDie1
    Select Case intNum1
    Case 1
    picDie1.Image = picOneDot.Image
    Case 2
    picDie1.Image = picTwoDots.Image
    Case 3
    picDie1.Image = picThreeDots.Image
    Case 4
    picDie1.Image = picFourDots.Image
    Case 5
    picDie1.Image = picFiveDots.Image
    Case 6
    picDie1.Image = picSixDots.Image
    End Select

    ' display the right image in picDie2
    Select Case intNum2
    Case 1
    picDie2.Image = picOneDot.Image
    Case 2
    picDie2.Image = picTwoDots.Image
    Case 3
    picDie2.Image = picThreeDots.Image
    Case 4
    picDie2.Image = picFourDots.Image
    Case 5
    picDie2.Image = picFiveDots.Image
    Case 6
    picDie2.Image = picSixDots.Image
    End Select

    ' display the right image in picDie3
    Select Case intNum3
    Case 1
    picDie3.Image = picOneDot.Image
    Case 2
    picDie3.Image = picTwoDots.Image
    Case 3
    picDie3.Image = picThreeDots.Image
    Case 4
    picDie3.Image = picFourDots.Image
    Case 5
    picDie3.Image = picFiveDots.Image
    Case 6
    picDie3.Image = picSixDots.Image
    End Select

    ' display the right image in picDie4
    Select Case intNum4
    Case 1
    picDie4.Image = picOneDot.Image
    Case 2
    picDie4.Image = picTwoDots.Image
    Case 3
    picDie4.Image = picThreeDots.Image
    Case 4
    picDie4.Image = picFourDots.Image
    Case 5
    picDie4.Image = picFiveDots.Image
    Case 6
    picDie4.Image = picSixDots.Image
    End Select








    ' calculate and display total number of dots
    intTotal = intNum1 + intNum2
    lblTotal.Text = intTotal.ToString()

    intTotal2 = intNum3 + intNum4
    lblTotal2.Text = intTotal2.ToString()

    If intTotal > intTotal2 Then
    MessageBox.Show("Player1 Wins")


    Dim count As Integer = 1

    Do While count > 0




    lblWins.Text = CStr(count)
    count = count + 1
    Loop

    End If


    End Sub

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: help with loop

    Why are you using a loop there? As is if inttotal> inttotal2 then it will show a msgbox and go into a semi endless loop showing as not responding. It should crash if you let it run long enough as it will eventually overflow the int variable.

    I think you need to remove the Do loop and just leave the content of the loop.
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured