Results 1 to 16 of 16

Thread: I just need a quick, easy answer

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715

    Question

    I forgot how to do this, but I want to see if a folder already is alread there, and if not, I want to create so can someone please fix the code for me:

    Code:
          if (the folder is already there) then
          Open "C:\dimas password\01.dat" For Output As #1
          Write #1, txtfn.Text, txtln.Text
          Close #1
    
          ELSE: MkDir "C:\dimas password\"
          Open "C:\dimas password\01.dat" For Output As #1
          Write #1, txtfn.Text, txtln.Text
          Close #1
    
    
          End If
    NXSupport - Your one-stop source for computer help

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    If Dir("C:\dimas password\") <> "" Then ...
    "It's cold gin time again ..."

    Check out my website here.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    thanks aloT!!!!
    NXSupport - Your one-stop source for computer help

  4. #4
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321

    object.FolderExists(folderspec)

    where object is the name of a FileSystemObject and folderspec is the folder name.

    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    I have another problem:

    Code:
    If Dir("C:\dimas password\") <> "" Then
    
    
            Open "C:\dimas password\01.dat" For Output As #1
            Write #1, txtfn.Text, txtln.Text
            Close #1
            
    Else:
    MkDir "C:\dimas password\"
    
    Open "C:\dimas password\01.dat" For Output As #1
    Write #1, txtfn.Text, txtln.Text
    Close #1
            
            
    End If
    the problem is that an error comes up when I run the program, I click debug and the yellow thign is pointing to where it ways:
    Code:
    MKDIR "C:\ dimas password\"
    NXSupport - Your one-stop source for computer help

  6. #6
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321

    Thumbs down Here's why If Dir("C:\dimas password\") <> "" Then... doesn't wo

    cause if c:\dimas password\ exist but is empty, then it returns "" as well, so going to MkDir would crash it.

    It also returns "" is the folder contains hidden files.

    Use the method mentioned above.
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715

    Re: Here's why If Dir(

    I don't think that I quite under stand what you wrote above, can you please put it so that it works in my case:

    object.folderexists(something)
    NXSupport - Your one-stop source for computer help

  8. #8
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321

    Lightbulb How to create fso

    btw... to create a FileSystemObject use:

    Code:
    Set fso = CreateObject("Scripting.FileSystemObject")
    then

    Code:
    If fso.FolderExists(anyFolder) Then

    Good luck
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715

    Re: How to create fso

    where do I put this:

    Code:
           Set fso = CreateObject("Scripting.FileSystemObject")

    Also, for how many years have you been learning VB (if not a secret)
    NXSupport - Your one-stop source for computer help

  10. #10
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321
    You can put the declaration wherever you want, preferably somewhere where it would run before fso is called. Like a module or Form_load or something..

    And I've been programming in vb since 89, so I guess that makes it 11 years..
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    Ok, thanks, it worked!!!

    WOW you've been programming for 11 years WOW!!!!

    do you work at some big company or something?
    NXSupport - Your one-stop source for computer help

  12. #12
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    I stand corrected. The FSO, not the Dir function was the way to go for this problem.
    "It's cold gin time again ..."

    Check out my website here.

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    one more question, how do I check if a file already exists
    NXSupport - Your one-stop source for computer help

  14. #14
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321

    Smile You use FileExists

    It's the same

    Just replace FolderExists with FileExists

    (and a filename within parentesis)

    object.FileExists(filenamewithpath)

    I'm not employed no I'm just still a student... but soon maybe..
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715

    Re: You use FileExists

    Ok, thanks for your help
    NXSupport - Your one-stop source for computer help

  16. #16
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321
    You're welcome, anytime!
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

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