Declaring Methods
The simple HelloWorld component in Listing 17.1 contains a single method named SayMessage(), which returns a string value. When writing components with Visual Basic .NET, you create methods by creating either a subroutine or a function. Use a subroutine when a method does not return a value, and use a function when a method does return a value.
The SayMessage() method in Listing 17.1 is an instance method. In other words, you must create a new instance of the HelloWorld class before you can call the SayMessage() method like this:
HelloWorld objHelloWorld = new HelloWorld();lblMessage.Text = objHelloWorld.SayMessage();
In the first line, a new instance of the HelloWorld component is created. The SayMessage() method is called ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access