passing arguments to sub - script not working as expected 
Author Message
 passing arguments to sub - script not working as expected

Hi there,

My script is below.. I'm trying to pass 3 arguments to a sub; two different
calls.  I can only get the second call to the sub to work if I comment out
the four lines of the first call..  I don't know if arguments are passed by
ref or value or if it is something entirely different causing this not to
work.  Also, this script is triggered by the 'Task, Scheduler' and once
started, appears as 'running' until I stop it.. Another mystery..  Any help
is greatly appreciated.

TIA,
Mike D.

-------------------------------------------------------------------

'purpose:  deletes all files from a specified folder not modified in the
last x days
dim TargetFolder
dim BufferDays
dim ForceReadOnly

'first call -----------------------
TargetFolder = "F:\SharePoint Technologies\database_backups"
BufferDays = 0  'x days to keep backed up; 0 will delete the ENTIRE
directory's contents
ForceReadOnly = TRUE 'boolean argument to force deletion of read only files
Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)

'second call --------------------------
TargetFolder = "\\is034\sharepoint-backup\database_backups"
BufferDays = 7  'x days to keep backed up
ForceReadOnly = TRUE 'boolean argument to force deletion of read only files
Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)

sub DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)
 set fso = CreateObject("Scripting.FileSystemObject")   'Initializes a File
System Object
 set fldr = fso.GetFolder(TargetFolder)  'places the target folder in the
File System Object
 set myfiles = fldr.files  'returns all of the files in the target folder

 for each indfile in myfiles
      if indfile.DateLastModified < (Now() - BufferDays) then
   indfile.Delete (ForceReadOnly)
      end if
 next

 set fso = nothing
 set fldr = nothing
 set myfiles = nothing
 set indfile = nothing
end sub

wscript.quit



Tue, 28 Sep 2004 05:11:54 GMT  
 passing arguments to sub - script not working as expected

Mike,

It's good practice to explicity specify whether parameters are passed ByVal
or ByRef in all your function declarations.   VB 6.0 and VBScript default to
ByRef, but VB.NET now defaults to ByVal.

Is your F: drive mapped properly?

Gordon Bell

'purpose:  deletes all files from a specified folder not modified in the
last x days
dim TargetFolder
dim BufferDays
dim ForceReadOnly

'first call -----------------------
TargetFolder = "F:\SharePoint Technologies\database_backups"
BufferDays = 0  'x days to keep backed up; 0 will delete the ENTIRE
directory's contents
ForceReadOnly = TRUE 'boolean argument to force deletion of read only files

Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)

'second call --------------------------
TargetFolder = "\\is034\sharepoint-backup\database_backups"
BufferDays = 7  'x days to keep backed up
ForceReadOnly = TRUE 'boolean argument to force deletion of read only files

Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)

Sub DeleteOldBackups(ByVal TargetFolder, ByVal BufferDays, ByVal
ForceReadOnly)
    set fso = CreateObject("Scripting.FileSystemObject")   'Initializes a
File System Object
    set fldr = fso.GetFolder(TargetFolder)  'places the target folder in the
File System Object
    set myfiles = fldr.files  'returns all of the files in the target folder

    for each indfile in myfiles
        if indfile.DateLastModified < (Now() - BufferDays) then
            indfile.Delete (ForceReadOnly)
        end if
    next

    set fso = nothing
    set fldr = nothing
    set myfiles = nothing
    set indfile = nothing
end sub

wscript.quit


Hi there,

My script is below.. I'm trying to pass 3 arguments to a sub; two different
calls.  I can only get the second call to the sub to work if I comment out
the four lines of the first call..  I don't know if arguments are passed by
ref or value or if it is something entirely different causing this not to
work.  Also, this script is triggered by the 'Task, Scheduler' and once
started, appears as 'running' until I stop it.. Another mystery..  Any help
is greatly appreciated.

TIA,
Mike D.

-------------------------------------------------------------------

'purpose:  deletes all files from a specified folder not modified in the
last x days
dim TargetFolder
dim BufferDays
dim ForceReadOnly

'first call -----------------------
TargetFolder = "F:\SharePoint Technologies\database_backups"
BufferDays = 0  'x days to keep backed up; 0 will delete the ENTIRE
directory's contents
ForceReadOnly = TRUE 'boolean argument to force deletion of read only files
Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)

'second call --------------------------
TargetFolder = "\\is034\sharepoint-backup\database_backups"
BufferDays = 7  'x days to keep backed up
ForceReadOnly = TRUE 'boolean argument to force deletion of read only files
Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)

sub DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)
 set fso = CreateObject("Scripting.FileSystemObject")   'Initializes a File
System Object
 set fldr = fso.GetFolder(TargetFolder)  'places the target folder in the
File System Object
 set myfiles = fldr.files  'returns all of the files in the target folder

 for each indfile in myfiles
      if indfile.DateLastModified < (Now() - BufferDays) then
   indfile.Delete (ForceReadOnly)
      end if
 next

 set fso = nothing
 set fldr = nothing
 set myfiles = nothing
 set indfile = nothing
end sub

wscript.quit



Tue, 28 Sep 2004 06:17:08 GMT  
 passing arguments to sub - script not working as expected
Yes, F: is fine.. I think my problem is when I run from the Task Scheduler,
because of the 'Run as:' user setting.  I'm using a different user that's
password never expires - which is good except for the fact this user doesn't
have sufficient rights on the network drive
\\is034\sharepoint-backup\database_backups....

Thanks for the clarification on VBScript's ByRef default.  Mike D.


Quote:

> Mike,

> It's good practice to explicity specify whether parameters are passed
ByVal
> or ByRef in all your function declarations.   VB 6.0 and VBScript default
to
> ByRef, but VB.NET now defaults to ByVal.

> Is your F: drive mapped properly?

> Gordon Bell

> 'purpose:  deletes all files from a specified folder not modified in the
> last x days
> dim TargetFolder
> dim BufferDays
> dim ForceReadOnly

> 'first call -----------------------
> TargetFolder = "F:\SharePoint Technologies\database_backups"
> BufferDays = 0  'x days to keep backed up; 0 will delete the ENTIRE
> directory's contents
> ForceReadOnly = TRUE 'boolean argument to force deletion of read only
files

> Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)

> 'second call --------------------------
> TargetFolder = "\\is034\sharepoint-backup\database_backups"
> BufferDays = 7  'x days to keep backed up
> ForceReadOnly = TRUE 'boolean argument to force deletion of read only
files

> Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)

> Sub DeleteOldBackups(ByVal TargetFolder, ByVal BufferDays, ByVal
> ForceReadOnly)
>     set fso = CreateObject("Scripting.FileSystemObject")   'Initializes a
> File System Object
>     set fldr = fso.GetFolder(TargetFolder)  'places the target folder in
the
> File System Object
>     set myfiles = fldr.files  'returns all of the files in the target
folder

>     for each indfile in myfiles
>         if indfile.DateLastModified < (Now() - BufferDays) then
>             indfile.Delete (ForceReadOnly)
>         end if
>     next

>     set fso = nothing
>     set fldr = nothing
>     set myfiles = nothing
>     set indfile = nothing
> end sub

> wscript.quit



> Hi there,

> My script is below.. I'm trying to pass 3 arguments to a sub; two
different
> calls.  I can only get the second call to the sub to work if I comment out
> the four lines of the first call..  I don't know if arguments are passed
by
> ref or value or if it is something entirely different causing this not to
> work.  Also, this script is triggered by the 'Task, Scheduler' and once
> started, appears as 'running' until I stop it.. Another mystery..  Any
help
> is greatly appreciated.

> TIA,
> Mike D.

> -------------------------------------------------------------------

> 'purpose:  deletes all files from a specified folder not modified in the
> last x days
> dim TargetFolder
> dim BufferDays
> dim ForceReadOnly

> 'first call -----------------------
> TargetFolder = "F:\SharePoint Technologies\database_backups"
> BufferDays = 0  'x days to keep backed up; 0 will delete the ENTIRE
> directory's contents
> ForceReadOnly = TRUE 'boolean argument to force deletion of read only
files
> Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)

> 'second call --------------------------
> TargetFolder = "\\is034\sharepoint-backup\database_backups"
> BufferDays = 7  'x days to keep backed up
> ForceReadOnly = TRUE 'boolean argument to force deletion of read only
files
> Call DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)

> sub DeleteOldBackups(TargetFolder, BufferDays, ForceReadOnly)
>  set fso = CreateObject("Scripting.FileSystemObject")   'Initializes a
File
> System Object
>  set fldr = fso.GetFolder(TargetFolder)  'places the target folder in the
> File System Object
>  set myfiles = fldr.files  'returns all of the files in the target folder

>  for each indfile in myfiles
>       if indfile.DateLastModified < (Now() - BufferDays) then
>    indfile.Delete (ForceReadOnly)
>       end if
>  next

>  set fso = nothing
>  set fldr = nothing
>  set myfiles = nothing
>  set indfile = nothing
> end sub

> wscript.quit



Tue, 28 Sep 2004 07:00:29 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. passing arguments to sub - script not working as expected

2. Type mismatch passing argument to sub

3. InStrRev not working as expected - bug?

4. Recursive sub will not work??

5. Arguments : Passing Arguments containing <">

6. Arguments pass short 8.3 filename, how pass LFN?

7. Passing Arguments / Passing an Array

8. Passing arguments ByRef to Script Control 1.0

9. Passing argument to .VBS script from HTML page

10. Passing arguments into a WSH script.

11. Passing Arguments in Logon Scripts

12. Valid script does not work with Scripting Object Model

 

 
Powered by phpBB® Forum Software