[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

VB6: Public UDT in a module or Private UDT in a form?

(Mike Mitchell)

8/2/2011 4:52:00 PM

Given that I have a user-defined type declared in a .bas module, is it
better to have

Public MyUDT As MyType in the module

or

Private MyUDT As MyType in a form?

The MyUDT is only referenced in the form.

I've tried both and there appears to be no difference.

MM
4 Answers

Jim Mack

8/2/2011 4:57:00 PM

0

MM wrote:
> Given that I have a user-defined type declared in a .bas module, is
> it better to have
>
> Public MyUDT As MyType in the module
>
> or
>
> Private MyUDT As MyType in a form?
>
> The MyUDT is only referenced in the form.
>
> I've tried both and there appears to be no difference.

It may make a difference if you intend to use tlbinf32.dll. Private
objects are not part of the public contract.

--
Jim

(Mike Mitchell)

8/2/2011 5:59:00 PM

0

On Tue, 2 Aug 2011 12:57:08 -0400, "Jim Mack" <no-uce-ube@mdxi.com>
wrote:

>MM wrote:
>> Given that I have a user-defined type declared in a .bas module, is
>> it better to have
>>
>> Public MyUDT As MyType in the module
>>
>> or
>>
>> Private MyUDT As MyType in a form?
>>
>> The MyUDT is only referenced in the form.
>>
>> I've tried both and there appears to be no difference.
>
>It may make a difference if you intend to use tlbinf32.dll. Private
>objects are not part of the public contract.

But from a 'purist' POV, is there any ~convention~? Isn't it better to
assign variables as little scope as possible? I'm trying to think
'classy' here (!) and not modular.

What gave me the idea to move the declaration to the form was that it
was nonsensical calling the QuickSort proc and passing the UDT array
when this was global. (The QuickSort proc resides in a module, along
with other 'helper' procs/functions.)

MM

Jim Mack

8/2/2011 6:33:00 PM

0

MM wrote:
> Jim Mack wrote:
>>
>> It may make a difference if you intend to use tlbinf32.dll. Private
>> objects are not part of the public contract.
>
> But from a 'purist' POV, is there any ~convention~? Isn't it better
> to assign variables as little scope as possible? I'm trying to think
> 'classy' here (!) and not modular.

Yes, 'best practice' says that variables should have minimum scope.

But there are two parts to that -- the definition of the Type and the
declaration of the variable. If both have only Form scope, you won't
be able to pass the variable outside the form as a parameter. The
definition must be in the scope of all items that will deal with
variables of that Type (IOW it must be Public, defined in a module).

>
> What gave me the idea to move the declaration to the form was that
> it was nonsensical calling the QuickSort proc and passing the UDT
> array when this was global. (The QuickSort proc resides in a
> module, along with other 'helper' procs/functions.)

Then the Type definition must be Public in a module. Variables of that
type can (and 'should', per convention) be private to the caller.

--
Jim

ralph

8/3/2011 2:28:00 PM

0

On Tue, 02 Aug 2011 18:58:46 +0100, MM <kylix_is@yahoo.co.uk> wrote:

>On Tue, 2 Aug 2011 12:57:08 -0400, "Jim Mack" <no-uce-ube@mdxi.com>
>wrote:
>
>>MM wrote:
>>> Given that I have a user-defined type declared in a .bas module, is
>>> it better to have
>>>
>>> Public MyUDT As MyType in the module
>>>
>>> or
>>>
>>> Private MyUDT As MyType in a form?
>>>
>>> The MyUDT is only referenced in the form.
>>>
>>> I've tried both and there appears to be no difference.
>>
>>It may make a difference if you intend to use tlbinf32.dll. Private
>>objects are not part of the public contract.
>
>But from a 'purist' POV, is there any ~convention~? Isn't it better to
>assign variables as little scope as possible? I'm trying to think
>'classy' here (!) and not modular.
>
>What gave me the idea to move the declaration to the form was that it
>was nonsensical calling the QuickSort proc and passing the UDT array
>when this was global. (The QuickSort proc resides in a module, along
>with other 'helper' procs/functions.)
>

This too has been beaten to death, if you have several UDTs that are a
critical part of your Application it is best to create a project type
library and declare them there. For a one-time store, probably not. (I
do it for All UDTs, but that"s just me. <g>)

UDTs usually package something of business interest and these things
have a habit of multiplying or rather expanding outside the initial
design, or to other projects/components. Having a single 'spot' of
declaration that can be used in any context is useful.

Once declared in a Type Library you can set it and forget it.

-ralph