Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,076 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,763 people online right now. Registration is fast and FREE... Join Now!




Deal or no deal help

2 Pages V  1 2 >  
Reply to this topicStart new topic

Deal or no deal help, asigning money value and rnd

aikiscotsman
18 Apr, 2008 - 08:27 AM
Post #1

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 9

Hi folks, im doing a hnc project at college, which requires building a basic version of deal or no deal.
so far ive created 22 boxes asigned the the no's 1 to 22 and got them randomisd. what im looking to do next is start on my values, ie 1p,10,1.00-250,000 for a box and keep them random. im doin it all through text including my box sizes. so no gui. can anyone help at this stage please. total beginner here.
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Deal Or No Deal Help
18 Apr, 2008 - 08:54 AM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Show us what you have so far and we can see what we can do. I assume you have an array representing the cases where each slot of the array will have a money value that is in that particular case.

So lets see what you came up with and we can guide you further. Don't forget to use code tags. code.gif

smile.gif
User is offlineProfile CardPM
+Quote Post

aikiscotsman
RE: Deal Or No Deal Help
18 Apr, 2008 - 02:05 PM
Post #3

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 9

QUOTE(Martyr2 @ 18 Apr, 2008 - 09:54 AM) *

Show us what you have so far and we can see what we can do. I assume you have an array representing the cases where each slot of the array will have a money value that is in that particular case.

So lets see what you came up with and we can guide you further. Don't forget to use code tags. code.gif

smile.gif




Ok Guys heres a lok at the story so far.....



vb

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(712, 334)
Me.Name = "Form1"
Me.Text = "Form1"

End Sub

#End Region


'*****************************************************************
'* written by **
'* SteffMiller **
'* April/May 2008 **
'* VisualBasics.net
'*****************************************************************

Const boxes = 22

Dim CPanel(boxes) As Panel
Dim Clabel(boxes) As Label
Dim Amount(boxes) As Integer 'stores the money value


Sub CreateLabels()

Dim k As Integer

For k = 1 To boxes

Clabel(k) = New Label
Clabel(k).Size = New Size(80, 30)
Clabel(k).Location = New Point(10, 10)
Clabel(k).BackColor = Color.White
Clabel(k).Font = New Font("Pristina", 16, FontStyle.Bold)
Clabel(k).Text = "Box " & Amount(k)
Clabel(k).Visible = False
CPanel(k).Controls.Add(Clabel(k))




Next

End Sub


Sub CreatePanels()

Const Gap = 10

Dim k As Integer


For k = 1 To boxes

CPanel(k) = New Panel
CPanel(k).Size = New Size(100, 50)
If k <= 11 Then
CPanel(k).Location = New Point(80, Gap + (k - 1) * 60)
Else
CPanel(k).Location = New Point(400, Gap + (k - 12) * 60)
End If

CPanel(k).BackColor = Color.Red

Controls.Add(CPanel(k))

AddHandler CPanel(k).Click, AddressOf panel_click

Next

End Sub



Sub panel_click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim K As Integer

For K = 1 To boxes
If sender Is CPanel(K) Then
CPanel(K).BackColor = Color.Yellow
Clabel(K).Visible = True


End If
Next
End Sub

Sub InitialiseAmount()
Dim k As Integer

For k = 1 To boxes
Amount(k) = k



Next



End Sub
Sub jumbleboxes()
Dim k As Integer
Dim number As Integer

For k = 1 To boxes
number = Int(Rnd(1) * (boxes - 1) + 1)
Amount(0) = Amount(number) 'this section tells the computer _
'to mix the boxes
Amount(number) = Amount(k)
Amount(k) = Amount(0)




Next



End Sub

'*******************************************************
'* *
'* End of global declarations *
'* *
'*******************************************************


Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated

Randomize()

Call InitialiseAmount()
Call jumbleboxes()
Call CreatePanels()
Call CreateLabels()

Me.Height = 1000
Me.Width = 600
Me.BackColor = Color.SlateGray



End Sub



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize()


End Sub
End Class

*edit: I guess you missed the part where I said use code tags! Please use them in the future, thanks! code.gif

This post has been edited by Martyr2: 18 Apr, 2008 - 02:49 PM
User is offlineProfile CardPM
+Quote Post

GravityGuy
RE: Deal Or No Deal Help
18 Apr, 2008 - 02:52 PM
Post #4

New D.I.C Head
*

Joined: 21 Jan, 2008
Posts: 45


My Contributions
In InitialiseAmount() you use a simple loop to assign the Amount array a value from 1 to 22. Why not just initialise the array with the correct values. If there is no easy formula to do it as an array, just assign them one at a time, ie. amount(1) = 0.10; amount(2) = 1; etc.
You will have to declare the array as a double, not as an integer.

I would also put the jumbleboxes loop inside of another loop and repeat the jumbling several more times. Doing it just once with only 22 boxes will not likely jumble all the boxes. You are picking the boxes at random but what are the chances you will actually pick all 22 boxes in 22 selections. Several boxes will be chosen multiple times and some not chosen at all. You can say that is just as valid but I don't think it passes the smell test.
User is offlineProfile CardPM
+Quote Post

aikiscotsman
RE: Deal Or No Deal Help
18 Apr, 2008 - 02:59 PM
Post #5

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 9

QUOTE(GravityGuy @ 18 Apr, 2008 - 03:52 PM) *

In InitialiseAmount() you use a simple loop to assign the Amount array a value from 1 to 22. Why not just initialise the array with the correct values. If there is no easy formula to do it as an array, just assign them one at a time, ie. amount(1) = 0.10; amount(2) = 1; etc.
You will have to declare the array as a double, not as an integer.

I would also put the jumbleboxes loop inside of another loop and repeat the jumbling several more times. Doing it just once with only 22 boxes will not likely jumble all the boxes. You are picking the boxes at random but what are the chances you will actually pick all 22 boxes in 22 selections. Several boxes will be chosen multiple times and some not chosen at all. You can say that is just as valid but I don't think it passes the smell test.


Thanks a lot, that really helps. cheers.
User is offlineProfile CardPM
+Quote Post

aikiscotsman
RE: Deal Or No Deal Help
19 Apr, 2008 - 07:12 AM
Post #6

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 9

QUOTE(aikiscotsman @ 18 Apr, 2008 - 03:59 PM) *

QUOTE(GravityGuy @ 18 Apr, 2008 - 03:52 PM) *

In InitialiseAmount() you use a simple loop to assign the Amount array a value from 1 to 22. Why not just initialise the array with the correct values. If there is no easy formula to do it as an array, just assign them one at a time, ie. amount(1) = 0.10; amount(2) = 1; etc.
You will have to declare the array as a double, not as an integer.

I would also put the jumbleboxes loop inside of another loop and repeat the jumbling several more times. Doing it just once with only 22 boxes will not likely jumble all the boxes. You are picking the boxes at random but what are the chances you will actually pick all 22 boxes in 22 selections. Several boxes will be chosen multiple times and some not chosen at all. You can say that is just as valid but I don't think it passes the smell test.


Thanks a lot, that really helps. cheers.


SOrry guys, still struggling a bit. I think i understand the point about the initialiseamount()
can you helpmore with how i would start to asign them amounts. i feel really stuck and yet oi know the answer is not that hard. got this so far, whats missing?????

CODE

    Const boxes = 22

    Dim CPanel(boxes) As Panel
    Dim Clabel(boxes) As Label
    Dim Amount(boxes) As Double    'stores the money value


    Sub CreateLabels()

        Dim k As Integer

        For k = 1 To boxes

            Clabel(k) = New Label
            Clabel(k).Size = New Size(80, 30)
            Clabel(k).Location = New Point(10, 10)
            Clabel(k).BackColor = Color.White
            Clabel(k).Font = New Font("Pristina", 16, FontStyle.Bold)
            Clabel(k).Text = "Box " & Amount(k)
            Clabel(k).Visible = False
            CPanel(k).Controls.Add(Clabel(k))




        Next

    End Sub


    Sub CreatePanels()

        Const Gap = 10

        Dim k As Integer


        For k = 1 To boxes

            CPanel(k) = New Panel
            CPanel(k).Size = New Size(100, 50)
            If k <= 11 Then
                CPanel(k).Location = New Point(80, Gap + (k - 1) * 60)
            Else
                CPanel(k).Location = New Point(400, Gap + (k - 12) * 60)
            End If

            CPanel(k).BackColor = Color.Red

            Controls.Add(CPanel(k))

            AddHandler CPanel(k).Click, AddressOf panel_click

        Next

    End Sub



    Sub panel_click(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim K As Integer

        For K = 1 To boxes
            If sender Is CPanel(K) Then
                CPanel(K).BackColor = Color.Yellow
                Clabel(K).Visible = True


            End If
        Next
    End Sub

    Sub InitialiseAmount()
        Amount(1) = 0.1
        Amount(2) = 0.1
        Amount(3) = 0.5
        Amount(4) = 1.0
        Amount(5) = 5.0
        Amount(6) = 10.0
        Amount(7) = 50.0
        Amount(8) = 100.0
        Amount(9) = 250.0
        Amount(10) = 500.0
        Amount(11) = 750.0
        Amount(12) = 1000.0
        Amount(13) = 3000.0
        Amount(14) = 5000.0
        Amount(15) = 10000.0
        Amount(16) = 15000.0
        Amount(17) = 20000.0
        Amount(18) = 35000.0
        Amount(19) = 50000.0
        Amount(20) = 75000.0
        Amount(21) = 100000.0
        Amount(22) = 250000.0






        Dim k As Integer

        For k = 1 To boxes
            Amount(k) = k



        Next



    End Sub
    Sub jumbleboxes()
        Dim k As Integer
        Dim number As Double


        For k = 1 To boxes
            number = Int(Rnd(1) * (boxes - 1) + 1)
            Amount(0) = Amount(number)  'this section tells the computer _
            'to mix the boxes
            Amount(number) = Amount(k)
            Amount(k) = Amount(0)




        Next



    End Sub

    '*******************************************************
    '*                                                     *            
    '*               End of global declarations            *
    '*                                                     *
    '*******************************************************


    Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated

        Randomize()

        Call InitialiseAmount()
        Call jumbleboxes()
        Call CreatePanels()
        Call CreateLabels()

        Me.Height = 1000
        Me.Width = 600
        Me.BackColor = Color.SlateGray



    End Sub



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Randomize()


    End Sub
End Class


This post has been edited by jayman9: 19 Apr, 2008 - 01:27 PM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Deal Or No Deal Help
19 Apr, 2008 - 01:27 PM
Post #7

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Use code.gif tags when posting your code. Thanks.
User is offlineProfile CardPM
+Quote Post

aikiscotsman
RE: Deal Or No Deal Help
20 Apr, 2008 - 03:53 AM
Post #8

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 9

QUOTE(jayman9 @ 19 Apr, 2008 - 02:27 PM) *

Use code.gif tags when posting your code. Thanks.

ok sorry, i understand now. anyone help?

code.gif

vb

Const boxes = 22

Dim CPanel(boxes) As Panel
Dim Clabel(boxes) As Label
Dim Amount(boxes) As Double 'stores the money value


Sub CreateLabels()

Dim k As Integer

For k = 1 To boxes

Clabel(k) = New Label
Clabel(k).Size = New Size(80, 30)
Clabel(k).Location = New Point(10, 10)
Clabel(k).BackColor = Color.White
Clabel(k).Font = New Font("Pristina", 16, FontStyle.Bold)
Clabel(k).Text = "Box " & Amount(k)
Clabel(k).Visible = False
CPanel(k).Controls.Add(Clabel(k))




Next

End Sub


Sub CreatePanels()

Const Gap = 10

Dim k As Integer


For k = 1 To boxes

CPanel(k) = New Panel
CPanel(k).Size = New Size(100, 50)
If k <= 11 Then
CPanel(k).Location = New Point(80, Gap + (k - 1) * 60)
Else
CPanel(k).Location = New Point(400, Gap + (k - 12) * 60)
End If

CPanel(k).BackColor = Color.Red

Controls.Add(CPanel(k))

AddHandler CPanel(k).Click, AddressOf panel_click

Next

End Sub



Sub panel_click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim K As Integer

For K = 1 To boxes
If sender Is CPanel(K) Then
CPanel(K).BackColor = Color.Yellow
Clabel(K).Visible = True


End If
Next
End Sub

Sub InitialiseAmount()
Amount(1) = 0.1
Amount(2) = 0.1
Amount(3) = 0.5
Amount(4) = 1.0
Amount(5) = 5.0
Amount(6) = 10.0
Amount(7) = 50.0
Amount(8) = 100.0
Amount(9) = 250.0
Amount(10) = 500.0
Amount(11) = 750.0
Amount(12) = 1000.0
Amount(13) = 3000.0
Amount(14) = 5000.0
Amount(15) = 10000.0
Amount(16) = 15000.0
Amount(17) = 20000.0
Amount(18) = 35000.0
Amount(19) = 50000.0
Amount(20) = 75000.0
Amount(21) = 100000.0
Amount(22) = 250000.0






Dim k As Integer

For k = 1 To boxes
Amount(k) = k



Next



End Sub
Sub jumbleboxes()
Dim k As Integer
Dim number As Double


For k = 1 To boxes
number = Int(Rnd(1) * (boxes - 1) + 1)
Amount(0) = Amount(number) 'this section tells the computer _
'to mix the boxes
Amount(number) = Amount(k)
Amount(k) = Amount(0)




Next



End Sub

'*******************************************************
'* *
'* End of global declarations *
'* *
'*******************************************************


Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated

Randomize()

Call InitialiseAmount()
Call jumbleboxes()
Call CreatePanels()
Call CreateLabels()

Me.Height = 1000
Me.Width = 600
Me.BackColor = Color.SlateGray



End Sub



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Randomize()


End Sub
End Class

code.gif

This post has been edited by PsychoCoder: 20 Apr, 2008 - 09:17 AM
User is offlineProfile CardPM
+Quote Post

ferrari12508
RE: Deal Or No Deal Help
20 Apr, 2008 - 08:54 AM
Post #9

D.I.C Lover
Group Icon

Joined: 2 Nov, 2007
Posts: 1,112



Thanked: 2 times
Dream Kudos: 150
My Contributions
ROFL, JUST ROFL
User is offlineProfile CardPM
+Quote Post

aikiscotsman
RE: Deal Or No Deal Help
20 Apr, 2008 - 09:16 AM
Post #10

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 9

QUOTE(ferrari12508 @ 20 Apr, 2008 - 09:54 AM) *

ROFL, JUST ROFL


Thanks for the help. hope you dont hurt yourself rolling around so much
cheers
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Deal Or No Deal Help
20 Apr, 2008 - 09:17 AM
Post #11

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Did that really just happen??!! blink.gif
User is offlineProfile CardPM
+Quote Post

aikiscotsman
RE: Deal Or No Deal Help
20 Apr, 2008 - 10:21 AM
Post #12

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 9

QUOTE(PsychoCoder @ 20 Apr, 2008 - 10:17 AM) *

Did that really just happen??!! blink.gif


What? come on guys. im climbing thewalls trying get this.
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:13PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month