Solved

Predefined values as arguement

Posted on 2002-03-24
2
260 Views
Last Modified: 2010-05-02
Here's my question...I have a function in a class that accepts a string argument.  I want to predefine the possible values that can be passed as this arguement.  Let's use colors as an example.

Public Function DoSomething(ByVal strColor As String) as String

Select Case strColor
   Case "red"
      ' Code here
   Case "blue"
      ' Code here
   Case "green"
      ' Code here
End Select

End Function

Given that code, how can I force the object calling this method to select from a list of red, blue, and green.  It seems like I should be able to create a collection of colors and declare the argument as my collection but that didn't work.  Seems like this should be easy enough.
0
Comment
Question by:jayh
2 Comments
 
LVL 1

Accepted Solution

by:
Ryan_231 earned 200 total points
ID: 6892611
use an enum

Public Enum Color
  Red = 1
  Blue = 2
  Green = 3
End Enum

then in your function

Public Funtion DoSomething(c as Color) As String
  Select Case c
    case is = Red
     'code
    case is = Blue
     'do something
  End Select

  or you can do this

  Select Case c
    case is = 1
     'code for red
    case is = 2
      'code for blue
  End Select
End function

note when you call the function you will have to do it like this

Dim myColor AS Color
myColor = Red
call DoSomething(myColor)
0
 

Author Comment

by:jayh
ID: 6893112
Thanks, I knew it was something simple but I just couldn't remember what it was.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Write data from SQL to CSV file - position 1 52
VBA saving file message display 5 56
Passing a Text Box name to a Sub 6 75
how to know if my Checkbox is True in VB6.0? 9 40
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now