Can anyone tell me how I would fix this code to do the following?
I want the buttons to be 0 through 9 not 1 through 10 like they are now.
==
Inherits System.Windows.Forms.Form
Public buttons(9) As Button
Const ButtonWH As Integer = 30 'Width & height of buttons
Private Sub Button_click(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
Dim n As Integer
Dim s As String
s = CType(sender, System.Windows.Forms.Button).Text
If IsNumeric(s) Then
n = Convert.ToInt32(s)
lblOutput.Text = lblOutput.Text & (n)
Else
lblOutput.Text = "Incorrect use of handler!"
End If
End Sub
Private Sub createButtons(ByVal i As Integer, ByVal pnt As Point) 'Which &
where
'Populate form with Buttons
buttons(i) = New Button
buttons(i).Enabled = True
buttons(i).Visible = True
buttons(i).Text = Convert.ToString(i + 1) '1, 2, 3, ...
buttons(i).Size = New System.Drawing.Size(ButtonWH, ButtonWH)
buttons(i).Location = pnt
Me.Controls.Add(buttons(i))
End Sub
#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.
Friend WithEvents btnExit As System.Windows.Forms.Button
Friend WithEvents lblOutput As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnExit = New System.Windows.Forms.Button
Me.lblOutput = New System.Windows.Forms.Label
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'btnExit
'
Me.btnExit.Location = New System.Drawing.Point(200, 248)
Me.btnExit.Name = "btnExit"
Me.btnExit.Size = New System.Drawing.Size(64, 24)
Me.btnExit.TabIndex = 0
Me.btnExit.Text = "Exit"
'
'lblOutput
'
Me.lblOutput.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0,
Byte))
Me.lblOutput.Location = New System.Drawing.Point(112, 104)
Me.lblOutput.Name = "lblOutput"
Me.lblOutput.Size = New System.Drawing.Size(256, 48)
Me.lblOutput.TabIndex = 1
Me.lblOutput.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(176, 160)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(104, 24)
Me.Button1.TabIndex = 2
Me.Button1.Text = "Clear Label"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(536, 273)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.lblOutput)
Me.Controls.Add(Me.btnExit)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
lblOutput.Text = ""
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim i, j, row As Integer
'Dim start As Char = "A"c
'Dim alpha(9) As Char
Dim pntCurrent As Point
row = 24
For i = 0 To 9
If i Mod 2 = 0 Then
j = i + 1
Else
j = i - 1
End If
Next
j = 0
For i = 0 To 9
j = i Mod 13 + 2
If i = 13 Then
row = 65 ' Drop to next line
End If
pntCurrent = New Point(j * (ButtonWH + 8), row)
Call createButtons(i, pntCurrent)
'create Buttons populates the form with the Buttons
Next
For k As Integer = 0 To buttons.GetUpperBound(0)
AddHandler buttons(k).Click, AddressOf Button_click
Next
End Sub