rbali2004
asked on
How to create object variables in VB6
Hi,
I have a question. What is the difference b/w the folliwng two syntaxes. I have a dll project named sortClass that contains a class called sortFuncs. When i add a reference to the class in vb6, i can use the following 2 syntaxes to create an object of that class. However, what is the difference between the two?
dim myobj1 as new sortfuncs
dim myobj1 as new sortClass.sortFuncs
MY second question is that while reading a vb .NET book I noticed that there were certain variables that were declared without the NEW keyword and certain had the new keyword. For example,
Dim myarraylist as arraylist
While in another example, an arraylist was declared as
Dim myarraylist as new arraylist
Isthere any difference?
Thanks
Rafay
I have a question. What is the difference b/w the folliwng two syntaxes. I have a dll project named sortClass that contains a class called sortFuncs. When i add a reference to the class in vb6, i can use the following 2 syntaxes to create an object of that class. However, what is the difference between the two?
dim myobj1 as new sortfuncs
dim myobj1 as new sortClass.sortFuncs
MY second question is that while reading a vb .NET book I noticed that there were certain variables that were declared without the NEW keyword and certain had the new keyword. For example,
Dim myarraylist as arraylist
While in another example, an arraylist was declared as
Dim myarraylist as new arraylist
Isthere any difference?
Thanks
Rafay
>> Dim myArrayList As ArrayList
myArrayList has been declared to be of type ArrayList, but has not yet been instantiated. Therefore, you cannot perform any actions on myArrayList yet. It is just a placeholder that can (but does not yet) point to an ArrayList in memory.
>> Dim myArrayList As New ArrayList
myArrayList has been declared to be of type ArrayList and now points to an instance of ArrayList in memory. You may immediately perform actions on myArrayList. A more formal declaration would look like this:
Dim myArrayList As ArrayList = New ArrayList
Some prefer to see it on two lines like this:
Dim myArrayList As ArrayList
myArrayList = New ArrayList
Regards,
Idle_Mind
myArrayList has been declared to be of type ArrayList, but has not yet been instantiated. Therefore, you cannot perform any actions on myArrayList yet. It is just a placeholder that can (but does not yet) point to an ArrayList in memory.
>> Dim myArrayList As New ArrayList
myArrayList has been declared to be of type ArrayList and now points to an instance of ArrayList in memory. You may immediately perform actions on myArrayList. A more formal declaration would look like this:
Dim myArrayList As ArrayList = New ArrayList
Some prefer to see it on two lines like this:
Dim myArrayList As ArrayList
myArrayList = New ArrayList
Regards,
Idle_Mind
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
dim myobj1 as new sortClass.sortFuncs
The class functions can be accessed only thorugh the respective class,if the class is not available in the same project. If the class is available in the same project then it acts like a global function.
Object variables can be used only if it is referenced with a New keyword.