Solved

Loop without Do error

Posted on 2006-11-14
5
176 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
[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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month3 days, 17 hours left to enroll

630 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