ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

42-Class

What is a class? A Class is a group of object that defines its functionality as a set of properties and the methods that will respond to. And it is also a container of your data and code. Wherein you can limit the data that you’re accessing. In Object-Oriented Programming(OOP) , classes, methods and properties help you create a complete application.

 

This is the example on how to use a class in the application.

  • Open the Visual Basic, select “File” on the menu, hit new and create a new project.
    01_helloworld
  • The New Project dialog will appear.
    create2s
    Select “windows” in the project types, hit the “windows form application” in the templates and hit “ok“.
  • Go to the solution explorer. Right click the application, click add and select a class
    fclassf1
  • The add new Item dialog will appear and do the process like what is shown below.
    fclassf3
  • Design the form just like shown below.

    fclassf2
  • Select Lines(class) and add this following code:
  1. Private lenLines As String
  2.  
  3. Property Lines() As String
  4. Get
  5. Return lenLines
  6. End Get
  7. Set(ByVal Value As String)
  8. lenLines = Value
  9. End Set
  10. End Property
  11.  
  12. ReadOnly Property Length() As Integer
  13. Get
  14. Return lenLines.Length
  15. End Get
  16. End Property
  • Go to the form design and double click a button to fire the click event handler of it. Add this following code in the method.
  1. Dim oLine As Lines
  2.  
  3. oLine = New Lines()
  4.  
  5. oLine.Lines = txtlines.Text
  6. txtlen.Text = oLine.Length.ToString()

Output:

fclassf4

 

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!