Named Arguments: How Do I create (1 Viewer)

Randomblink

The Irreverent Reverend
Local time
Yesterday, 19:16
Joined
Jul 23, 2001
Messages
279
When you put a MsgBox in code, you start typing...

MsgBox "<insert Prompt Here>",------

as soon as you enter that last comma (like above) a little window pops down...
This window lists out ALL the different types of MsgBoxes you can generate...
VBOk
vbCritical
etc...

How do I set up a function to list similar out...?

For instance...
If I create a paint function to, let's say, paint the BackColor of objects...How could I set it so that...

as I call the function like this...

Paint (FieldName, ----

That after hitting the second comma a list of colors pops down...
Then after selecting a color from the list is paints the back color to that color...?

Here is an example code to hopefully better explain...

Public Function Paint (fld As Control, clr As NamedArgument?)
fld.BackColor = clr
End Function

What code would I enter to finish this Function to give it named arguments...

OH, and I might be mis-using the words Named Arguments...
So if this is called something else, please enlighten me...

I have never been taught VB, I just learned it on my own...
Thanks!
 

SteveA

Registered User.
Local time
Today, 10:16
Joined
Oct 8, 2001
Messages
126
If you are using Access 2000, you can define an Enum in the top of a Module such as follows:

Code:
Public Enum InterfaceColors
    icMistyRose = &HE1E4FF
    icSlateGray = &H908070
    icDodgerBlue = &HFF901E
    icDeepSkyBlue = &HFFBF00
    icSpringGreen = &H7FFF00
    icForestGreen = &H228B22
    icGoldenrod = &H20A5DA
    icFirebrick = &H2222B2
End Enum

Then, when you declare your function simply refer to the Enum as your datatype ie:

Code:
Function Test(a as InterfaceColors).

Anytime you call the function Test, a drop down list will appear with the values of icMistyRose, icSlateGrate etc.

I don't think this is supported in earlier version of Access.

Cheers,
SteveA :)
 

Randomblink

The Irreverent Reverend
Local time
Yesterday, 19:16
Joined
Jul 23, 2001
Messages
279
Enum just NOT a number?

Ok...

I get Type problems when I try to:

Public Enum Names
nmJohn = "John Jacob Jingleheimersmith"
nmSteve = "Steven Samuel Sliczensky"
nmRoberto = "Robert Timothy Randern"
End Enum

Public Function UserDetail(username as Names)
Select Case username
Case nmJohn
' Find the Current Salary for John
Case nmSteve
' Find the Current Salary for Steve
...etc...
End Function

Private Sub <insert name here>()
CurrentSalary = UserDetail(nmJohn)
CurrentSalary = CurrentSalary + Raise

...you get the idea right?...
End Sub

What can I do?
Can anyone help me?

(heck, would learning how to build dll files be the way to go?)
 
Last edited:

SteveA

Registered User.
Local time
Today, 10:16
Joined
Oct 8, 2001
Messages
126
Each value in an enum list contains two parts. These are membername and constantexpression.

Membername is the value you want to see in the drop down box.
constantexpression is an option value (of datatype long) that represents the true value of your enum (ie you might use the customer number associated with each customer on your books)

If you don't use the constantexpression, a number is automatically allocated behind the scenes. For the first entry, this number will be zero, for all subsequent entries it will be one greater than the number for the previous entry in the enum list.

I hope this helps.

SteveA :)
 

Users who are viewing this thread

Top Bottom