CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2012
    Posts
    3

    Basic Visual Basic Homework help!!

    I am very new to visual basic. My homework assignment is to make a form functional that my teacher set up. The for is a coin toss program that has a text box for heads and tails that will be filled with the head and tails count (the amount it lands on either) The percentage of times it lands on either and the longest run that a head or tail is consecutively landed on. We have a text box the user inserts the amount of flips they want. there are two buttons; one of them just flips the coin as many times as the user inserts and the other button flips the coin until the consecutive flips of either heads or tails is reached from the user inserted amount. I have no clue what to do with the code. How do I do this?!

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Basic Visual Basic Homework help!!

    Probably need to GO TO CLASS to learn how NOT to cheat...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Oct 2012
    Posts
    3

    Re: Basic Visual Basic Homework help!!

    I have gone to class every single day. The teacher just learned Visual Basic this summer and is not much help. There is no text for this book so I am trying to get HELP any way I can. I am not trying to cheat (although I understand it may seem like that and maybe it even is cheating) I am just really lost and seeing if anyone can give me a hand. I have been working on this problem for a week straight.

  4. #4
    Join Date
    Oct 2012
    Posts
    3

    Re: Basic Visual Basic Homework help!!

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim rnd As New Random
    Dim num As Integer
    Dim headcount As Double
    Dim tailcount As Double
    Dim target As Double

    For i = 0 To target
    num = rnd.Next(0, 2)

    headcount = 0
    tailcount = 0
    If num = 1 Then
    headcount += (headcount + 1)
    Else
    tailcount += (tailcount + 1)
    End If

    Next

    txtHeadsCount.Text = headcount
    txtTailsCount.Text = tailcount


    This is a code I have so far and all I can do is get it to give me 1 count in either heads or tail at a click

  5. #5
    Join Date
    Jul 2005
    Posts
    1,083

    Re: Basic Visual Basic Homework help!!

    Study the RND function, it will help you to simulate the result of each coin flip
    http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Basic Visual Basic Homework help!!

    Looks a lot like VB.Net, not VB6. Make sure which book you are reading!

    This part in particular
    Code:
    num = rnd.Next(0, 2)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Basic Visual Basic Homework help!!

    For a start, I think you need to make your tailcount and headcount variables Static

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Basic Visual Basic Homework help!!

    And this doesn't do what you expect:
    Code:
    headcount += (headcount + 1)
    Headcount = 2
    headcount += (headcount + 1)
    2 ________ + ( 2+1)
    = 5 instead of 3

    Code:
    headcount += 1
    This will add 1 each time...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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