In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to achieve VB.NET construction object, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Event description
When Sub Main runs, it is loaded as a component, and before the object is created.
Class_Initialize it runs before other code in the object runs. When an object is created, it is transported
Called by a line program.
Class_Terminate is run after other code in the object is run. Run when the object is unloaded
Program call.
In VB.NET, objects also have the concept of life cycle, but it is very different from what it used to be. In particular, we no longer have the same concept of component-level Sub Main (which is loaded as a DLL), and the Class_Terminate event has been changed, while the Class_Initialize event has been replaced by a mature constructor method. It is worth pointing out that this constructor method can accept parameters. Now in VB.NET, all we need to define a life cycle is a New event that runs before other code in the object and is called when the object is created.
VB.NET construction
The VB.NET construction object is triggered when we create a new instance of the class. You can use the keyword NEW to implement it.
Sub Main: since VB 6 is based on COM, creating an object will trigger a Sub Main process to run. This happens when an object is created from a given component (usually DLL). Before creating the object, the VB 6 runner loads the DLL (dynamic Link Library) and runs the Sub Main process.
The .NET common language runtime takes a different approach to processing components, as does VB.NET. This means that no Sub Main procedure is called when the component is loaded. In fact, Sub Main is only used when an application starts. When another component is loaded by the application, only the code in the class is called. In fact, it is unwise to rely on Sub Main in VB6, because the code will be run before all wrong actions. Bugs in Sub Main is difficult to debug in VB6. If we have to use code that adheres to the concept of Sub Main to initialize, then we need to execute a workspace in VB.NET.
It is easy to call a method from a constructor method in each class. For example, we can create valid code in a module:
Public Module CentralCode Private blnHasRun As Boolean Public Sub Initialize () If Not blnHasRun Then blnHasRun = True (initialize here) End If End Sub End Module
This program is designed to run only once, no matter how it is called. We can use this method from every constructor in the class. For example:
Public Class TheClass Public Sub New () CentralCode.Initialize () (add additional work here) End Sub End Class above is all the content of the article "how to implement VB.NET Construction objects". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.