| | |
strange loop problem
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2007
Posts: 3
Reputation:
Solved Threads: 0
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:
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)
Open filename For Input As #1 Do Until EOF(1) 'until end of file Input #1, strLineValue 'read each line of text file, assign value If strLineValue = "Optimal Parameter Set" Then Input #1, strLineValue Input #1, strLineValue 'figure out how many ARCAEM parameters there are Do While strLineValue <> "" arrCellValue = Split(strLineValue) If arrCellValue(0) <> "ARCAEM_BG_K" Then param = param + 1 Else BGK = True End If Input #1, strLineValue MsgBox strLineValue & ": " & param Loop End If Loop Close #1
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)
Do While strLineValue <> "" And Not EOF(1)
•
•
Join Date: Aug 2007
Posts: 3
Reputation:
Solved Threads: 0
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?
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?
•
•
Join Date: Aug 2007
Posts: 57
Reputation:
Solved Threads: 1
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
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
![]() |
Similar Threads
- nested for loop problem (Java)
- a for loop problem (Java)
- Alright this loop problem is bugging me (Java)
- I think Loop problem (Java)
- Strange monitor problem (Monitors, Displays and Video Cards)
- loop problem (C)
- Random Different Number in each loop ?? HLP Me PLZ (c or c++) (C++)
- loop problem (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: How to Resize Image with form resize event
- Next Thread: VB6 - Spreadsheet "MergeCells" not working
Views: 1292 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





