Solved

Loop without Do error

Posted on 2006-11-14
5
175 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
vb6 connector to SQL Server 2 42
SLMGR Switches Are Not Working On KMS Host 3 170
VB6 ListBox Question 4 62
VBA - If Bookmark = "XXBOOKMARKXX" then 15 66
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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