Com interoperability-use the. NET type in the VB Script

Source: Internet
Author: User

Please refer to the following sectionVbsCode:

SetOBJ = Createobject ("System. Collections. arraylist")

OBJ. Add ("This is a test")

OBJ. Add (1)

OBJ. Add (OBJ)

 

Msgbox OBJ (0)

Msgbox OBJ (1)

Msgbox OBJ (2). tostring ()

 

The Code tries to create Arraylist Of . Net Object, and then add several different types of objects in this Arraylist . Why can we Vbs Used in . Net What about built-in types? This is because . Net After installation Com Visible types have been registered. Open the Registry Editor and you will see System_class_root There are many System. Starting Progid , These Progid Of CLSID Of Inprocserver All Mscoree. dll In other words VB Script In the script Createobject When an object is called, Com Library passed Mscoree. dll Load CLR And then create System. Collections. arraylist Object and finally return VB ScriptProgram.

 

and msgbox OBJ (1) there are also xuanjicang. You must know that in the arraylist only Object type data can be saved, that is, obj. add (1) after the call is completed, arraylist the second element is a Object type, why msgbox OBJ (1) but it can be correctly displayed 1 ? the object type contains several functions, such as equals , gethashcode why other functions are not called, instead, what about calling the tostring function? This is because . net tostring function dispid set to zero, in com , dispid 0 is the default function.

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.