vb.net 2003 I am so lost

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bflyrose
    New Member
    • Feb 2007
    • 7

    vb.net 2003 I am so lost

    I am trying to create a coin toss game for class but me and programming are having a hard time getting to know one another.

    my question is What is wrong with this code?
    I really do alot better with networks hardware and software wish I didn't even have to do this because I am so confused

    I am not done with alot of it and I have to rotate two images corresponding to picturebox and whether heads lands or tails

    Code:
     Dim MyValue As Integer = Toss
    
            MyValue = CInt(Int((2 * Rnd())))
            If MyValue = 0 Then
                intHeads = intHeads + 1
    
    
            Else
    
                intTails = intTails + 1
    
            End If
            intTotal = intHeads + intTails
            If radOne.Checked = True Then
                intHeads = intHeads + 1
            Else
                intTails = intTails + 1
    
            End If
    
    
    
            PicCoin.Image = Image.FromFile("C:\Documents and Settings\Lauri\Desktop\#3projectvb\TossThatCoin\bin & m_strFile_Prefix & m_strFile_Suffix")
    and thank you
    Last edited by willakawill; Feb 26 '07, 05:37 AM. Reason: please use code tags when posting code
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi. What are you trying to do with this code and what is not working?

    Comment

    • bflyrose
      New Member
      • Feb 2007
      • 7

      #3
      Originally posted by willakawill
      Hi. What are you trying to do with this code and what is not working?
      hi I am trying to random number of tosses and pictures of tails and heads with this code I revised it some but it still not working right

      Code:
      Private Sub btnToss_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToss.Click
              Dim MyValue As Integer
              Dim x As Integer
              For x = 0 To Toss
                  MyValue = CInt(Int((2 * Rnd())))
                  If (MyValue < 0.5) Then
                      Heads += 1
                  Else
                      Tails += 2
                  End If
                  intTotal += 2
      
              Next
      
              'Update Picture Box and Display Leading Output
              If (Heads > Tails) Then
                  txtCurrentOut.Text = HEAD
                  PicCoin.Visible = True
                  PicCoin.Image = Image.FromFile("head.jpg")
              ElseIf (Tails > Heads) Then
                  txtCurrentOut.Text = TAIL
                  PicCoin.Visible = True
                  PicCoin.Image = Image.FromFile("tail.jpg")
                  
              End If
      
              'Update Displays
              txtHeads.Text = Heads.ToString
              txtTails.Text = Tails.ToString
              txtTosses.Text = intTotal.ToString
      Last edited by willakawill; Feb 27 '07, 02:08 PM. Reason: Once again, please use code tags

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        You need to be more specific than "not working". What is it doing, or not doing?

        I did notice one or two things here...
        Code:
                'Update Picture Box and Display Leading Output
                If (Heads > Tails) Then
                    txtCurrentOut.Text = [U]HEAD[/U]
                    PicCoin.Visible = True
                    PicCoin.Image = Image.FromFile("head.jpg")
                [U]ElseIf (Tails > Heads)[/U] Then
                    txtCurrentOut.Text = [U]TAIL[/U]
                    PicCoin.Visible = True
                    PicCoin.Image = Image.FromFile("tail.jpg")
                End If
        • Unless HEAD and TAIL are constants, they should be in quotes
        • The ElseIf (Tails > Heads) can probably just be written as Else. Also, note that your current test will not catch the situation where Tails = Heads.


        Oh! And in this...
        Code:
        MyValue = CInt(Int((2 * Rnd())))
        If (MyValue < 0.5) Then
        I don't think it makes much sense to compare an integer (whole numbers, remember) to 0.5.

        Comment

        • bflyrose
          New Member
          • Feb 2007
          • 7

          #5
          Originally posted by Killer42
          You need to be more specific than "not working". What is it doing, or not doing?

          I did notice one or two things here...
          Code:
                  'Update Picture Box and Display Leading Output
                  If (Heads > Tails) Then
                      txtCurrentOut.Text = [U]HEAD[/U]
                      PicCoin.Visible = True
                      PicCoin.Image = Image.FromFile("head.jpg")
                  [U]ElseIf (Tails > Heads)[/U] Then
                      txtCurrentOut.Text = [U]TAIL[/U]
                      PicCoin.Visible = True
                      PicCoin.Image = Image.FromFile("tail.jpg")
                  End If
          • Unless HEAD and TAIL are constants, they should be in quotes
          • The ElseIf (Tails > Heads) can probably just be written as Else. Also, note that your current test will not catch the situation where Tails = Heads.


          Oh! And in this...
          Code:
          MyValue = CInt(Int((2 * Rnd())))
          If (MyValue < 0.5) Then
          I don't think it makes much sense to compare an integer (whole numbers, remember) to 0.5.

          yes I see what you mean and what I mean is I am getting counts of tails and heads but by six's and the picture does not always load with the corresponding flip of the coin meaning if the text displays 6 times landing on heads the picture box is not displaying the head I am getting closer I now have percentages displayed thank you for your input

          Comment

          • bflyrose
            New Member
            • Feb 2007
            • 7

            #6
            Originally posted by bflyrose
            yes I see what you mean and what I mean is I am getting counts of tails and heads but by six's and the picture does not always load with the corresponding flip of the coin meaning if the text displays 6 times landing on heads the picture box is not displaying the head I am getting closer I now have percentages displayed thank you for your input
            I did change the integer value to this
            Code:
            intRandom = CInt(Int((2 * Rnd() + 1)))     
            
            
                    For x = 0 To Toss
            
                        If (intRandom < 2) Then
                            Heads += 1
                        Else
                            Tails += 1
                        End If
                        intTotal += 1
            but still I think I am just really tired at the moment because its still not loading the pictures right

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              I'll leave you to mull over it for the moment, because it's time for dinner, then bed (probably a different timezone). But I do have one question. What is the value of Toss?

              Oh, and have you considered setting intRandom inside the loop?

              Comment

              • bflyrose
                New Member
                • Feb 2007
                • 7

                #8
                I had forgotton to come back and say thank you for your help I did get it to finally work right
                Thanks again

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  Originally posted by bflyrose
                  I had forgotton to come back and say thank you for your help I did get it to finally work right
                  Glad we could help. :)

                  Comment

                  Working...