Vector class in VB6 - Unnecessary? 
Author Message
 Vector class in VB6 - Unnecessary?

Hello!

I want to port a project to VB6 which was originally written in C++.
The code makes use of a vector "class" (?), and I am not sure if I
really need to rewrite it in its full length.
As far as I understand, a vector in C++ is just like an array in VB6.

The code that I'm talking about is exactely this one stated here:
http://www.*-*-*.com/

I am still totally new to C++, so if anybody could tell me more about
this vector class and how to realize the same in VB6 I'd be really glad.
Maybe it's just a simple Dim b() as boolean or Dim s() as string?

Thank you for the help.
Reiner



Sun, 12 Feb 2012 17:44:44 GMT  
 Vector class in VB6 - Unnecessary?


Quote:
> Hello!

> I want to port a project to VB6 which was originally written in C++.
> The code makes use of a vector "class" (?), and I am not sure if I
> really need to rewrite it in its full length.
> As far as I understand, a vector in C++ is just like an array in VB6.

> The code that I'm talking about is exactely this one stated here:

http://listengine.tuxfamily.org/lists.tuxfamily.org/eigen/2009/01/msg...

Quote:

> I am still totally new to C++, so if anybody could tell me more about
> this vector class and how to realize the same in VB6 I'd be really glad.
> Maybe it's just a simple Dim b() as boolean or Dim s() as string?

> Thank you for the help.
> Reiner

Yes a "vector" object created from the STL is for all practical purpose the
same as a VB Array object. So your assumption is correct - converting a
vector is "just a simple Dim b() as Boolean or Dim s() as String".

C++ uses an additional container class library for "arrays" because in C
language itself there is no such thing as an Array object. There is only a
contiguous block of memory which can be managed by the programmer only
through conventions and diligence. (Such things as defining a 'string' as an
block of memory that ends with a nul-terminator. Making sure you don't
accidently run off the end. etc.) A vector class encapsulates this extra
work for programmer. In VB the object does this for you.

[A VB String is also an object, a BSTR.]

-ralph



Sun, 12 Feb 2012 19:35:12 GMT  
 Vector class in VB6 - Unnecessary?
It may be helpful to also note that you can replace a <list>, <map>, and
<deque> with a VB Container or with a Dictionary object from the Scripting
Runtime.

Unfortunately while functionally equivalent the implementation of the VB
Container is not what one might call optimal. It serves well in general
cases, but where you need to have a lighter object or better performance you
may need to seek out another replacement. There are several available on the
web.

hth
-ralph



Sun, 12 Feb 2012 20:00:10 GMT  
 Vector class in VB6 - Unnecessary?
Thank you for the reply, Ralph.
Just to be 100% sure... the code that I have posted a link to is indeed
such a vector class, isn't it?

Thank you,
Reiner



Sun, 12 Feb 2012 20:07:32 GMT  
 Vector class in VB6 - Unnecessary?


Quote:
> Thank you for the reply, Ralph.
> Just to be 100% sure... the code that I have posted a link to is indeed
> such a vector class, isn't it?

Yes, or rather a declaration of a vector 'class template' that can be used
to create a vector object.

The ANSI/ISO C++ 'standard' defines what should be in the C++ standard
library but it does not define implementation. That is up to the vendor of
each compiler. The 'standard' is to define the standard library as templates
(the STL), but there are many other C++ libraries out there. P.J. Plauger
has been the primary author of standard libraries for MS C/C++.

If you check-out the 'headers' section of your current C++ compiler you will
find code identical to this for all of the methods and classes defined in
the STL.

-ralph



Sun, 12 Feb 2012 20:43:39 GMT  
 Vector class in VB6 - Unnecessary?
Thank you, Ralph!


Sun, 12 Feb 2012 20:54:21 GMT  
 Vector class in VB6 - Unnecessary?


Quote:
> It may be helpful to also note that you can replace a <list>, <map>, and
> <deque> with a VB Container or with a Dictionary object from the Scripting
> Runtime.

> Unfortunately while functionally equivalent the implementation of the VB
> Container is not what one might call optimal. It serves well in general
> cases, but where you need to have a lighter object or better performance
you
> may need to seek out another replacement. There are several available on
the
> web.

Oops!

Said "VB Container", meant to say "VB Collection".

-ralph



Sun, 12 Feb 2012 21:45:49 GMT  
 Vector class in VB6 - Unnecessary?
To add to what others suggested, a "vector" is a dynamic array in C++. The
most important aspect of it rather than plain arrays(those like x[i]) is
that it calls the clean up code for any object contained in the dynamic
array. If one used a plain array, and an exception happened(run time error),
the clean up code is not called, and you have memory leak. This is one
reason why older versions of windows need to be rebooted after a while.

http://en.wikipedia.org/wiki/Vector_(C%2B%2B)

(Copy the link to the browser if you get a page not found error)



Sun, 12 Feb 2012 23:39:36 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. C++ Vector class for VB

2. Using Class Builder Utility to create a base class (VB6)

3. VB6 class module turns into regular module using VB6 IDE

4. Unnecessary message cant be turned off??

5. Unnecessary Instance of Word...

6. Unnecessary Save question when using templates in W2000

7. Microsoft.VisualBasic.DLL dependancy in unnecessary situations

8. HELP: Why those unnecessary click events

9. fear of DAO - unnecessary?

10. UnNecessary Beeping

11. HELP: Why those unnecessary click events

12. unnecessary files in VB4 setup's file list

 

 
Powered by phpBB® Forum Software