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

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




Whats wrong here?

 
Reply to this topicStart new topic

Whats wrong here?, Deal or no deal

aikiscotsman
21 Apr, 2008 - 09:19 AM
Post #1

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 9

Ok folks im posting this again, but ive managed to tidy up the crap i posted before. ive take the script back a bit.
ive added my values at Initiliseamount() but still unsure how to change the text when i click a button from saying box 1, box 2, box 15 etc, to 100 200,2000 etc. see here-

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.BackColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(192, Byte), CType(192, Byte))
Me.ClientSize = New System.Drawing.Size(712, 334)
Me.Name = "Form1"
Me.Text = "Form1"

End Sub

#End Region

'*******************************************************
'* *
'* Written By *
'* 15 April 2008 *
'* *
'* Version 2 *
'* *
'*******************************************************

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(100, Gap + (k - 1) * 60)
Else
CPanel(k).Location = New Point(300, 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 Integer


For K = 1 To boxes

number = Int(Rnd(1) * (boxes - 1) + 1)
Amount(0) = Amount(number)
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

End Sub



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

End Sub
End Class



This is the part with the error
vb

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))


EDIT: Code tags added. Please don't ever use that font color again smile.gif

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

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 12:28AM

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