Results 1 to 9 of 9

Thread: 10% probability of dying

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    15

    10% probability of dying

    Hi all

    got another problem. Been playing with a few ideas for a task which i could do with some help with. Any help would be deeply appreciated. Thanks all


    The task

    Write a Visual Basic program which draws a 5 by 5 grid of labels and a button. Each time the button is clicked each label should decide whether it dies or not with a 10% probability of dying. (that is, after the first click about 10% of your labels should die)

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: 10% probability of dying

    What do you mean by die? Should the label be..removed?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: 10% probability of dying

    With a number that low, it may not pay to do anything fancy with collections or anything, just loop from 0 to 24, picking a random number between 0-100 (the top value is not used in Random.GetNext, so 0-100 is right). If the number comes up less than 10, then that label dies. The only difficulty would be deciding which label each iteration of the loop was dealing with, but that shouldn't be hard.

    Of course, as Atheist pointed out, we don't know what "dies" means in terms of a label.

    You could make a pun out of it, by simply changing it's color.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    15

    Re: 10% probability of dying

    Quote Originally Posted by Atheist
    What do you mean by die? Should the label be..removed?
    10% of the labels are to go each time you press a button

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: 10% probability of dying

    to go ...well then i presume you mean that they should be removed
    Shaggy hiker has said it all
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: 10% probability of dying

    Sounds like a school project? What have you done so far?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: 10% probability of dying

    I would go along these lines. A 5x5 grid sounds like a good use of a TableLyoutPanel. You'd place your 25 Labels in the cells of the table and then do something like this:
    VB Code:
    1. Dim myRandom As New Random
    2.  
    3. For Each lbl As Label in myTableLayoutPanel.Controls
    4.     If myRandom.Next(0, 10) = 0 Then
    5.         'Kill the Label.
    6.         lbl.Dispose()
    7.         myTableLayoutPanel.Controls.Remove(lbl)
    8.     End If
    9. Next lbl
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    15

    Re: 10% probability of dying

    Quote Originally Posted by RobDog888
    Sounds like a school project? What have you done so far?
    Not quite a school project, manage to get diffrent labels disappear at as random variable but not to the 10% dying time that was asked of the task

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: 10% probability of dying

    Or more specifically even:
    VB Code:
    1. Private myRandom As New Random
    2.  
    3. Private Sub KillLabels(ByVal likelihoodOfDeath As Integer)
    4.     Debug.Assert(likelihoodOfDeath > 0 AndAlso likelihoodOfDeath <= 100)
    5.  
    6.     For Each lbl As Label in myTableLayoutPanel.Controls
    7.         If myRandom.Next(0, 100) < likelihoodOfDeath Then
    8.             'Kill the Label.
    9.             lbl.Dispose()
    10.             myTableLayoutPanel.Controls.Remove(lbl)
    11.         End If
    12.     Next lbl
    13. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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