Approaching vb.net (ii) to talk about function call again

Source: Internet
Author: User
Tags dot net integer
Function



Approaching vb.net (ii) to talk about function call again
In VB6 if you want to call a dialog box, first you know to use the VB Built-in MsgBox function, you even use the API, most people are happy to use the API. As follows:
Public Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd as Long, ByVal Lptext as String, ByVal LpC Aption as String, ByVal wtype as long as long. I think the current article rarely introduces some of the primary east level, I just have a limited level, by the way a little bit of elementary knowledge, API and ordinary functions like return a value to the function of the name, this bracket after the last as long is the definition of this function (MessageBox) of the data type is long. So each time the call is preceded by a declaration of a variable, dim xxx As Long and again as follows: Xxx=messagebox (the corresponding parameter is filled in this bracket, as the first argument is ByVal hwnd As Long, which is for you to fill in a Long handle, you can first call a 0 , and write a comma, writing the character data for the second string, which is the contents of the dialog box ... ..... In fact, most of the time, the returned value is not used, just as a method of invocation. Lib "user32" means using User32 DLL file, alias "MessageBoxA" is API function, MessageBox is just a code name, in Linux not also have an alias? , it's an alias.
Why did vb.net make most of the older programmers feel angry? This is not completely conservative, a beginner programmer is unable to imagine a complete program language needs accumulated over the last few days of knowledge. But now all this has changed, as some of the most basic knowledge mentioned above is no longer basic. But why are you willing to use the API, you will answer, he is more flexible and challenging, but vb.net
is not more rich in these. Maybe Microsoft will be like a rumor to restore some VB6 things in BETA2, but I am not happy. Perhaps some people say that VB has a lot of learning Java (probably learning Microsoft's situation is always very few, everyone likes to be in fact Xianpinaifu, in the verbal direction of the strong, cynicism the weak to be satisfied) but only one object-oriented enough to support the net plan, if so, Microsoft should have been in the other software vendors already. is the object-oriented, there is a more powerful difference, and in fact he is more powerful. You may not be able to use him, but in the years to come, some new programmers (who may not yet have access to programming today) will master a language that is so powerful ...
Let's see how that changes:
Shared Function <system.runtime.interopservices.dllimport ("User32.dll") > MessageBoxA (ByVal hwnd as Integer, ByVal text As String, ByVal lpcaption as String, ByVal wtype as Integer) As Integer
End Function
First integer is replaced by 32-bit data (long is 64-bit)
System is a family of net languages, and System.Runtime.InteropServices is a class in system. System.Runtime.InteropServices.DLLimpor is one of the ways. Calling the DLL's API
interface, which means that VB6 's Lib "user32", share is the meaning of sharing, for example:
Public Class ClassA
Shared Function <system.runtime.interopservices.dllimport ("User32.dll") > MessageBoxA (ByVal h as Integer, ByVal m As String, ByVal C as String, ByVal type As Integer) As Integer
End Function
End Class
You can call Classa.messageboxa this way, but without this share after class, there will be no MESSAGEBOXA members.
Now you use him as you used to.

In fact, the above method is not correct, we still have to use API declaration, but a different form

If you think this is vb.net, look at this:
System. WinForms.MessageBox.Show ("Dialogue content is written here", "title written here", MessageBox.) OK Bitor MessageBox. Iconasterisk)

This is the object-oriented, you have done all the tasks. No API declarations are required. There is no need to write extra code.

MessageBox. iconasterisk= exclamation icon
MessageBox. Iconerror= error icon
MessageBox. Iconexclamation= warning icon
MessageBox. Iconhand= error icon
MessageBox. iconinformation= hint icon

By Dot Net is to arrive, in the back of the family, in the back of the class, in the back of the object. The second problem is the relationship between classes and classes, net deals with human relationships on the Internet, and deals with class and class relationships in program languages. The bottom is to add share, the bottom is the class behind, or dim into an object (take him as a variable bar), is equal to class, or new class. Is Dim xxx As Class=new class or Dim xxx As New Class
It's just that vb.net will be simpler, and it's not necessary to study something difficult.
Writing a program will be as free as writing an article, he is also more difficult, he let you decide what to do, education experience may no longer be the most important, he let you in the space of wisdom to gallop ...



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.