Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Visual Basic (Classic) FAQ


How To: Restrict values passed to a function, procedure or a property. by PankajBanga
Posted: 6 Jul 04

Sometime we have to restrict the values passed into a function, procedure or a property. A common practice is to validate values inside the code. For instance the following procedure accepts marital status of a customer, checks for valid marital status and displays it in a message box.

Public Sub GetMaritalStatus(ByVal mStatus As String)
        If mStatus = "Defacto" Then
        ElseIf mStatus = "Divorced" Then
        ElseIf mStatus = "Married" Then
        ElseIf mStatus = "Separated" Then
        ElseIf mStatus = "Single" Then
            MessageBox.Show("Invalid marital status.")
        End If
End Sub

This is a simple example where I had to check only five conditions. Imagine having multiple data values, which becomes a sluggish, time consuming process involving heap of IF blocks. There is an alternative, which makes the process more efficient and regarded as a good programming practice, it is using Enumeration:

Enum MaritalStatus
End Enum

Now all you have to do is declare your argument as type MaritalStatus:

Public Sub GetMaritalStatus(ByVal mStatus As MaritalStatus)

End Sub

Enumeration is basically a type which can hold a set of values. In .NET Framework Enumeration can be of any type except Char. If no underlying type is explicitly declared, Int32 is used.

For more information on Enumeration visit the following link:

Happy Programming!!!

Back to Visual Basic (Classic) FAQ Index
Back to Visual Basic (Classic) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close