Sunteți pe pagina 1din 11

Methods

Methods
Method - is any procedure that is contained within a class.
Although the command window and message dialogs are
valid ways to receive input from a user and display output,
they are limited in their capabilitiesthe command
window can obtain only one line of input at a time from the
user, and a message dialog can display only one
message.
To introduce more sophisticated user interface
programming, GUI is used.

Methods
GUI Graphical User Interface
GUI event handling - the ability to respond to a state of
change in the GUI, such as when
the user clicks a button
A class can inherit attributes and behaviors (data and
methods) from another class if that class is specified to the
right of the Inherits keyword.
An event represents a user action, such as clicking a
Button or altering a value.

Methods
An event handler is a method that is executed (called)
when a certain event is raised (occurs).
Event-handler names created by the IDE begin with the
objects name, followed by an underscore and the name
of the event.
Calls to methods, such as Math.Max, that are defined in a
class in the FCL must include the class name and the dot
(.) operator (also called the member access operator)

Methods
Parameter Info feature displays information for
programmer-defined procedures and all methods
contained in the FCL.
IntelliSense provides a list of all the available methods in
class Math.
The Math class contains numerous methods
that allow the programmer to perform a variety of
common mathematical calculations

Methods
Expected Output:

Methods
Step 1. Open Windows Application
Step 2. Create three (3) textboxes and name them txtFirst,
txtSecond, and txtThird.
Step 3. Create three (3) labels and name them lblOne,
lblTwo, and lblThree. Put them beside the
textboxes.
Use the following text:
Enter First Value:
Enter Second Value:
Enter Third Value:

Methods
Step 4. Create another label and name it lblMaximum
with no text. Put it under lblThree.
Step 5. Create a button and name it cmdMaximum and
change the text to Maximum.
Step 6. Double click the cmdMaximum button and put the
following codes:
Dim value1, value2, value3 As Double
value1 = txtFirst.Text
value2 = txtSecond.Text
value3 = txtThird.Text
lblMaximum.Text = Maximum(value1, value2, value3)

Methods

Step 7: Add the following below the codes of cmdMaximum:


Function Maximum(ByVal valueOne As Double, _
ByVal valueTwo As Double, ByVal valueThree As Double)
Return Math.Max(Math.Max(valueOne, valueTwo), valueThree)
End Function

Methods
All codes should look like this:
Public Class FrmMaximum
Private Sub cmdMaximum_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdMaximum.Click
Dim value1, value2, value3 As Double
value1 = txtFirst.Text
value2 = txtSecond.Text
value3 = txtThird.Text
lblMaximum.Text = Maximum(value1, value2, value3)
End Sub
Function Maximum(ByVal valueOne As Double, ByVal valueTwo As Double,
ByVal valueThree As Double)
Return Math.Max(Math.Max(valueOne, valueTwo), valueThree)
End Function
End Class

Methods
Activity
Make a program that will let the user enter 5 numbers
including decimals and display on a label the highest
number.

S-ar putea să vă placă și