Results 1 to 5 of 5

Thread: Using Flags

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    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
    [email protected]
    ICQ: 15743470 Add Me ICQ Me
    AIM: TomY10
    PERL, JavaScript and VB Programmer

  2. #2
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301

    Post

    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).]

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    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.
    Code:
    '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).]

  4. #4
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Try this:

    Code:
    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: [email protected]
    ICQ: 19552879
    AIM: RYoni69

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 1999
    Location
    NY, USA
    Posts
    270

    Post

    Thanks Yonatan! Exactly what I was looking for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width