[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

microsoft.public.vb.general.discussion

How to code optional stuff

BillyJ

6/11/2016 9:37:00 PM

There seems to be no way to code the following.

I do not include using #IF ... as what I want to use, knowing that I
could do this as a last resort.

So I am trying to make a general purpose module (can be used in all my
apps) that has a routine like this:

m_eInfoType is set in a previous routine to steer the following.

<air code>
Public Sub Message(sMsg as String)

Select Case m_eInfoType
Case eInfoLog
cLog.InfoLog sMsg

Case eInfoLogFLash
cLogFlash.InfoLog sMsg

Case ...

Case Else
End Select

End Sub

Either cLogFlash or cLog is instantiated, but not both.
Only one m_eInfoType will be called withing an application.

So all will complain unless I can make the lack of one of these be ignored.

Normally the cLog or cLogFlash is Dim-ed in the mdlMain Sub Main()
(startup).

But the cLog or cLogFlash is instantiated in the main Form since
WithEvents is required.

Possibly one solution is to Dim the not used cLog or cLogFlash to
something? But what would be appropriate?

Public cLog as Object

Will that work or cause unforeseen problems?

Any better way to do this?

4 Answers

Henning

6/12/2016 12:08:00 AM

0


"BillyJ" <BJ@Spamless.com> skrev i meddelandet
news:nji090$17em$1@gioia.aioe.org...
> There seems to be no way to code the following.
>
> I do not include using #IF ... as what I want to use, knowing that I could
> do this as a last resort.
>
> So I am trying to make a general purpose module (can be used in all my
> apps) that has a routine like this:
>
> m_eInfoType is set in a previous routine to steer the following.
>
> <air code>
> Public Sub Message(sMsg as String)
>
> Select Case m_eInfoType
> Case eInfoLog
> cLog.InfoLog sMsg
>
> Case eInfoLogFLash
> cLogFlash.InfoLog sMsg
>
> Case ...
>
> Case Else
> End Select
>
> End Sub
>
> Either cLogFlash or cLog is instantiated, but not both.
> Only one m_eInfoType will be called withing an application.
>
> So all will complain unless I can make the lack of one of these be
> ignored.
>
> Normally the cLog or cLogFlash is Dim-ed in the mdlMain Sub Main()
> (startup).
>
> But the cLog or cLogFlash is instantiated in the main Form since
> WithEvents is required.
>
> Possibly one solution is to Dim the not used cLog or cLogFlash to
> something? But what would be appropriate?
>
> Public cLog as Object
>
> Will that work or cause unforeseen problems?
>
> Any better way to do this?
>

How do you make it general purpose if you don't have routines for both?
The one not called will not cause any problems.

/Henning


Ulrich Korndoerfer

6/12/2016 2:09:00 AM

0

Hi,

BillyJ schrieb:
> There seems to be no way to code the following.
>
> I do not include using #IF ... as what I want to use, knowing that I
> could do this as a last resort.
>
> So I am trying to make a general purpose module (can be used in all my
> apps) that has a routine like this:
>
> m_eInfoType is set in a previous routine to steer the following.
>
> <air code>
> Public Sub Message(sMsg as String)
>
> Select Case m_eInfoType
> Case eInfoLog
> cLog.InfoLog sMsg
>
> Case eInfoLogFLash
> cLogFlash.InfoLog sMsg
>
> Case ...
>
> Case Else
> End Select
>
> End Sub
>
> Either cLogFlash or cLog is instantiated, but not both.
> Only one m_eInfoType will be called withing an application.
>
> So all will complain unless I can make the lack of one of these be ignored.
>
> Normally the cLog or cLogFlash is Dim-ed in the mdlMain Sub Main()
> (startup).
>
> But the cLog or cLogFlash is instantiated in the main Form since
> WithEvents is required.
>
> Possibly one solution is to Dim the not used cLog or cLogFlash to
> something? But what would be appropriate?
>
> Public cLog as Object
>
> Will that work or cause unforeseen problems?
>
> Any better way to do this?
>

Use interfaces. Create an interface class cLogInterface for logging with
a method InfoLog and then implement this interface in cLog and
cLogFlash. Then at program start instantiate either a cLog or CLogFlash
and save its pointer in a var of type cLogInterface. Then the switch
can be omitted too.

--
Ulrich Korndoerfer

VB tips, helpers, solutions -> http://www.prosource.de/...
MS Newsgruppen Alternativen -> http://www.prosource.de/ms-ng-...

Deanna Earley

6/12/2016 6:16:00 PM

0

On 11/06/2016 22:36, BillyJ wrote:
> There seems to be no way to code the following.
>
> I do not include using #IF ... as what I want to use, knowing that I
> could do this as a last resort.
>
> So I am trying to make a general purpose module (can be used in all my
> apps) that has a routine like this:

This is one of the key uses of the conditional compilation, especially
if it's per app. Set the conditional in the compile settings then
everything else will follow suit.

--
Deanna Earley (dee@earlsoft.co.uk, dee@doesnotcompute.co.uk)

(Replies direct to my email address will be printed, shredded then fed
to the dragons. Please reply to the group.)

Arne Saknussemm

6/16/2016 8:25:00 AM

0

On Sun, 12 Jun 2016 04:08:50 +0200
"Ulrich Korndoerfer" wrote in microsoft.public.vb.general.discussion
<ds3ui2F9rp9U1@mid.individual.net>:

> Use interfaces. Create an interface class cLogInterface for logging
> with a method InfoLog and then implement this interface in cLog and
> cLogFlash. Then at program start instantiate either a cLog or
> CLogFlash and save its pointer in a var of type cLogInterface. Then
> the switch can be omitted too.

Agreed 100%, I was about writing the same thing; this is a *perfect*
example of the use of such a VB OOP feature which is often forgotten

Another possible approach may be the following

Create a new "logger" project of type ActiveX DLL

Add to the main class module all the desired properties, methods and
events, include a property to allow setting the logging type

Add a couple private classes wrapping the two logging methods code,
those classes won't be exposed to the outside but only available inside
the "logger" object

Build the DLL

now, in the the main project set a reference to the "logger", instance
it, set the logging method and use it for whatever logging purpose,
this way you'll have a single object which will adapt itself to the
caller needs