Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Loop without Do error

Posted on 2006-11-14
5
Medium Priority
?
179 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 1500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
Suggested Courses

879 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