"Step-by-step learning VBA" to create a user-defined class or a custom type

Source: Internet
Author: User
Different types of variables can be combined to create user-defined types (such as structs in the well-known C programming language). User-defined types are useful when you need to create a single variable to record multiple related information.


You can create a user-defined type with the type statement, which must be placed in the Declarations section of the module. User-defined types can be declared as Private or public with the appropriate keywords, for example:


Private Type Mydatatype
Or


Public Type Mydatatype


For example, you can create a user-defined type that records information about a computer system:


' Declaration (a standard module).
Private Type SystemInfo
CPU as Variant
Memory as Long
Videocolors as Integer
Cost as Currency
Purchasedate as Variant
End Type


Declaring a variable of a user-defined type
For the same user-defined type, it can be declared as a local, private, or common module-level variable:


Dim Mysystem as SystemInfo, Yoursystem as SystemInfo


Reference article: click

"Step-by-step learning VBA" to create a user-defined class or a custom type

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.