I have Button A and Button B. How to make Button A, same with action like Button B ?
For example , if I click Button A , it will do calculation x = 1 + 1 . Button B also will do that if I click at somewhere else.
But, I dont want to copy the same code in A to the code B . It will make longer for my case.
PLease help ..
If you want to avoid duplicate code use a method. In this case call it
doCalculation or something like that.
To add to ddanbe recommendation of using a method to keep your code clean and DRY (do not repeat yourself), you can also make use of the controls Handles clause which allows you to specify what events a controls method is bound to. So for example, you could state that the click event of button1 is also bound to button2:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click, Button2.Click MessageBox.Show(doCalculation(1, 1).ToString) End Sub Private Function doCalculation(a As Integer, b As Integer) As Integer Return a + b End Function
Ideally, you would rename Button1_Click to something more appropriate as it is handling the click event of two buttons.
Edited by djjeavons
ddanbe and djjeavons. :)
You may also want to look into
AddHandler which allows you to add the same handler to multiple controls.
Edited by Reverend Jim
@model Stattips.Models.MatchesList <br /> <div class="col-sm-8 container-fluid"> <table class="table table-striped "> <tr rowspan="3"><ul class="breadcrumb"> <li><a href="#">Soccer</a></li> <li><a href="#">Albania</a></li> <li class="active">Kategoria Superiore</li> </ul></tr> <tr> <th>Matches</th> <th>Country</th> <th>Odds</th> </tr> @using (Html.BeginForm("AddMatches", "Matches")) ...
i put this code::
matirial = raw_input ('what is your favorite lesson') if matirial == 'maths' or 'math' or 'Maths' or 'Math' or 'رياضيات': print 'like me broo!!' elif matirial ...
I have access data table and vb . project .access data table include ID ,word and description Colum v b project include three text box and one list ...