Results 1 to 4 of 4
  1. #1
    maxbre is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    38

    optional features for UDF (Enum problem?)

    thanks to the help of a member of this great forum
    (https://www.accessforums.net/program...ray-18818.html)
    I had this more than welcomed gift: two user defind function to get files name present in a given dir;
    '---------------------------------------------------------------------------------------------------------------
    Public Function GetFiles(colDirList As Collection, ByVal FilePath As String, FileName As String) As Boolean

    Dim strTemp As String
    Dim colFolders As New Collection

    FilePath = TrailingSlash(FilePath)

    'returns the file name
    strTemp = dir(FilePath & FileName)

    Do While strTemp <> vbNullString

    ' adds the items to the collection colDirList
    ' two options available here


    colDirList.Add FilePath & strTemp 'path and file name
    colDirList.Add strTemp 'just the file name

    strTemp = dir

    Loop

    End Function


    Public Function TrailingSlash(FilePath As Variant) As String

    If Len(FilePath) > 0& Then
    If Right(FilePath, 1&) = "\" Then
    TrailingSlash = FilePath
    Else
    TrailingSlash = FilePath & "\"
    End If
    End If
    End Function
    '---------------------------------------------------------------------------------------------------------------
    now, I would like to generalise the function GetFiles in order to have two optional features: i.e. listing files with or without the indication of the path (at choice);

    to accomplish that I think it has something to do with the declaration Enum.
    In other words something like:

    Public Enum....
    Option1 ...
    Option2...
    End Enum

    I've been "googled" the web, searched this forum, and read the on-line help but I could not find a proper solution (unless I'm not pointing to the wrong direction)

    any help for this?

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    you don't have to do anything with an enumeration. an enum is nothing more than an "indexing loop". you probably just need to extract the right side of the file path using RIGHT() and searching for the first "\" in the string using INSTRREV().

  3. #3
    maxbre is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Oct 2010
    Posts
    38
    thanks for your reply but it's not about a problem of extracting just the file name rather than to keep the two options (file name or path and file name) both available within the same function (without the the need to define one function for each feature)

    in fact it's about selecting one of the two following lines within the given function

    colDirList.Add FilePath & strTemp 'path and file name
    colDirList.Add strTemp 'just the file name

    in other words, I need to tell to the function which is the option I'm choosing;
    it may be just simply passing an optional parameter to the function itself, but I can't figure how properly do it...

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Why not add another parameter to the function?
    PathRequired as Variant
    if True return the Full path and Filename
    if False return only the Filename

    You could set it up as with a default in case no value is supplied.


    see http://allenbrowne.com/ser-30.html

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Features Left in or out of 2010
    By Paul H in forum Access
    Replies: 7
    Last Post: 11-08-2011, 12:57 PM
  2. multiple optional criteria
    By TheShabz in forum Programming
    Replies: 7
    Last Post: 07-05-2011, 05:13 PM
  3. Removing access features
    By GraemeG in forum Programming
    Replies: 1
    Last Post: 03-10-2011, 11:12 AM
  4. convert property TYPE to ENUM
    By ajetrumpet in forum Programming
    Replies: 4
    Last Post: 09-10-2010, 11:09 AM
  5. Skipping optional arguments
    By canfish in forum Programming
    Replies: 3
    Last Post: 08-19-2010, 01:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums