EDN Admin
Well-known member
I am pretty nooby at this, and have totally forgotten half of what i did know about 2 years ago, im sure it is possible to write a bit of code in the main class and then call this using a single word just to keep my code cleaner otherwise im looking at over 1400
extra lines.
this is what ive got
<pre class="prettyprint lang-vb Public Class Form1
Dim TotalBtnPresses As Integer
Dim Btn1 As Integer
Dim Btn2 As Integer
Dim Btn3 As Integer
Dim Btn4 As Integer
Dim Btn5 As Integer
Dim Btn6 As Integer
Dim Btn7 As Integer
Dim Btn8 As Integer
Dim Btn9 As Integer
Dim Btn10 As Integer
Dim Btn11 As Integer
Dim Btn12 As Integer
Dim Btn13 As Integer
Dim Btn14 As Integer
Dim Btn15 As Integer
Dim Btn16 As Integer
Dim Btn17 As Integer
Dim Btn18 As Integer
Dim Btn19 As Integer
Dim Btn20 As Integer
Dim Btn21 As Integer
Dim Btn22 As Integer
Dim Btn23 As Integer
Dim Btn24 As Integer
Dim Btn25 As Integer
Dim Btn26 As Integer
Dim Btn27 As Integer
Dim Btn28 As Integer
Dim Btn29 As Integer
Dim Btn30 As Integer
Dim Btn31 As Integer
Dim Btn32 As Integer
Dim Btn33 As Integer
Dim Btn34 As Integer
Dim Btn35 As Integer
Dim Btn36 As Integer
Dim Btn37 As Integer
Dim Btn38 As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TotalBtnPresses += 1
Btn1 += 1
Label1.Text = Btn1 / TotalBtnPresses
Label2.Text = Btn2 / TotalBtnPresses
Label3.Text = Btn3 / TotalBtnPresses
Label4.Text = Btn4 / TotalBtnPresses
Label5.Text = Btn5 / TotalBtnPresses
Label6.Text = Btn6 / TotalBtnPresses
Label7.Text = Btn7 / TotalBtnPresses
Label8.Text = Btn8 / TotalBtnPresses
Label9.Text = Btn9 / TotalBtnPresses
Label10.Text = Btn10 / TotalBtnPresses
Label11.Text = Btn11 / TotalBtnPresses
Label12.Text = Btn12 / TotalBtnPresses
Label13.Text = Btn13 / TotalBtnPresses
Label14.Text = Btn14 / TotalBtnPresses
Label15.Text = Btn15 / TotalBtnPresses
Label16.Text = Btn16 / TotalBtnPresses
Label17.Text = Btn17 / TotalBtnPresses
Label18.Text = Btn18 / TotalBtnPresses
Label19.Text = Btn19 / TotalBtnPresses
Label20.Text = Btn20 / TotalBtnPresses
Label21.Text = Btn21 / TotalBtnPresses
Label22.Text = Btn22 / TotalBtnPresses
Label23.Text = Btn23 / TotalBtnPresses
Label24.Text = Btn24 / TotalBtnPresses
Label25.Text = Btn25 / TotalBtnPresses
Label26.Text = Btn26 / TotalBtnPresses
Label27.Text = Btn27 / TotalBtnPresses
Label28.Text = Btn28 / TotalBtnPresses
Label29.Text = Btn29 / TotalBtnPresses
Label30.Text = Btn30 / TotalBtnPresses
Label31.Text = Btn31 / TotalBtnPresses
Label32.Text = Btn32 / TotalBtnPresses
Label33.Text = Btn33 / TotalBtnPresses
Label34.Text = Btn34 / TotalBtnPresses
Label35.Text = Btn35 / TotalBtnPresses
Label36.Text = Btn36 / TotalBtnPresses
Label37.Text = Btn37 / TotalBtnPresses
Label38.Text = Btn38 / TotalBtnPresses
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TotalBtnPresses += 1
Btn2 += 1
Label1.Text = Btn1 / TotalBtnPresses
Label2.Text = Btn2 / TotalBtnPresses
End Sub
End Class
[/code]
As you can see doing that for 38 seperate button makes for alot of code. how do i make it use the one from button1_click for the other 37 buttons.
without writing it in each one?
View the full article
extra lines.
this is what ive got
<pre class="prettyprint lang-vb Public Class Form1
Dim TotalBtnPresses As Integer
Dim Btn1 As Integer
Dim Btn2 As Integer
Dim Btn3 As Integer
Dim Btn4 As Integer
Dim Btn5 As Integer
Dim Btn6 As Integer
Dim Btn7 As Integer
Dim Btn8 As Integer
Dim Btn9 As Integer
Dim Btn10 As Integer
Dim Btn11 As Integer
Dim Btn12 As Integer
Dim Btn13 As Integer
Dim Btn14 As Integer
Dim Btn15 As Integer
Dim Btn16 As Integer
Dim Btn17 As Integer
Dim Btn18 As Integer
Dim Btn19 As Integer
Dim Btn20 As Integer
Dim Btn21 As Integer
Dim Btn22 As Integer
Dim Btn23 As Integer
Dim Btn24 As Integer
Dim Btn25 As Integer
Dim Btn26 As Integer
Dim Btn27 As Integer
Dim Btn28 As Integer
Dim Btn29 As Integer
Dim Btn30 As Integer
Dim Btn31 As Integer
Dim Btn32 As Integer
Dim Btn33 As Integer
Dim Btn34 As Integer
Dim Btn35 As Integer
Dim Btn36 As Integer
Dim Btn37 As Integer
Dim Btn38 As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TotalBtnPresses += 1
Btn1 += 1
Label1.Text = Btn1 / TotalBtnPresses
Label2.Text = Btn2 / TotalBtnPresses
Label3.Text = Btn3 / TotalBtnPresses
Label4.Text = Btn4 / TotalBtnPresses
Label5.Text = Btn5 / TotalBtnPresses
Label6.Text = Btn6 / TotalBtnPresses
Label7.Text = Btn7 / TotalBtnPresses
Label8.Text = Btn8 / TotalBtnPresses
Label9.Text = Btn9 / TotalBtnPresses
Label10.Text = Btn10 / TotalBtnPresses
Label11.Text = Btn11 / TotalBtnPresses
Label12.Text = Btn12 / TotalBtnPresses
Label13.Text = Btn13 / TotalBtnPresses
Label14.Text = Btn14 / TotalBtnPresses
Label15.Text = Btn15 / TotalBtnPresses
Label16.Text = Btn16 / TotalBtnPresses
Label17.Text = Btn17 / TotalBtnPresses
Label18.Text = Btn18 / TotalBtnPresses
Label19.Text = Btn19 / TotalBtnPresses
Label20.Text = Btn20 / TotalBtnPresses
Label21.Text = Btn21 / TotalBtnPresses
Label22.Text = Btn22 / TotalBtnPresses
Label23.Text = Btn23 / TotalBtnPresses
Label24.Text = Btn24 / TotalBtnPresses
Label25.Text = Btn25 / TotalBtnPresses
Label26.Text = Btn26 / TotalBtnPresses
Label27.Text = Btn27 / TotalBtnPresses
Label28.Text = Btn28 / TotalBtnPresses
Label29.Text = Btn29 / TotalBtnPresses
Label30.Text = Btn30 / TotalBtnPresses
Label31.Text = Btn31 / TotalBtnPresses
Label32.Text = Btn32 / TotalBtnPresses
Label33.Text = Btn33 / TotalBtnPresses
Label34.Text = Btn34 / TotalBtnPresses
Label35.Text = Btn35 / TotalBtnPresses
Label36.Text = Btn36 / TotalBtnPresses
Label37.Text = Btn37 / TotalBtnPresses
Label38.Text = Btn38 / TotalBtnPresses
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TotalBtnPresses += 1
Btn2 += 1
Label1.Text = Btn1 / TotalBtnPresses
Label2.Text = Btn2 / TotalBtnPresses
End Sub
End Class
[/code]
As you can see doing that for 38 seperate button makes for alot of code. how do i make it use the one from button1_click for the other 37 buttons.
without writing it in each one?
View the full article