How do we use objects in Visual Basic
The most simple way
Objects or classes are just slightly more complicated than elements such as String, Integer, Long, etc.. It requires the presence of the New function to exist. In this article, I present the class in its simplest form is to use the class as a structure. The structure is a term used in a programming language which is the oldest C or C + + (Also known Cpp). Structure is ultimately is a combination of several basic elements.
In Visual Basic, the term structure does not exist because Visual Basic is object-oriented programming. Structure is not an object, it is an element in the concept abandoned. However, using a class as a structure is very very very very useful. Before discussing and debating concepts, here is the computer code for the item, that is to say the use of class in its simplest form.
The pace of Form1.vb form
The Form1.vb file.
<summary> improve your coding </summary> <remarks></remarks> Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load End Sub <summary> start button </summary> <param name="sender"></param> <param name="e"></param> <remarks></remarks> Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim oClass1 As Class1 Initiate variable Try If oClass1 Is Nothing Then MsgBox("oClass1 is nothing") oClass1 = New Class1 create object oClass1.File = "filename" fill the String named File oClass1.Extension = ".txt" fill the String named Extension oClass1.Path = "c:" fill the String named Path display informations from oClass1 to form and textbox TextBox1.Text = "this is my oClass1" TextBox2.Text = oClass1.File TextBox3.Text = oClass1.Extension TextBox4.Text = oClass1.Path Catch ex As Exception add basic error message here MsgBox(ex.StackTrace, MsgBoxStyle.Exclamation, ex.Message) End Try End Sub End Class |
The Class1.vb file.
Public Class Class1 Public File As String Public Path As String Public Extension As String End Class |
Then, in the Try it creates the object:
oClass1 = New Class1 create object |
When the class has been called oClass1 is created, information on strings that compose it: "File", "Extension" and "Path"
oClass1.File = "filename" oClass1.Extension = ".txt" oClass1.Path = "c:" |
Note that the assignment is simply equal the mathematical sign (=).
So you have to read that "filename" is in oClass1.File and so is the other 2. In other words, this information is stored in the object oClass1.
Finally, from the object, it does display the information in the TextBox:
TextBox1.Text = "this is my oClass1" TextBox2.Text = oClass1.File TextBox3.Text = oClass1.Extension TextBox4.Text = oClass1.Path |
Noticed something interesting when you write lines of code, every time you hit the point after writing the name of a variable, a window appears and shows the different choices. In these choices, you will find your 3 strings String. Choose them using the mouse or keyboard selections and avoid writing them. Save time. Use the intelligence of the code and Visual Basic Express or Visual Studio to your own advantage.
One of the advantages of working with objects (or classes) is to combine pieces of information in a single package. And then manipulate a packet of information that is easier to manipulate the information one by one.
About
I invite you to visit my blog for more articles and leave a comment.
Check Technologies represents more than 10 years .... Computer and computer aided design.
Official Website Check Technologies = http://checktechno.ca
0 komentar:
Posting Komentar