Charlotte Foust
cfoust at infostatsystems.com
Tue Feb 24 15:21:02 CST 2009
Not sure I follow, Stuart. Subs set values like Cancel or process a keycode. They don't return them per se. Charlotte Foust -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart McLachlan Sent: Tuesday, February 24, 2009 1:12 PM To: Access Developers discussion and problem solving Subject: Re: [AccessD] Function vs Sub (was: Classes and Events - EVENTSNOTREQUIRED) Which begs the question, why does VBA use Subs for event procedures which return values such as Cancel or KeyCode? Aren't these Functions? :-) -- Stuart On 24 Feb 2009 at 9:24, Charlotte Foust wrote: > Absolutely when you need multiple return values, but a simple boolean or > single value? > > Charlotte Foust > > -----Original Message----- > From: accessd-bounces at databaseadvisors.com > [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav Brock > Sent: Tuesday, February 24, 2009 1:45 AM > To: accessd at databaseadvisors.com > Subject: Re: [AccessD] Function vs Sub (was: Classes and Events - EVENTS > NOTREQUIRED) > > Hi Charlotte > > Not tidy? In some cases this feature is very useful. > Here is a simple example of sub returning multiple values: > > <code> > Public Sub CompositeRGB( _ > ByVal lngRGB As Long, _ > ByRef intRed As Integer, _ > ByRef intGreen As Integer, _ > ByRef intBlue As Integer) > > ' Calculate discrete RGB colours from composite colour Value. > ' > ' 1999-08-20. Cactus Data ApS, CPH > > If lngRGB < 0 Then > ' Nothing to do. > intRed = 0 > intGreen = 0 > intBlue = 0 > Else > ' Dissolve composite RGB into discrete colours. > intRed = lngRGB And vbRed > intGreen = (lngRGB And vbGreen) / &H100 > intBlue = (lngRGB And vbBlue) / &H10000 > End If > Debug.Print intRed, intGreen, intBlue > End Sub > > </code> > > The only reason I see to not write a sub when a return value is not > needed, is if the (sub)function will be used in a macro as these can't > call subfunctions. > > /gustav > > > >>> cfoust at infostatsystems.com 24-02-2009 01:14 >>> > I didn't say functions HAD to return a value, just that you had to have > a function in order to return the value in this case. Actually, using > ByRef for arguments passed into a sub allows you to get values back too, > but it isn't as tidy. > > Charlotte Foust > > > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com > > -- > AccessD mailing list > AccessD at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/accessd > Website: http://www.databaseadvisors.com -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com