Solved

Question for RanjeetRain?

Posted on 2004-08-02
14
196 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

919 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now