locked
can anyone help me with checkbox? RRS feed

  • Question

  • I have corrected my syntax my program works now can anyone give me a suggestion on how to display the last info only if checkbox is checked?

    Option Strict On
    Option Explicit On

    Public Class Form1
        Private Player1 As String
        Private Player2 As String
        Private Player1Wins As Integer = 1
        Private Player2Wins As Integer = 1
        Private Tie As Integer = 1

     


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

    Option Strict On
    Option Explicit On
    
    Public Class Form1
        Private Player1 As String
        Private Player2 As String
        Private Player1Wins As Integer = 1
        Private Player2Wins As Integer = 1
        Private Tie As Integer = 1
    
    
    
    
        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")
                lblWins.Text = CStr(Player1Wins)
                Player1Wins = Player1Wins + 1
            End If
            If intTotal2 > intTotal Then
                MessageBox.Show("Player2Wins")
                lblWins2.Text = CStr(Player2Wins)
                Player2Wins = Player2Wins + 1
            End If
    
            If intTotal = intTotal2 Then
                MessageBox.Show("Tie")
                lblTies.Text = CStr(Tie)
                Tie = Tie + 1
               
            End If
    
    
    
    
    
    
    
        End Sub
    
    
    
    End Class
    


       

    Wednesday, March 18, 2015 12:51 AM

Answers

  • I have corrected my syntax my program works now can anyone give me a suggestion on how to display the last info only if checkbox is checked?

    I'm not sure that this is the reason for your question, but you can nest your IF blocks.

    If CheckBox1.CheckState = CheckState.Checked Then 
      
     If
          ...
        End If
        ...
    End If

    Also, although it doesn't affect your results, your code is offbyone.

       Private Player1Wins As Integer = 1
       ...

          lblWins.Text = CStr(Player1Wins)
          Player1Wins
    = Player1Wins + 1

    should be

       Private Player1Wins As Integer = 0
       ...

          Player1Wins = Player1Wins + 1
          lblWins.Text = CStr(Player1Wins)

    and the same adjustment for the other scores.


    • Edited by Acamar Wednesday, March 18, 2015 2:49 AM sp
    • Marked as answer by Youjun Tang Wednesday, March 25, 2015 6:58 AM
    Wednesday, March 18, 2015 2:48 AM
  • If checkbox.checked then

    'do what you want to do only if the checkbox is checked

    End If


    Armin

    • Proposed as answer by vb.NET 0.0 Wednesday, March 18, 2015 5:40 PM
    • Marked as answer by Youjun Tang Wednesday, March 25, 2015 6:58 AM
    Wednesday, March 18, 2015 1:17 AM

All replies

  • If checkbox.checked then

    'do what you want to do only if the checkbox is checked

    End If


    Armin

    • Proposed as answer by vb.NET 0.0 Wednesday, March 18, 2015 5:40 PM
    • Marked as answer by Youjun Tang Wednesday, March 25, 2015 6:58 AM
    Wednesday, March 18, 2015 1:17 AM
  • I have corrected my syntax my program works now can anyone give me a suggestion on how to display the last info only if checkbox is checked?

    I'm not sure that this is the reason for your question, but you can nest your IF blocks.

    If CheckBox1.CheckState = CheckState.Checked Then 
      
     If
          ...
        End If
        ...
    End If

    Also, although it doesn't affect your results, your code is offbyone.

       Private Player1Wins As Integer = 1
       ...

          lblWins.Text = CStr(Player1Wins)
          Player1Wins
    = Player1Wins + 1

    should be

       Private Player1Wins As Integer = 0
       ...

          Player1Wins = Player1Wins + 1
          lblWins.Text = CStr(Player1Wins)

    and the same adjustment for the other scores.


    • Edited by Acamar Wednesday, March 18, 2015 2:49 AM sp
    • Marked as answer by Youjun Tang Wednesday, March 25, 2015 6:58 AM
    Wednesday, March 18, 2015 2:48 AM