Solved

Loop without Do error

Posted on 2006-11-14
5
170 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
Comment Utility
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)
Comment Utility
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
Comment Utility
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
Comment Utility
You need to define and load an FSO object:

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

Kevin
0
 

Author Comment

by:casit
Comment Utility
Thanks I figured it all out.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now