Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBScript Loop Error

Posted on 2010-11-10
4
Medium Priority
?
628 Views
Last Modified: 2012-05-10
I'm receiving a Microsoft VBScript Compilation error " loop without do"  at line 93.  I don't understand considering I have the two loop statements in the Function getCurrentFiles().
I've attached the script I'm using for your review and comments.  Thank you - Daniel
' Author: Dan Figueroa
 ' Version: 1.0
 ' Description: Uses the FileMaker Server 9 command line to search for
 ' all non-opened databases and opens them
 '
 ' This script does not have full Error handling.
 ' For instance, it will break if there are spaces in the FM file names.
 '
WScript.Echo "Setting variables "

 Const WshFinished = 1
 q = Chr(34) ' the " character, needed to wrap around paths with spaces

 '--------------------------------------------------------------------------------------------
 ' Change these variables to match your setup

 theAdminUser = "administrator"
 theAdminPW = "happysoftware"
 pathToSAtool = "C:\Program Files\FileMaker\FileMaker Server\Database Server\fmsadmin.exe"

 '--------------------------------------------------------------------------------------------


 SAT = "cmd /c " & q & pathToSAtool & q & " " ' watch the trailing space
 
WScript.Echo "Finding utility"

 callFMS = SAT
 If Len(theAdminUser) > 0 Then
 callFMS = callFMS & " -u " & theAdminUser
 End If
 If Len(theAdminPW) > 0 Then
 callFMS = callFMS & " -p " & theAdminPW
 End If
 
WScript.Echo "entering passwords "
 listfiles = callFMS & " list files -s"
 closeFiles = callFMS & " close file "

 ' hook into the Windows shell
 Set sh = WScript.CreateObject("wscript.shell")

 ' get list of files and open them
 fileIDs = getCurrentFiles()
 fileCount = UBound(fileIDs)

 ' loop through the files and open them
 WScript.Echo "loop through the files and open them "
 
 If fileCount > 0 Then
      Do Until fileCount = 0
      	   WScript.Echo "files to be opened "
           'fullCommand = openFiles & fileIDs(0) & " -y"
           'Set oExec = sh.Exec(fullCommand)
           ' give FMS some time and then requery the list of files
           Do Until oExec.Status = WshFinished
               WScript.Sleep 50
           Loop
           fileIDs = getCurrentFiles()
           fileCount = UBound(fileIDs)

      Loop
 End If

Function getCurrentFiles()

 tempCount = 0
 Dim tempArray()
 Set oExec = sh.Exec(listfiles)

 ' in case there are no files...
 If oexec.StdOut.AtEndOfStream Then Redim temparray(0)

 ' read the output of the command
 Do While Not oExec.StdOut.AtEndOfStream
     strText = oExec.StdOut.ReadLine()
     strText = Replace(strtext, vbTab, "")
     Do Until InStr(strtext, " ") = 0
           strText = Replace (strtext, " ", " ")
     Loop
     If InStr(strText, "ID File Clients Size Status Enabled Extended Privileges") > 0 Then
         ' do nothing
         Redim temparray(0)
     Else
 		 tempFile = Split(strtext, " ")
 		 status = LCase(tempFile(4))
         'If status = "closed" Then
 		 If status = "normal" Then
 		 tempCount = tempCount + 1
 		 Redim Preserve tempArray(tempCount)
 		 tempArray(tempCount - 1) = tempFile(1) & ".fp7"
 		 End If
  Loop

 	 getCurrentFiles = tempArray
 	 WScript.Echo "write to event log "
 	 WshShell.LogEvent 2, "WARNING: These file-ids: " & getCurrentFiles & "  are not open " & Time() & " on " & Date()
 End Function

Open in new window

0
Comment
Question by:danfiggolf
[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
  • 2
4 Comments
 
LVL 6

Expert Comment

by:r3nder
ID: 34107999
you need
Do[{while | Until} condition]
[statements]
[Exit Do]
[statements]
Loop

Example:
Do Until str = "Cool"
System.Console.WriteLine("What to do?")
str = System.Console.ReadLine()
Loop
End Sub

Thanks R3nder


0
 
LVL 3

Expert Comment

by:lecretia
ID: 34108028
Try moving lines 78, 79 and 80 into their own function and call that function in their place.

e.g.

Function getCurrentFiles()

 tempCount = 0
 Dim tempArray()
 Set oExec = sh.Exec(listfiles)

 ' in case there are no files...
 If oexec.StdOut.AtEndOfStream Then Redim temparray(0)

 ' read the output of the command
 Do While Not oExec.StdOut.AtEndOfStream
     strText = oExec.StdOut.ReadLine()
     strText = Replace(strtext, vbTab, "")
     replacetxt()
     If InStr(strText, "ID File Clients Size Status Enabled Extended Privileges") > 0 Then
         ' do nothing
         Redim temparray(0)
     Else
              tempFile = Split(strtext, " ")
              status = LCase(tempFile(4))
         'If status = "closed" Then
              If status = "normal" Then
              tempCount = tempCount + 1
              Redim Preserve tempArray(tempCount)
              tempArray(tempCount - 1) = tempFile(1) & ".fp7"
              End If
  Loop

        getCurrentFiles = tempArray
        WScript.Echo "write to event log "
        WshShell.LogEvent 2, "WARNING: These file-ids: " & getCurrentFiles & "  are not open " & Time() & " on " & Date()
 End Function

Function replacetxt()
     Do Until InStr(strtext, " ") = 0
           strText = Replace (strtext, " ", " ")
     Loop
End Function
0
 
LVL 3

Expert Comment

by:lecretia
ID: 34108066
r3nder's method is the correct way. Please ignore my offering.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 34108375
You need an End If between lines 92 and 93, so this
              End If
  Loop


becomes this
              End If
       End If
  Loop


Regards,

Rob.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

721 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