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!
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.
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.
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.
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
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.
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.
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 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
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 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