EOF not stopping
EOF not stopping
EOF not stopping
EOF not stopping
EOF not stopping
EOF not stopping EOF not stopping EOF not stopping EOF not stopping EOF not stopping EOF not stopping EOF not stopping EOF not stopping
EOF not stopping EOF not stopping
EOF not stopping
Go Back  Xtreme Visual Basic Talk > > > EOF not stopping


Reply
 
Thread Tools Display Modes
  #1  
Old 01-29-2005, 05:58 PM
fred_elliot fred_elliot is offline
Newcomer
 
Join Date: Jan 2005
Posts: 8
Default EOF not stopping


im using a Do Loop using the Until keyword and EOF(1) in my code...but it doesent seem to stop while stepping through debugging it will just carry on and on and on...it doesent come up with an actual error message im not sure if its not finding the end of the file right or i havent coded it right...im not sure if anyone will be able to help me...would i need to show my code?
Reply With Quote
  #2  
Old 01-29-2005, 06:52 PM
stijn koopal stijn koopal is offline
Centurion
 
Join Date: Jan 2004
Posts: 101
Default

Yes showing your code would be helpfull. We can't guess of what you are doing.
Reply With Quote
  #3  
Old 01-29-2005, 07:12 PM
fred_elliot fred_elliot is offline
Newcomer
 
Join Date: Jan 2005
Posts: 8
Default

Try
FileOpen(1, FileLocation, OpenMode.Append)
PrintLine(1, List.ToString)
Catch ex As Exception
MsgBox(" File error")
End Try
FileClose(1)

Try
FileOpen(1, FileLocation, OpenMode.Input)
Catch ex As Exception
MsgBox(" File error")
End Try

LineOfText = LineInput(1)
'split data into individual fields
Ref = LineOfText.Substring(0, 6)
Type = LineOfText.Substring(6, 1)
Weight = LineOfText.Substring(7, 4)
Quant = LineOfText.Substring(11, 4)
Calc = LineOfText.Substring(15, 1)
Buy = LineOfText.Substring(16, 4)
Sale = LineOfText.Substring(20, 4)

Do
For LoopAround = 1 To 6

If (Type) = (LoopAround) Then
Report.TextBox1.Text = Report.TextBox1.Text & _
Ref & " " & _
Type & " " & _
Weight & " " & _
Quant & " " & _
Calc & " " & _
Buy & " " & _
Sale & " " & _
vbCrLf
count = LoopAround
End If
Next LoopAround
Loop Until EOF(1)
Reply With Quote
  #4  
Old 01-30-2005, 12:50 AM
loquin's Avatar
loquinEOF not stopping loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,400
Default

This appears to be a .Net app, so I'll move it to the appropriate forum.

Second. It's not normally a good idea to place the EOF check at the end of the loop when reading a file. What happens inside the loop if the file is empty to begin with? You're much better off to:

Code:
Do While Not EOF (1) 'Read a Line ' Process a Line Loop
Reading a file this way won't even try to read a line if the file is empty.
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
Reply With Quote
  #5  
Old 01-30-2005, 09:49 AM
MKoslof's Avatar
MKoslofEOF not stopping MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

In .Net a typical Do loop for reading a text file would look something like:

Code:
'using a streamReader Dim sr As New StreamReader("C:\Testing.txt") Dim sLine As String Do sLine = sr.ReadLine() If Not sLine Is Nothing Then MessageBox.Show(sLine) End If Loop Until sLine Is Nothing sr.Close()
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #6  
Old 01-30-2005, 02:35 PM
fred_elliot fred_elliot is offline
Newcomer
 
Join Date: Jan 2005
Posts: 8
Default

ive tried putting the EOF at the beginning before and tried it again now just incase and the same thing happens it just hangs...no error message or anything it will just not end...

and i tried changing my code to use stream reader but it causes so much problems...i feel like im so close to having this sorted it just like one step away
Reply With Quote
  #7  
Old 01-30-2005, 02:42 PM
MKoslof's Avatar
MKoslofEOF not stopping MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Show us your updated code where you use the streamReader, because this method will work fine.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #8  
Old 01-30-2005, 04:07 PM
fred_elliot fred_elliot is offline
Newcomer
 
Join Date: Jan 2005
Posts: 8
Default

Dim sr As New StreamReader(FileLocation)

Try
FileOpen(1, FileLocation, OpenMode.Append)
PrintLine(1, List.ToString)
Catch ex As Exception
MsgBox(" File error")
End Try
FileClose(1)

Do
LineOfText = sr.ReadLine()
If Not LineOfText Is Nothing Then
'split data into individual fields
Ref = LineOfText.Substring(0, 6)
Type = LineOfText.Substring(6, 1)
Weight = LineOfText.Substring(7, 4)
Quant = LineOfText.Substring(11, 4)
Calc = LineOfText.Substring(15, 1)
Buy = LineOfText.Substring(16, 4)
Sale = LineOfText.Substring(20, 4)

For LoopAround = 1 To 6

If (Type) = (LoopAround) Then
Report.TextBox1.Text = Report.TextBox1.Text & _
Ref & " " & _
Type & " " & _
Weight & " " & _
Quant & " " & _
Calc & " " & _
Buy & " " & _
Sale & " " & _
vbCrLf
count = LoopAround
End If
Next LoopAround
End If
Loop Until LineOfText Is Nothing
Reply With Quote
  #9  
Old 01-30-2005, 04:54 PM
elnerdo's Avatar
elnerdo elnerdo is offline
Contributor
 
Join Date: Jul 2004
Location: Northern New Jersey
Posts: 490
Default

First off, that try-catch block at the beginning seems kind of pointless, just put the whole loop in the try catch block instead.

Also, I don't know if it works or not the way you do it, but the way I was taught to use streamreaders is to first dim a filestream
Code:
dim mystream as filestream = new filestream("c:\poopoo.txt", filemode.append)
THEN dim the streamreader
Code:
dim myreader as streamreader = new streamreader(mystream)
__________________
nerds unite!
Reply With Quote
  #10  
Old 01-31-2005, 09:57 PM
fred_elliot fred_elliot is offline
Newcomer
 
Join Date: Jan 2005
Posts: 8
Default

ive put that aside for the moment and i know this isnt the right place to post this...but i wasnt sure where to so i decieded to put it on the bottom here...the numbers that im sending to the file need to be formatted so that if a user was to put less digits than the max length of the field it filled the rest in...for example if one field had a max length of 4 and a user put in 33 it would return it as 0033...

ive tried using the Tostring method like so

Ref.ToString("000000")

but i receive this syntx error

type 'String' cannot be converted to 'System.IFormatProvider'.

what method should i use to format this?

thanks for all your help
Reply With Quote
  #11  
Old 02-12-2005, 02:04 PM
MKoslof's Avatar
MKoslofEOF not stopping MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

So is "ref" a defined string variable or number? If you want to pad your strings with zeros or other characters, use the .PadLeft and .PadRight methods (If I understand your question)
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
EOF not stopping
EOF not stopping
EOF not stopping EOF not stopping
EOF not stopping
EOF not stopping
EOF not stopping EOF not stopping EOF not stopping EOF not stopping EOF not stopping EOF not stopping EOF not stopping
EOF not stopping
EOF not stopping
 
EOF not stopping
EOF not stopping
 
-->