Solved

Question for RanjeetRain?

Posted on 2004-08-02
14
195 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
Comment Utility
Just noticed, there is no error checking!

What message boxes pop up?
0
 

Author Comment

by:cyle
Comment Utility
None, just didn't create any.
0
 
LVL 31

Assisted Solution

by:qwaletee
qwaletee earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:cyle
Comment Utility
I do have Sub CreateDir.....

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

Expert Comment

by:RanjeetRain
Comment Utility
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
Comment Utility
"Variant does not exist."
0
 
LVL 19

Expert Comment

by:RanjeetRain
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

16 Experts available now in Live!

Get 1:1 Help Now