strange loop problem

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2007
Posts: 3
Reputation: Nakhla is an unknown quantity at this point 
Solved Threads: 0
Nakhla Nakhla is offline Offline
Newbie Poster

strange loop problem

 
0
  #1
Aug 21st, 2007
I have a 'do..while' section of code where it loops through lines in a text file, counts them, and when the line = "" the loop is supposed to stop and report the number of lines it counted. This all works fine in debugging mode... but when I compile it and try to run it from a program it doesn't stop when the line = "" it keeps going... it doesn't even stop at EOF.

Oddly enough... when I popped some msgbox's in there to see why it wasn't stopping when the line = "" it worked perfectly!

Anyone have ANY idea what could be going on? Here is the code, you'll notice the test msgbox I had put in:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Open filename For Input As #1
  2. Do Until EOF(1) 'until end of file
  3. Input #1, strLineValue 'read each line of text file, assign value
  4.  
  5. If strLineValue = "Optimal Parameter Set" Then
  6. Input #1, strLineValue
  7. Input #1, strLineValue
  8.  
  9. 'figure out how many ARCAEM parameters there are
  10. Do While strLineValue <> ""
  11. arrCellValue = Split(strLineValue)
  12. If arrCellValue(0) <> "ARCAEM_BG_K" Then
  13. param = param + 1
  14. Else
  15. BGK = True
  16. End If
  17. Input #1, strLineValue
  18. MsgBox strLineValue & ": " & param
  19. Loop
  20. End If
  21. Loop
  22. Close #1
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3
Reputation: Rich0001 is an unknown quantity at this point 
Solved Threads: 1
Rich0001's Avatar
Rich0001 Rich0001 is offline Offline
Newbie Poster

Re: strange loop problem

 
0
  #2
Aug 21st, 2007
Your code will fail when your data file has no empty lines. Consider changing your second DO statement to this:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Do While strLineValue <> "" And Not EOF(1)
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 57
Reputation: culebrin is an unknown quantity at this point 
Solved Threads: 1
culebrin culebrin is offline Offline
Junior Poster in Training

Re: strange loop problem

 
0
  #3
Aug 22nd, 2007
I think it would be a string type conversion (ASCII - Unicode thing) I use

trim(cstr(strLineValue)) <> ""

to make sure the values are evenly analysed.

Greetings
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3
Reputation: Nakhla is an unknown quantity at this point 
Solved Threads: 0
Nakhla Nakhla is offline Offline
Newbie Poster

Re: strange loop problem

 
0
  #4
Aug 22nd, 2007
Thanks for the input. I know that the text file will, and always will, be in the same format which includes "" lines, so there was no need to change the condition statement.

I played around with it yesterday and tried to come up with my own work-around. I concluded that since it always works when there was a msgbox there, it basically works when it has a slight 'pause.' So I put a .1 second pause in there, and now it works!

But I'm still baffled as to why it works... and was that the only way to fix it? (I'm afraid to play with it any more since it's finally working)

culebrin - do you think that because of some speed issue, the values were not being evenly analyzed, thus the reason for the infinite loop?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3
Reputation: Nakhla is an unknown quantity at this point 
Solved Threads: 0
Nakhla Nakhla is offline Offline
Newbie Poster

Re: strange loop problem

 
0
  #5
Aug 23rd, 2007
Originally Posted by culebrin View Post
I think it would be a string type conversion (ASCII - Unicode thing) I use

trim(cstr(strLineValue)) <> ""

to make sure the values are evenly analysed.

Greetings
I did give this a try, but it still did an infinite loop.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: strange loop problem

 
0
  #6
Aug 24th, 2007
Hi,

So Why not Trim and Check...?

Do While Trim(strLineValue) <> ""

REgards
Veena
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 57
Reputation: culebrin is an unknown quantity at this point 
Solved Threads: 1
culebrin culebrin is offline Offline
Junior Poster in Training

Re: strange loop problem

 
0
  #7
Aug 24th, 2007
Hi Nakhla,

Well, if you did give it a try, there's nowhere else to go with that advice.

If you try to put pause into the code, it will slow down the loop, the best to use in these cases is the DoEvents command, it will execute all the unfinished commands until that line of code.

I hope this is what you are looking for...

Greetings
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1292 | Replies: 6
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC