[AccessD] VBA Function with parameters
Bill Benson
bensonforums at gmail.com
Tue Nov 9 00:57:14 CST 2021
If you pass any to functions let me know how it goes. I have been trying to
figure out what I was doing wrong but I lost Intellisense within functions
even though the enum declared punlic.
Also, when I would use the enum and type in lower case it changes the case
everywhere including the enum declarations.
On Sun, Nov 7, 2021 at 5:05 PM Borge Hansen <pcs.accessd at gmail.com> wrote:
> Thanks Paul and Stewart,
> Enum is great...
> Stewart’s example got me googling …
>
> Link here explains what Enum is in the VBA world:
> http://www.cpearson.com/excel/Enums.aspx
>
> With
> +++++++++++
> Enum CarMakes
> Ford = 1
> Toyota = 2
> Suzuki = 4
> End Enum
>
> Function SHowCar(cm As CarMakes) As Long
> Dim s As String
> If cm And 1 Then s = "Ford "
> If cm And 2 Then s = s & "Toyota "
> If cm And 4 Then s = s & "Suzuki"
> MsgBox s
> End Function
> ++++++++++++
>
> I do understand that if I do
> ShowCar(7) I get all three cars in the message box
> If I do ShowCar(6) I get Toyota Suzuki
> If I do random number I get for example:
> 8 - none
> 9 - Ford
> 10 - Toyota
> ahah! pattern here 9-8=1 - hence Ford
> 11 - Ford Toyota 11-8 =3 - hence Ford Toyota
> 12 - Suzuki
> 13 - Ford Suzuki
> and yes
> 14 - Toyota Suzuki
> wait..
> 15 - Ford Toyota Suzuki
> 16 - none
> etc etc
>
> So what is behind an expression like this?
> If cm And x ??
> Bitwise enumeration …
>
> To get my head around the ‘And’ bitwise operator, I found this link which
> explains bitwise operators in the C# world:
> https://www.alanzucconi.com/2015/07/26/enum-flags-and-bitwise-operators/
>
> To avoid crazy enum parameters - link above - , we can do:
>
> Enum CarMakes
> [_First] = 1
> Ford = 1
> Toyota = 2
> Suzuki = 4
> [_Last] = 4
> End Enum
>
> I know most of you are well versed with all of this.
> I am posting this thinking it might be helpful for someone else wondering
> what is behind the "addition" of enum parameters set up as powers of two.
>
> /borge
>
>
>
>
>
>
> On Fri, Nov 5, 2021 at 4:08 PM Stuart McLachlan <stuart at lexacorp.com.pg>
> wrote:
> >
> > Or even:
> >
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
More information about the AccessD
mailing list