|
-
Nov 29th, 2006, 02:58 PM
#1
Thread Starter
New Member
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)
-
Nov 29th, 2006, 02:59 PM
#2
Re: 10% probability of dying
What do you mean by die? Should the label be..removed?
-
Nov 29th, 2006, 03:03 PM
#3
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
 
-
Nov 29th, 2006, 03:08 PM
#4
Thread Starter
New Member
Re: 10% probability of dying
 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
-
Nov 29th, 2006, 03:15 PM
#5
-
Nov 29th, 2006, 03:18 PM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 29th, 2006, 07:01 PM
#7
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:
Dim myRandom As New Random
For Each lbl As Label in myTableLayoutPanel.Controls
If myRandom.Next(0, 10) = 0 Then
'Kill the Label.
lbl.Dispose()
myTableLayoutPanel.Controls.Remove(lbl)
End If
Next lbl
-
Nov 29th, 2006, 08:42 PM
#8
Thread Starter
New Member
Re: 10% probability of dying
 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
-
Nov 29th, 2006, 08:50 PM
#9
Re: 10% probability of dying
Or more specifically even:
VB Code:
Private myRandom As New Random
Private Sub KillLabels(ByVal likelihoodOfDeath As Integer)
Debug.Assert(likelihoodOfDeath > 0 AndAlso likelihoodOfDeath <= 100)
For Each lbl As Label in myTableLayoutPanel.Controls
If myRandom.Next(0, 100) < likelihoodOfDeath Then
'Kill the Label.
lbl.Dispose()
myTableLayoutPanel.Controls.Remove(lbl)
End If
Next lbl
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|