Results 1 to 11 of 11

Thread: loop without do error

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    10

    loop without do error

    I am in the process of learning windows scripting and have run into a problem.
    I have been asked to get a script working that was started by another user that is no longer with the company I am working for. The script is suppose to pull a zip file from our web servers over to another server and unzip them to the correct directories for processing through and application called clicktracks. currently I am getting an error stating "Loop without do" and I can't figure out what the problem is.

    Here is an sample of the code

    VB Code:
    1. Option Explicit
    2.  
    3. 'Declare Variables
    4. Dim objFSO,objWSHShell,objInFile,objFolder,objFile,objZipFolder,objZipFile,objLogFile
    5. Dim strDate,strMonth,strYear,strDay,strTargetFile1,strTargetfile2,strDeleteDate
    6. Dim strServer,strImageLib,strPrimaryWS,strVirtualWS,strStage,strSyntax,strExt,strZip
    7. Dim arrWebServerList,strFolder1,strFolder2,strFolder3,strFolder4,strFolder5,strFile1
    8. Dim strFile2,strFile3,strMovefile,strNetUse,strSource,strOutFile
    9.  
    10. 'Set Objects
    11. Set objFSO = CreateObject("Scripting.FileSystemObject")
    12. Set objWSHShell = CreateObject("WScript.Shell")
    13. Set objInFile = objFSO.OpenTextFile("C:\scripts\WebServerList.txt")
    14.  
    15. 'Determin Target Date
    16. strDate = Now()-1
    17. strMonth = CStr(Month(strDate))
    18. strYear = Right(CStr(Year(strDate)),2)
    19. strDay = CStr(Day(strDate))
    20.  
    21. 'If Month Single Digit then pad with leading zero
    22. If Len(strMonth) = 1 Then
    23.     strMonth = "0" & strMonth
    24. End If
    25.  
    26. 'If Day Single Digit then pad with leading Zero
    27. If Len(strDay) = 1 Then
    28.     strDay = "0" & strDay
    29. End If
    30.  
    31. 'Determin Target Files
    32. strTargetFile1 = "ex" & strYear & strMonth & strDay & ".zip"
    33. strTargetfile2 = "ex" & strYear & strMonth & strDay & ".log"
    34.  
    35. 'Target Delete Date
    36. 'strDeleteDate = Date -32
    37.  
    38. 'Read Web Server List
    39. Do While Not objInFile.AtEndOfStream
    40.     arrWebServerList = Split(objInFile.ReadLine,",")
    41.    
    42. strServer= arrWebServerList(0)
    43. strImageLib = arrWebServerList(1)
    44. strPrimaryWS = arrWebServerList(2)
    45. strVirtualWS = arrWebServerList(3)
    46. strStage = "D:\" & strServer & "\"
    47. strZip = "c:\winzip\winzip32"
    48. strFile1 = strPrimaryWS & strTargetfile2
    49. strFile2 = strVirtualWS & strTargetfile2
    50. strFile3 = strImageLib & strTargetfile2
    51.  
    52. 'Authenticate to Web Server
    53. strNetUse = "cmd /c netuse \\" & strServer & (Login information for server)
    54. objWSHShell.Run strNetUse,0,True
    55.  
    56. 'Zip file Exist on Server
    57. If objFSO.FileExists ("\\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1) Then
    58.     Set objFile = objFSO.GetFile("\\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1)
    59.     'Copy zip file From WebServer
    60.     objFOS.Copyfile objFile.Path, strStage & "\"
    61.    
    62. 'UnZip File to Local Directory
    63. strSyntax = strZip & " -e " & stgStage & "\" & strTargetFile1 & " " & "C:\"
    64. objWSHShell.Run strSyntax,0,True
    65.  
    66. 'Move File to Destination Directory
    67. If objFSO.FileExists ("c:\" & strFile1) Then
    68. objFSO.MoveFile strStage & strPrimaryWS & "\"
    69.  
    70. If objFSO.FileExists ("c:\" & strFile2) Then
    71. objFSO.MoveFile strStage & strVirtualWS & "\"
    72.  
    73. If objFSO.FileExists ("c:\" & strFile3) Then
    74. objFSO.MoveFile strStage & strImageLib & "\"
    75.  
    76. Elseif strExt = ".zip" Then
    77. objFSO.MoveFile objLogFile.Path,strStage & "completedZips\"
    78.  
    79. 'Disconnect From Web Server
    80. strNetUse = "cmd /c netuse \\" & strServer & /d"
    81. objWSHShell.Run strNetUse,0
    82.  
    83. End If
    84.  
    85.     Loop

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: loop without do error

    check you "IF's" you seem to be missing some "End If's"
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: loop without do error

    Are the line continuation characters not showing? Or are they really not in the code?

    If...then...elseif is not being processed correctly if _ isn't there.

  4. #4
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: loop without do error

    I'm not sure what you are trying to do with all those if statements down at the bottom but for 4 if statements you have only one End If. If each of those are supposed to be seperate ifs then you need to properly end each one of them with an end if.

    typical if statement syntax is

    VB Code:
    1. If variable = something Then
    2.  
    3. Else 'Optional You dont have to have an else
    4.  
    5. End If

    you can do

    VB Code:
    1. If something = somethingelse Then
    2.  
    3. ElseIf something = somethingelse Then
    4.  
    5. ElseIf ...... you get the picture
    6.  
    7. End If
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: loop without do error

    or even

    IF Something then Something

    but if you go to another line after "Then" then you need an end if for each If
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: loop without do error

    rhyatt,

    That's some really bad coding. First try indenting your if statement to give you a better understanding of what is executed under what conditions. But you definitely need some End If statements in there somewhere.

  7. #7
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: loop without do error

    rhyatt,

    Your code would actually be clearer if it was structured in this manner:

    Code:
    'Declare Variables
    Dim objFSO, objWSHShell, objInFile, objFolder, objFile, objZipFolder, objZipFile, objLogFile
    Dim strDate, strMonth, strYear, strDay, strTargetFile1, strTargetfile2, strDeleteDate
    Dim strServer, strImageLib, strPrimaryWS, strVirtualWS, strStage, strSyntax, strExt, strZip
    Dim arrWebServerList, strFolder1, strFolder2, strFolder3, strFolder4, strFolder5, strFile1
    Dim strFile2, strFile3, strMovefile, strNetUse, strSource, strOutFile
    
    'Set Objects
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objWSHShell = CreateObject("WScript.Shell")
    Set objInFile = objFSO.OpenTextFile("C:\scripts\WebServerList.txt")
    
    'Determin Target Date
    strDate = Now() - 1
    strMonth = CStr(Month(strDate))
    strYear = Right(CStr(Year(strDate)), 2)
    strDay = CStr(Day(strDate))
    
    'If Month Single Digit then pad with leading zero
    If Len(strMonth) = 1 Then
        strMonth = "0" & strMonth
    End If
    
    'If Day Single Digit then pad with leading Zero
    If Len(strDay) = 1 Then
        strDay = "0" & strDay
    End If
    
    'Determin Target Files
    strTargetFile1 = "ex" & strYear & strMonth & strDay & ".zip"
    strTargetfile2 = "ex" & strYear & strMonth & strDay & ".log"
    
    'Target Delete Date
    'strDeleteDate = Date -32
    
    'Read Web Server List
    Do While Not objInFile.AtEndOfStream
        arrWebServerList = Split(objInFile.ReadLine, ",")
        
        strServer = arrWebServerList(0)
        strImageLib = arrWebServerList(1)
        strPrimaryWS = arrWebServerList(2)
        strVirtualWS = arrWebServerList(3)
        strStage = "D:\" & strServer & "\"
        strZip = "c:\winzip\winzip32"
        strFile1 = strPrimaryWS & strTargetfile2
        strFile2 = strVirtualWS & strTargetfile2
        strFile3 = strImageLib & strTargetfile2
    
        'Authenticate to Web Server
        strNetUse = "cmd /c netuse \\" & strServer & (Login information for server)
        objWSHShell.Run strNetUse, 0, True
        
        'Zip file Exist on Server
        If objFSO.FileExists("\\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1) Then
            Set objFile = objFSO.GetFile("\\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1)
            'Copy zip file From WebServer
            objFOS.Copyfile objFile.Path, strStage & "\"
            'UnZip File to Local Directory
            strSyntax = strZip & " -e " & stgStage & "\" & strTargetFile1 & " " & "C:\"
            objWSHShell.Run strSyntax, 0, True
    
            'Move File to Destination Directory
            If objFSO.FileExists("c:\" & strFile1) Then
                objFSO.MoveFile strStage & strPrimaryWS & "\"
            Else
    
                If objFSO.FileExists("c:\" & strFile2) Then
                    objFSO.MoveFile strStage & strVirtualWS & "\"
                Else
                
                    If objFSO.FileExists("c:\" & strFile3) Then
                        objFSO.MoveFile strStage & strImageLib & "\"
    
                    ElseIf strExt = ".zip" Then
                        objFSO.MoveFile objLogFile.Path, strStage & "completedZips\"
        
                        'Disconnect From Web Server
                        strNetUse = "cmd /c netuse \\" & strServer & /d"
                        objWSHShell.Run strNetUse, 0
                    End If
                    
                 End If
                 
             End If
    
        End If
    
    Loop

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: loop without do error

    Shouldn't you always disconnect from the server? Right now it's in the IF statement.

  9. #9

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    10

    Re: loop without do error

    Everyone

    Thanks you for your help on this problem. As Randem suggested I modified and cleaned up the code some. My only problems now is once the files are unzipped they do not move to the proper folders and the script does not loop. For what ever if I user this
    VB Code:
    1. Set objFile1 = objFSO.GetFile("C:\" & strFile1)
    2. objFSO.MoveFile objFile1.path,strStage & "\" & strPrimaryWS & "\"

    It works fine. but with this
    VB Code:
    1. objFSO.MoveFile strStage & "\" & strPrimaryWS & "\"
    the log files will not be moved.

    Here is a copy of the updated code. any suggestions on the movefile problem or the non looping issue would be great.

    VB Code:
    1. Option Explicit
    2.  
    3. On Error Resume Next
    4.  
    5. 'Declare Variables
    6. Dim objFSO,objWSHShell,objInFile,objFolder,objFile,objZipFolder,objZipFile,objLogFile,objFile1,objFile2,objFile3,objOutFile
    7. Dim strDate,strMonth,strYear,strDay,strTargetFile1,strTargetfile2,strDeleteDate
    8. Dim strServer,strImageLib,strPrimaryWS,strVirtualWS,strStage,strSyntax,strExt,strZip
    9. Dim arrWebServerList,strFolder1,strFolder2,strFolder3,strFile1
    10. Dim strFile2,strFile3,strMovefile,strNetUse,strSource,strOutFile
    11.  
    12. 'Set Objects
    13. Set objFSO = CreateObject("Scripting.FileSystemObject")
    14. Set objWSHShell = CreateObject("WScript.Shell")
    15. Set objInFile = objFSO.OpenTextFile("C:\scripts\WebServerList.txt")
    16.  
    17.  
    18. 'Determin Target Date
    19. strDate = Now()-1
    20. strMonth = CStr(Month(strDate))
    21. strYear = Right(CStr(Year(strDate)),2)
    22. strDay = CStr(Day(strDate))
    23.  
    24. 'If Month Single Digit then pad with leading zero
    25. If Len(strMonth) = 1 Then
    26.     strMonth = "0" & strMonth
    27. End If
    28.  
    29. 'If Day Single Digit then pad with leading Zero
    30. If Len(strDay) = 1 Then
    31.     strDay = "0" & strDay
    32. End If
    33.  
    34. 'Determin Target Files
    35. strTargetFile1 = "ex" & strYear & strMonth & strDay & ".zip"
    36. strTargetfile2 = "ex" & strYear & strMonth & strDay & ".log"
    37.  
    38. 'Target Delete Date
    39. 'strDeleteDate = Date -32
    40.  
    41. 'Read Web Server List
    42. Do While Not objInFile.AtEndOfStream
    43.     arrWebServerList = Split(objInFile.ReadLine,",")
    44.    
    45.     strServer= arrWebServerList(0)
    46.     strImageLib = arrWebServerList(1)
    47.     strPrimaryWS = arrWebServerList(2)
    48.     strVirtualWS = arrWebServerList(3)
    49.     strStage = "c:\PioWebLogs\" & strServer
    50.     strZip = "c:\winzip\winzip32"
    51.     strFolder1 = strStage & "\" & strPrimaryWS
    52.     strFolder2 = strStage & "\" & strVirtualWS
    53.     strFolder3 = strStage & "\" & strImageLib
    54.     strFile1 = strPrimaryWS & strTargetfile2
    55.     strFile2 = strVirtualWS & strTargetfile2
    56.     strFile3 = strImageLib & strTargetfile2
    57.  
    58.     'Create Log file
    59.     Set objOutFile = objFSO.CreateTextFile("C:\PioWebLogs\" & strServer & "_LogResults.Log")
    60.     Const forWriting = 2
    61.     objOutFile.WriteLine "Web Log Pulls Results Log"
    62.     objOutFile.WriteLine Now() & vbTab & "Process Started"
    63.  
    64.     'Authenticate to Web Server
    65.     objOutFile.WriteLine Now() & vbTab & "Authenticate to Web Server: " & strServer
    66.     'objOutFile.WriteLineBlankLines(1)
    67.     strNetUse = "cmd /c netuse \\" & strServer & "Logon information"
    68.     objWSHShell.Run strNetUse,0,True
    69.  
    70.     'Zip file Exist on Server
    71.     If objFSO.FileExists ("\\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1) Then
    72.         objOutFile.WriteLine Now() & vbTab & "File Exists: " & strTargetFile1
    73.         Set objFile = objFSO.GetFile("\\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1)
    74.         'Copy zip file From WebServer
    75.         objOutFile.WriteLine Now() & vbTab & "Move Zip File From Web Server: \\" & strServer & "\D$\Logs\ZipFiles\" & strTargetFile1
    76.         objFSO.Copyfile objFile.Path,strStage & "\CompletedZips\"
    77.    
    78.    
    79.         'UnZip File to Local Directory
    80.         strSyntax = strZip & " -e -o " & strStage & "\CompletedZips\" & strTargetFile1 & " " & "C:\"
    81.         objOutFile.WriteLine Now() & vbTab & "Unzip File to Local Directory: " & strSyntax
    82.         objWSHShell.Run strSyntax,0,True
    83.  
    84.         'Move File to Destination Directory
    85.         objOutFile.WriteLine Now() & vbTab & "Move file to Destination Directory"
    86.         If objFSO.FileExists ("c:\" & strFile1) Then
    87.         objOutFile.WriteLine Now() & vbTab & " Move " & objFile1 & " To " & strStage & "\" & strPrimaryWS & "\"
    88.         objFSO.MoveFile strStage & "\" & strPrimaryWS & "\"
    89.         Else
    90.  
    91.             If objFSO.FileExists ("c:\" & strFile2) Then
    92.             objOutFile.WriteLine Now() & vbTab & " Move " & objFile2 & " To " & strStage & "\" & strPrimaryWS & "\"
    93.                 objFSO.MoveFile strStage & "\" & strVirtualWS & "\"
    94.             Else
    95.            
    96.                 If objFSO.FileExists ("c:\" & strFile3) Then
    97.                 objOutFile.WriteLine Now() & vbTab & " Move " & objFile3 & " To " & strStage & "\" & strPrimaryWS & "\"
    98.                     objFSO.MoveFile strStage & "\" & strImageLib & "\"
    99.        
    100.                    
    101.        
    102.                     'Disconnect From Web Server
    103.                     strNetUse = "cmd /c netuse \\" & strServer & "\IPC$ /d"
    104.                     objWSHShell.Run strNetUse,0
    105.                 End If     
    106.            
    107.             End If
    108.            
    109.         End If
    110.    
    111.     End If
    112.  
    113. Loop
    114.  
    115. objOutFile.WriteLine Now() & vbTab & "Process Complete"
    116. objOutFile.Close
    Last edited by rhyatt; Oct 3rd, 2005 at 11:47 AM.

  10. #10
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: loop without do error

    Because the objFSO.MoveFile methods needs two information to be able to move files... and that is the source path and the destination path (comma separated. You only plugged in one value in your erroneous line

  11. #11

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    10

    Resolved Re: loop without do error

    Everyone

    Thanks again for your help on this problem. I made a few more changes and got the script working. It loops through the file and everything is being moved to it's correct location.

    Thanks again
    Ron

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