Home > Software engineering >  VB on the global structure of the variable declared in a class problem
VB on the global structure of the variable declared in a class problem

Time:09-16

I use class is not much, no experience, problems as follows

Have a car at the moment, for example, a type of car, license plate, production date... Attribute

I declared in the module structure types, and defines the global structure variable
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Private type tCar
CarType as string
CarID as string
End type

Public Car as tCar
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
There is no question of above,
In other forms call no problem
Such as: Car type="mercedes-benz"
================================
But now I don't want to do with the module, I think he is defined as a class
I add a blank class and named cls_Car
In the class wrote
Private type tCar
CarType as string
CarID as string
End type

Public Car as tCar 'began to complain here
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Compile all compiled not the past, he suggests the public global declarations can't use a custom type · · · · · · ·

Why is this? Please explain to me why, as carefully as possible, I want to learn,
==========================================
Here's what I try to use other methods
In the class wrote
Public CarType as string
Public CarID as string
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
In other forms, the
Dim the Car as New cls_Car

Car. Cartype="mercedes-benz"
It is possible, as I understand the class,
========================================
There is a problem believe that class above declared in the global structure of the problem is resolved
This sure is settled, they two error as the nature of the
If at the moment the people sitting on the bus, so name, gender... is he wants some attribute
I wrote in the cls_Car
Private type tPerson
The Name as string
Sex as a Boolean
End type

Private type tCar
CarType as string
CarID as string
The number of the Person (s) as tPerson 'uncertain, so the definition of dynamic array
End type

Public Car as tCar
'want to achieve the purpose of the above is my final, but did not compile the past
=================================

CodePudding user response:

My solution is: change the type to the class and type members into a class member.

CodePudding user response:

reference 1st floor milaoshu1020 response:
my solution is: change the type to type, type members into a class member.


Put it that way, that was built many classes,
This is not the key, the key is dynamic class of building, the number of passengers such as uncertainty,

CodePudding user response:

refer to the second floor weixin_44603568 response:
Quote: refer to 1st floor milaoshu1020 response:

My solution is: change the type to the class and type members into a class member.


Put it that way, that was built many classes,
This is not the key, the key is dynamic class of building, the number of passengers such as uncertainty,


More than 1. The class does not matter, as long as you are diligent;
2. Not sure number can use the collection.
Private Person as the New Collection
It's weak type not only can let the Person class of objects, also can put object of other classes;
Or create a Collection class:
Private colPerson as new PersonCollection.
PersonCollection inside class reloading a Collection of properties and methods, such as the add method using strongly typed parameters at the entrance.
Can also be.

at the entrance

CodePudding user response:

Collection classes can refer to this article, NewEnum methods need to be in the menu to find the method of attribute, and modify the method ID.
https://www.cnblogs.com/ayanmw/archive/2012/07/03/2575000.html
  • Related