K
K
khru-khru2016-06-03 11:05:25
OOP
khru-khru, 2016-06-03 11:05:25

How to create a new object in Visual basic 6.0?

There is a code:

Public Sub Tick()
    ...
    For Each Link In NLinks
       Dim NextP As New NPackets
   ...

The problem is that, as planned, Dim NextPacket As New NetworkPackets creates a new instance of the class N (but this is of course not the case), then its properties change and it is added to the collection (with a reference to this same object), then at the next iteration, a new object is created and added to the collection (in fact, on the next iteration in foreach, the code refers to the same object that was previously placed in the collection).
dim is not a statement, a new object will not be created each time the next iteration of the loop inside this method's code begins.
How can objects be created without using a separate method to create the object?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom Karetnikov, 2016-06-03
@art_karetnikov

vb6 is still alive? :)
From memory:
Dim NextP As NPackets
...
For Each Link In NLinks
set NextP = New Npackets
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question