Solved

Question for RanjeetRain?

Posted on 2004-08-02
14
201 Views
Last Modified: 2013-12-18
STPD question, but the code doesn't seem to work, maybe I missed something to create
   C:\WORK\ABC
Sub CreateDir(Byval DirName As String)
     Dim Parent As String
     Dim ParentExists As Variant
     
     On Error Resume Next
     Parent = Strleftback(Dirname, "\")
     ParentExists = Dir(Parent)
     
     If ParentExists = "" Then
          If Len(Parent) > 2 Then
               Msgbox "Call " + Parent
               Call CreateDir (Parent)
          End If
     End If
     Mkdir Dirname
End Sub

0
Comment
Question by:cyle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
14 Comments
 
LVL 31

Expert Comment

by:qwaletee
ID: 11697552
Just noticed, there is no error checking!

What message boxes pop up?
0
 

Author Comment

by:cyle
ID: 11697586
None, just didn't create any.
0
 
LVL 31

Assisted Solution

by:qwaletee
qwaletee earned 100 total points
ID: 11697737
Change to


Sub CreateDir(Byval DirName As String)
     Dim Parent As String
     Dim ParentExists As Variant
     
     On Error Resume Next
     Parent = Strleftback(Dirname, "\")
     ParentExists = Dir(Parent)
     
     If ParentExists = "" Then
          If Len(Parent) > 2 Then
               Msgbox "Call " + Parent
               Call CreateDir (Parent)
          End If
     Else
          Msgbox "Not necessary to create " & parent & " - just create final"
     End If
if err <> 0 then
    msgbox "prelude error " & error,,err
    err = 0
else
     Mkdir Dirname
if err <> 0 then
    msgbox "mkdir error " & error,,err
    err = 0
end if
   
End Sub

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11702786
Cyle,

THat is a 'TESTED OK' sub. The thing is - U also have to call it. Did you call it :)


After having typed that function.. you also have to call that SUB with an argument. Did you do that? I think you didn't :)

Call CreateDir ("C:\WORK\ABC")

Mission completed.
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11703071
Qwaletee,

That is some non-value-add code you added. Doesn't really help a lot. Besides, I feel your code won't even compile.
0
 

Author Comment

by:cyle
ID: 11703435
This is what I have. I had it working the first time but when I tested it (deleted the first one and tried creating it again, nothing happens)
Dim Parent As String
Dim ParentExists As Variant

On Error Resume Next
Parent = Strleftback("C:\WORK\ABC", "\")
ParentExists = Dir(Parent)

If ParentExists = "" Then
   If Len(Parent) > 2 Then
'   Msgbox "Call " + Parent
   Call CreateDir ("C:\WORK\ABC")
  End If
End If
MKdir Dirname

0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11703579
NO, NO, NO! That will cause an INFINITE LOOP. Do this!

1. Put the sub in in a Script Library
2. Use the Script Library in your form/agent
3. Call it like
       Call CreateDir ("C:\WORK\ABC")
    from wherever you want to create the directory.

If anything is not clear, pls let me know.
0
 

Author Comment

by:cyle
ID: 11703646
I do have Sub CreateDir.....

Call createdir(doc)  --- This is how I call it.
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11703916
NO! Call it like

Call CreateDir ("C:\WORK\ABC")

If you have to pick the value dynamically from the document, you may call it like:

Call CreateDir (doc.path(0))
0
 

Author Comment

by:cyle
ID: 11703999
"Variant does not exist."
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11704233
Yes, if your form doesn't have a field called PATH. See, do you want a dynamic path? Only then you have to take it from the document. Otherwise simply use the first version:

Call CreateDir ("C:\WORK\ABC")

Thats sufficient.

0
 

Author Comment

by:cyle
ID: 11704392
Sorry Ranjeet, here it is again.
Sub CreateDir(Byval DirName As String)
  Dim Parent As String
  Dim ParentExists As Variant
  On Error Resume Next
  Parent = Strleftback("C:\WORK\RFCECN", "\")
  ParentExists = Dir(Parent)
  If ParentExists = "" Then
     If Len(Parent) > 2 Then
       Call CreateDir ("C:\WORK\RFCECN")
     End If
  End If
Mkdir Dirname
End Sub

Call CreateDir ("C:\WORK\RFCECN")  Calling it as this.

wordobj.filesaveas "C:\WORK\RFCECN\" & RFC & ".doc"  , , , , , ,True, , , , , True     Saving it as this.

I get the error in saving, it would asks me to check the filepath. I also checked my C: and no C:\WORK is even created.

0
 
LVL 19

Accepted Solution

by:
RanjeetRain earned 400 total points
ID: 11704705
Oh oh. The same mistake again. YOu couldn't understand the context. You do not have to modify the call to CreateDir at all places. Only at one place. In your sub declaration you do not have to hard-code the path. DO NOT modify the sub declaration. Copy paste this one.


Sub CreateDir(Byval DirName As String)
    Dim Parent As String
    Dim ParentExists As Variant
   
     On Error Resume Next
    Parent = Strleftback(Dirname, "\")
    ParentExists = Dir(Parent)
   
     If ParentExists = "" Then
          If Len(Parent) > 2 Then
              Msgbox "Call " + Parent
              CreateDir Parent
         End If
    End If
    Mkdir Dirname
End Sub



Call CreateDir ("C:\WORK\RFCECN")  


NOTICE that I have only modified the main call to the sub... and not the Sub definition itself :)
0
 

Author Comment

by:cyle
ID: 11705308
Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question