VBA - Issues with Dir() and MkDir

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sitko
    New Member
    • Sep 2007
    • 140

    VBA - Issues with Dir() and MkDir

    Hi,

    I inherited some code from a client, and have been having issues with it.

    The first line was:
    Code:
    If Dir$(opath & "Requests\" & dirStr, vbDirectory) = "" Then
    I did a search in VBA help, and couldn't find 'Dir$' but did find 'Dir' I figured this was an instance where VBA had slightly less functionality than VB6/.net has...

    Dir$ returns a string, while Dir returns a variant. Unsure if this is an issue or not.

    The next line is the line that it blows up on:
    Code:
    MkDir opath & "Requests\" & dirStr
    Originally, he had:
    Code:
    MkDir (opath & "Requests\" & dirStr)
    But, it was hanging up there, so I removed the ( )s.
    opath IS a real path AT runtime.
    dirStr is a legal path as well.

    Any ideas?

    Thanks,
    Sitko.
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by sitko
    Hi,

    I inherited some code from a client, and have been having issues with it.

    The first line was:
    Code:
    If Dir$(opath & "Requests\" & dirStr, vbDirectory) = "" Then
    I did a search in VBA help, and couldn't find 'Dir$' but did find 'Dir' I figured this was an instance where VBA had slightly less functionality than VB6/.net has...

    Dir$ returns a string, while Dir returns a variant. Unsure if this is an issue or not.
    Its not a bug!, its a feature!,workin g it as a string is way faster than a variant, but you'll have to forget about some implicit type conversions (an insignificant draw back)

    But if it makes you feel better, you can remove the $ freely. It'll still working in VBA, or you can use DIR$ in many other versions of VB too.

    Originally posted by sitko
    The next line is the line that it blows up on:
    Code:
    MkDir opath & "Requests\" & dirStr
    Originally, he had:
    Code:
    MkDir (opath & "Requests\" & dirStr)
    But, it was hanging up there, so I removed the ( )s.
    opath IS a real path AT runtime.
    dirStr is a legal path as well.

    Any ideas?

    Thanks,
    Sitko.
    Yes, this code should be run only once, because you're creating a new dir.
    Once the Dir is created, you cannot create it again, so i'll show you an error.
    Just make sure the dir doesnt exists before you create it, or an error handler might be of help too.

    HTH

    PS: yeah, parenthesis may be removed without a problem.

    Comment

    • sitko
      New Member
      • Sep 2007
      • 140

      #3
      so, I guess the problem lies elsewhere...

      Thanks,
      Sitko.

      Comment

      • Dököll
        Recognized Expert Top Contributor
        • Nov 2006
        • 2379

        #4
        Might also consider telling us what you are trying to achieve, perhaps there's an idea here you can use...

        You can submit the whole code for all to see, just in case someone is passing through;-)

        See you soon!

        Dököll
        Last edited by Dököll; May 3 '08, 05:32 AM. Reason: considetr;-)

        Comment

        Working...