Solved

Loop without Do error

Posted on 2006-11-14
5
174 Views
Last Modified: 2010-04-30
Here is the error I get
C:\Inetpub\ftproot\thomson\import_hist1.vbs(49, 3) Microsoft VBScript compilatio
n error: 'loop' without 'do'
[code]
 Set Args = WScript.Arguments
 Const ForReading = 1, ForWriting = 2, ForAppending = 3
 Dim fs, f
 
 Filepath= args.Item(0)
 newfilepath=args.Item(1)

 If FSO.FileExists(Filepath) Then
  Dim file
  set file = FSO.GetFile(Filepath)
  Set newfile = fs.CreateTextFile(newfilepath, True)
  Dim FileSize
  FileSize = file.Size
  Dim TextStream
  Set TextStream = file.OpenAsTextStream(FileForReading)
 
  ' Read the file line by line
  Dim old_bondid, new_bondid
  Dim newline
  newline = """col0"",""col1"",""col2"",""col3"""
  old_bondid = "1"
  Do While Not textStream.AtEndOfStream  
  Dim Line
   Line = TextStream.readline
   
   ' Do something with "Line"
   Dim ar
   ar = Split(line, ",")
   new_bondid = ar(0)
   If new_bondid <> old_bondid Then
    Replace newline, "col1", ""
    Replace newline, "col1", ""
    Replace newline, "col1", ""
    newfile.WriteLine(newline)
    newline = """col0"",""col1"",""col2"",""col3"""
    Replace newline, "col0", ar(0)
   End If
   
   If InStr(line, """ISIN""") > 0 Then
    Replace newline, "col1", ar(7)
   Else if InStr(line, """AC""") > 0 Then
    Replace newline, "col2", ar(7)
   Else if InStr(line, """X""") > 0 Then
    Replace newline, "col3", ar(7)
   End if
    old_bondid = new_bondid  
  f.Close
  Loop
  TextStream.close
  newfile.Close
 End if
[/code]
0
Comment
Question by:casit
  • 2
  • 2
5 Comments
 
LVL 35

Expert Comment

by:Raynard7
ID: 17942223
The problem is pretty much how it is stated

 old_bondid = new_bondid  
  f.Close
  Loop<<<<<<<<<<<<<<<<<<<<<<<<<
  TextStream.

is a loop - now it needs a point to go back to , which is normally set with a do statement,

I am not sure where this would go but if you had
Do While ar = ... where the comment 'do something with "line" is you may get it to work
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 17942229
Your "Else" clauses were missformed:

   Set args = WScript.Arguments
   Const ForReading = 1, ForWriting = 2, ForAppending = 3
   Dim fs, f
   
   Filepath = args.Item(0)
   newfilepath = args.Item(1)

   If FSO.FileExists(Filepath) Then
   Dim file
   Set file = FSO.GetFile(Filepath)
   Set NewFile = fs.CreateTextFile(newfilepath, True)
   Dim FileSize
   FileSize = file.Size
   Dim TextStream
   Set TextStream = file.OpenAsTextStream(FileForReading)
   
   ' Read the file line by line
   Dim old_bondid, new_bondid
   Dim newline
   newline = """col0"",""col1"",""col2"",""col3"""
   old_bondid = "1"
   Do While Not TextStream.AtEndOfStream
      Dim Line
      Line = TextStream.readline
     
      ' Do something with "Line"
      Dim ar
      ar = Split(Line, ",")
      new_bondid = ar(0)
      If new_bondid <> old_bondid Then
         Replace newline, "col1", ""
         Replace newline, "col1", ""
         Replace newline, "col1", ""
         NewFile.WriteLine (newline)
         newline = """col0"",""col1"",""col2"",""col3"""
         Replace newline, "col0", ar(0)
      End If
     
      If InStr(Line, """ISIN""") > 0 Then
         Replace newline, "col1", ar(7)
      ElseIf InStr(Line, """AC""") > 0 Then
         Replace newline, "col2", ar(7)
      ElseIf InStr(Line, """X""") > 0 Then
         Replace newline, "col3", ar(7)
      End If
      old_bondid = new_bondid
      f.Close
   Loop
   TextStream.Close
   NewFile.Close
   End If

Kevin
0
 

Author Comment

by:casit
ID: 17942271
Thanks Kevin now I'm gettin ghtis error
C:\Inetpub\ftproot\thomson>import_hist1.vbs C:\thompson\equity\equity_daily01.cs
v C:\thompson\equity\ouput.txt
C:\Inetpub\ftproot\thomson\import_hist1.vbs(8, 4) Microsoft VBScript runtime err
or: Object required: 'FSO'
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 17942324
You need to define and load an FSO object:

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Kevin
0
 

Author Comment

by:casit
ID: 17979879
Thanks I figured it all out.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

821 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