Results 1 to 7 of 7

Thread: (Help) Dir Function in Module..

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Philippines
    Posts
    36

    (Help) Dir Function in Module..

    hello guys..

    i tried this code in my module
    Code:
    Public Const sPath As String = Dir("C:\Sample.txt", vbNormal Or vbHidden)
    and got this error:
    Constant Expression Required
    what should i do.?

    thnx in advance..
    Last edited by TRENDcafe; May 28th, 2009 at 02:06 AM.

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: (Help) Dir Function in Module..

    You just need to modify it like this.
    Code:
    Public sPath As String 
    SPath = Dir("C:\Sample.txt", vbNormal Or vbHidden)
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: (Help) Dir Function in Module..

    as you call it sPath, note the return from dir is filename only
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: (Help) Dir Function in Module..

    I suspect you are using VB.NET and not VB6. Is that an accurate supposition?

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: (Help) Dir Function in Module..

    If "c:\sample.txt" file will always be there then you can define your constant like this:
    Code:
    Public Const SAMPLE_FILE As String = "C:\Sample.txt"
    Change scope to Private if you want to declare it in the form.

  6. #6
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: (Help) Dir Function in Module..

    Dir("C:\Sample.txt", vbNormal Or vbHidden) will not be constant hence you cannot use it in your constant declaration.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2009
    Location
    Philippines
    Posts
    36

    Re: (Help) Dir Function in Module..

    wow.. thank to all of u guys...

    @dee-u: thnx for ur reply sir,, ah so it means i cannot use that as a constant?

    @westconn1: thnx u sir,, yup i am aware of that..hehehe

    @Hack:i am using VB6 sir,,i just trying to make that as constant but i think i cant.

    @RhinoBull: nope the "C:\sample.txt" may be there but its hidden, thats why i use Dir to check sir..hehe

    @dee-u: thank u sir,, its clear to me now..hehehe

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