Click to See Complete Forum and Search --> : Using Flags
Compwiz
Nov 16th, 1999, 09:07 AM
Is there an easier way to retrieve what flags a user specifies in a function other than a bunch of IF, ELSEIF, THEN or CASE statements?
I mean this:
Call MyFunction(FLAG1 Or FLAG2 Or FLAG3)
Did I explain this enough? If not, please reply, well then again, reply anyway).
------------------
Tom Young, 14 Year Old
tyoung@stny.rr.com
ICQ: 15743470 (http://wwp.icq.com/15743470) Add Me (http://wwp.icq.com/scripts/search.dll?to=15743470) ICQ Me (http://wwp.icq.com/scripts/contact.dll?msgto=15743470)
AIM: TomY10 (http://www.aol.com/aim/aim30.html)
PERL, JavaScript and VB Programmer
Juan Carlos Rey
Nov 16th, 1999, 09:45 AM
What?
"Did I explain this enough? If not, please reply, well then again, reply anyway)."
Select Case "I explain this enough"
Case Yes
Please.Reply
Case No
Please.Reply Also
Case Else
Please.Reply AnyWay
End Select
(Just Kidding)
Please, Clarify your question...
[This message has been edited by Juan Carlos Rey (edited 11-16-1999).]
MartinLiss
Nov 16th, 1999, 09:36 PM
I'm guessing that what you want to do is to be easily able to determine if the value sent in the function is one of a set of values. If so, here is one way to do it.
'In a form or a module, define a collection. (It would
' need to be Public in a module)
Private MyCollection As New Collection
'---------
' Then add the set of values to the collection.
' The first string is the collection's item value
' and the second is its index
MyCollection.Add "one", "one"
MyCollection.Add "two", "two"
MyCollection.Add "three", "three"
MyCollection.Add "two-hundred", "two-hundred"
'-----------
' Then to determine if the sent value is one that
' you expect, do the following
Public Function MyFunction(sValue As String)
Dim sDummy As String
Dim bFound As Boolean
On Error Resume Next
'If sValue is in the collection, Err = 0, otherwise it's not
sDummy = MyCollection.Item(sValue)
bFound = (Err = 0)
If bFound Then
Err.Clear
MsgBox "This value is in my collection"
Else
MsgBox "This value isn't"
End If
End Function
------------------
Marty
[This message has been edited by MartinLiss (edited 11-17-1999).]
Yonatan
Nov 16th, 1999, 10:10 PM
Try this:
Option Explicit
Private Const FLAG1 = &H1
Private Const FLAG2 = &H2
Private Const FLAG3 = &H4
Function MyFunction(ByVal Flags As Long)
Dim FlagIsSet(1 To 3) As Boolean
FlagIsSet(1) = ((Flags And FLAG1) = FLAG1)
FlagIsSet(2) = ((Flags And FLAG2) = FLAG2)
FlagIsSet(3) = ((Flags And FLAG3) = FLAG3)
If FlagIsSet(1) Then Debug.Print "FLAG1 is set."
If FlagIsSet(2) Then Debug.Print "FLAG2 is set."
If FlagIsSet(3) Then Debug.Print "FLAG3 is set."
End Function
------------------
Yonatan
Teenage Programmer
E-Mail: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)
AIM: RYoni69
Compwiz
Nov 17th, 1999, 02:44 AM
Thanks Yonatan! Exactly what I was looking for.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.