Solved

Question for RanjeetRain?

Posted on 2004-08-02
14
203 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

622 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