Go deep into scripting Runtime Library 2

Source: Internet
Author: User

Go deep into scripting Runtime Library 2

Www.applevb.com

The last time I introduced how to use the scripting Runtime Library to obtain drive information and perform operations on folders and files.
Method. Here we will introduce the scripting Runtime Library, which is an inconspicuous but useful object-dictionary object.
In VB, if you want to implement a one-to-one list of symptom dictionaries and perform queries, for example, to implement a one-to-one correspondence between student Student IDs and student names, enter
Student ID to get the Student name. What methods will you use? The general method is to create two lists in two columns respectively.
Enter the Student name and student ID in the table. When querying, first query the student ID that matches the student ID in the student ID list, and then bring up the corresponding student name list.
Name. However, this increases the programming volume and is not easy to maintain. Some readers may think of using the database, but it seems that
In addition, Database Calling has a great impact on the program size and running speed. Here I want to introduce the usage
The dictionary object in the scripting Runtime Library implements the dictionary function.
The following describes how to use a dictionary object through a program.
Create a new project file, add a ListBox control and a Textbox Control to form1, and then in the code window of form1
Add the following code:
Dim dictemp as new scripting. Dictionary

Private sub form_load ()
List1.additem "apple"
List1.additem "banana"
List1.additem "grape"
List1.additem "orange"
List1.additem "strawberry"

Dictemp. Add "apple", "apple"
Dictemp. Add "orange", "citrus"
Dictemp. Add "banana", "banana"
Dictemp. Add "grape", "grape"
Dictemp. Add "strawberry", "strawberry"
Text1.text = ""
End sub

Private sub form_unload (cancel as integer)
Dictemp. removeall
Set dictemp = nothing
End sub

Private sub listmediaclick ()
Dim astr as string

Astr = list1.list (list1.listindex)

Text1.text = dictemp. Item (astr)
End sub

Private sub listdomaindblclick ()
Dim astr as string

Text1.text = ""
Astr = list1.list (list1.listindex)
List1.removeitem (list1.listindex)
Dictemp. Remove (astr)
End sub

Run the program and click the project in list1. The corresponding Chinese explanation will appear in the middle of text1.
The above program is very simple, but this dictionary object has many advantages:
First, this is an object, which makes the program readable and maintainability very good. At the same time, its operation is also very simple, using the additem Method
You can add a project with a keyword. By using the item attribute, you can return a project with a corresponding keyword. You can delete the project with the Remove Method.
A project.

Related Article

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.