Results 1 to 4 of 4

Thread: VB Script

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    4

    VB Script

    Hi All,

    I am attempting to create a small vbscript program that will check a directory to see if it has a file with todays date in it. Then the script will send an e-mail out if there isn't.

    Here is the code I have so far


    On Error Resume Next
    Dim strPath
    Dim blnFound
    Set fso = CreateObject("Scripting.FileSystemObject")
    strPath = Dir(pstrDir & "\*.*")
    While Len(strPath) > 0 And Not blnFound
    If Day(FileDateTime(pstrDir & "\" & strPath)) = Day(Now) Then
    blnFound = True
    End If
    strPath = Dir()
    Wend
    CheckForTodaysFile = blnFound

    If CheckForTodaysFile("M:\monitor\edi\edi\dump") Then
    Set refOutlook=CreateObject("outlook.application")
    sendmail=1
    If err <> 0 Then
    sendmail=0
    End If
    On Error GoTo 0
    ' do usefull stuff
    emaildata=("The Releases have not been loaded today. Please check

    their status and resolve!")
    If sendmail=1 Then
    Set refmailitem=refoutlook.createitem(0)
    refmailitem.to="[email protected]"
    refmailitem.Subject="New Realeses have not been loaded.Please

    Check!!"
    refmailitem.body=emaildata
    refmailitem.send
    Set refmailitem=nothing
    Set refoutlook = Nothing
    End If
    End If


    But it is not working. Can someone take a look and see if I am missing something.

    Thanks for any help...

  2. #2
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    Just so you know next time put your code using (vbcode) and then paste your code and close it with (/vbcode) but use brackets instead of perenthesis.

    VB Code:
    1. On Error Resume Next
    2.  
    3. 'the searching part of your code works fine.
    4. Dim strPath
    5. Dim blnFound
    6. pstrDir = "C:\"
    7. Set fso = CreateObject("Scripting.FileSystemObject")
    8. strPath = Dir(pstrDir & "\*.*")
    9. While Len(strPath) > 0 And Not blnFound
    10.     If Day(FileDateTime(pstrDir & "\" & strPath)) = Day(Now) Then
    11.         blnFound = True
    12.     End If
    13.     strPath = Dir()
    14. Wend
    15.  
    16. 'Now what are you doing here? Why are you giving
    17. 'CheckForTodaysFile the blnFound value?
    18. CheckForTodaysFile = blnFound
    19.  
    20. 'Then when you use your if statment it seems like you are
    21. 'calling the function CheckForTodaysFile with a string
    22. 'parameter. What does CheckForTodaysFile do?
    23. If CheckForTodaysFile("M:\monitor\edi\edi\dump") Then
    24.     Set refoutlook = CreateObject("outlook.application")
    25.     sendmail = 1
    26.     If Err <> 0 Then
    27.         sendmail = 0
    28.     End If
    29.     On Error GoTo 0
    30.     ' do usefull stuff
    31.     emaildata = ("The Releases have not been loaded today. Please check their status and resolve!")
    32.    
    33.     If sendmail = 1 Then
    34.         Set refmailitem = refoutlook.createitem(0)
    35.         'I was using my email here to be testing it.
    36.         refmailitem.to = "[email protected]"
    37.         refmailitem.Subject = "New Realeses have not been loaded.Please Check!!"
    38.         refmailitem.body = emaildata
    39.         refmailitem.send
    40.         Set refmailitem = Nothing
    41.         Set refoutlook = Nothing
    42.     End If
    43. End If

    Everything in your code works fine except what is CheckForTodaysFile? Is it a function or a variable? If it is a function please post your code for it otherwise I can't help since that is where your code is messing up.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    4
    Hi Maldrid,

    Thanks for your reply....

    Originally the first part of the code was called "checkfortodaysfile" as a function.

    All I want, is for the e-mail to be sent out if there is not a file in the directory with todays date.

    I need the program to search the "M:\monitor\edi\edi\dump" folder, and then if it doesn't find the file, to send the e-mail.

    Now I know the e-mail part of the code works fine. So how do I link the two parts of the code together?

    Thanks.....

  4. #4
    Fanatic Member
    Join Date
    Jun 2003
    Location
    IL
    Posts
    739
    Ok here is what your code should look like.

    VB Code:
    1. Dim strPath As String
    2. Dim blnFound as Boolean
    3.  
    4. pstrDir = "M:\monitor\edi\edi\dump"
    5.  
    6. 'not sure what fso is used for?
    7. Set fso = CreateObject("Scripting.FileSystemObject")
    8.  
    9. strPath = Dir(pstrDir & "\*.*")
    10. While Len(strPath) > 0 And Not blnFound
    11.     If Day(FileDateTime(pstrDir & "\" & strPath)) = Day(Now) Then
    12.         blnFound = True
    13.     End If
    14.     strPath = Dir()
    15. Wend
    16.  
    17.  
    18. If blnFound Then
    19.     Set refoutlook = CreateObject("outlook.application")
    20.     sendmail = 1
    21.     If Err <> 0 Then
    22.         sendmail = 0
    23.     End If
    24.     On Error GoTo 0
    25.     ' do usefull stuff
    26.     emaildata = ("The Releases have not been loaded today. Please check their status and resolve!")
    27.    
    28.     If sendmail = 1 Then
    29.         Set refmailitem = refoutlook.createitem(0)
    30.         'I was using my email here to be testing it.
    31.         refmailitem.to = "[email protected]"
    32.         refmailitem.Subject = "New Realeses have not been loaded.Please Check!!"
    33.         refmailitem.body = emaildata
    34.         refmailitem.send
    35.         Set refmailitem = Nothing
    36.         Set refoutlook = Nothing
    37.     End If
    38. End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width