Solved

Predefined values as arguement

Posted on 2002-03-24
2
262 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

820 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