Private Sub Command1_Click()
UserWantsOut = True
DoEvents
If UserWantsOut Then
Exit For
End If
End Sub
is it correct now? why its giving error msg exit for not within for
16 1511
No, I don't think you're understanding the way different routines interact in VB.
The idea is that your For loop which is doing the correction to the data keeps checking the value of the variable UserWantsOut, to see whether it needs to stop. The Click event for the button simply sets it to True. The DoEvents, If test and Exit For that you have placed in the Click event procedure don't belong there. They should have been put inside the For loop.
Private Sub Command1_Click()
UserWantsOut = True
DoEvents
If UserWantsOut Then
Exit For
End If
End Sub
is it correct now? why its giving error msg exit for not within for
there is no exit for... - Private Sub Command1_Click()
-
UserWantsOut = True
-
DoEvents
-
If UserWantsOut Then
-
GoTo ExitFor
-
End If
-
ExitFor:
-
End Sub
I think this will help you.
there is no exit for... - Private Sub Command1_Click()
-
UserWantsOut = True
-
DoEvents
-
If UserWantsOut Then
-
GoTo ExitFor
-
End If
-
ExitFor:
-
End Sub
I think this will help you.
One more thing, Give appropriate topic. - Private Sub Command1_Click()
-
UserWantsOut = True
-
DoEvents
-
If UserWantsOut Then
-
GoTo ExitFor
-
End If
-
ExitFor:
-
End Sub
I think this will help you.
No, it won't.
This is part of an ongoing development effort which has been discussed in other threads. There is a FOR loop going on elsewhere, and clicking this button is supposed to drop out of the loop. The Exit For didn't belong here at all.
- ' Scan the byte array and correct the constant parts.
-
For I = 49 To mFileSize - 6 Step 6
-
-
' Display original version of each line.
-
rich1.SelStart = Len(rich1.Text)
-
rich1.SelText = "Before : " & FormattedBytes(I, 6) & vbNewLine
-
-
' Check and correct 1st two bytes of each chunk.
-
If arrByte(I) <> a Then
-
arrByte(I) = a
-
changeMade = True
-
End If
-
If arrByte(I + 1) <> b Then
-
arrByte(I + 1) = b
-
changeMade = True
-
End If
-
-
' If section modified, show the corrected version.
-
If changeMade Then
-
AnyChanged = True
-
rich1.SelText = "After : " & FormattedBytes(I, 6) & " <--- Corrected" & vbNewLine
-
-
' Allow user to stop process by clicking Abort button.
-
DoEvents
-
If UserWantsOut Then
-
Exit For
-
End If
-
-
End If
-
-
Next
-
-
' Report whether we finished or were interrupted.
-
If UserWantsOut Then
-
MsgBox "Aborted by user!"
-
Else
-
MsgBox "Finished!"
-
End If
-
-
End If
-
-
End Sub
-
Am i putting the user want statement in right place.If i wana stop the scanning(i mean do correction) until EOF in the middle of the scanning process and resume back?How.Is that the userwantout function to abort the program in the middle of the one running process and continue back?
No, it won't.
This is part of an ongoing development effort which has been discussed in other threads. There is a FOR loop going on elsewhere, and clicking this button is supposed to drop out of the loop. The Exit For didn't belong here at all.
may be , but i do not think there is an 'exit for' key word in VB. if he mean it he have to give it like <exit for>
may be , but i do not think there is an 'exit for' key word in VB. if he mean it he have to give it like <exit for>
Exit For was correct, he just put it in the wrong place. VB uses Exit For to drop out of a For loop. At least, up to version 6 it does. Don't know about later ones.
... Am i putting the user want statement in right place.If i wana stop the scanning(i mean do correction) until EOF in the middle of the scanning process and resume back?How.Is that the userwantout function to abort the program in the middle of the one running process and continue back?
You have it very nearly correct. Apart from the extra End If at the end (which may relate to an earlier If that you didn't include in the message) I think this will work. (Note, I added some comments in your code.)
However, there is one change I would make to improve the responsiveness. Your check for whether the user wants to exit is only being done when you make a change. You should do the check each time around the For loop. Oh, also I spotted a bug. You never clear the changeMade flag, so once you do change a section, it will keep reporting every section changed after that.
Here's my modified version... - ' Scan the byte array and correct the constant parts.
-
For I = 49 To mFileSize - 6 Step 6
-
-
' Clear our "change made in this section" flag.
-
changemade = False
-
-
' Display original version of each line.
-
rich1.SelStart = Len(rich1.Text)
-
rich1.SelText = "Before : " & FormattedBytes(I, 6) & vbNewLine
-
-
' Check and correct 1st two bytes of each section.
-
If arrByte(I) <> a Then
-
arrByte(I) = a
-
changemade = True
-
End If
-
If arrByte(I + 1) <> b Then
-
arrByte(I + 1) = b
-
changemade = True
-
End If
-
-
' If section modified, show the corrected version.
-
If changemade Then
-
AnyChanged = True
-
rich1.SelText = "After : " & FormattedBytes(I, 6) & " <--- Corrected" & vbNewLine
-
End If
-
-
' Allow user to stop process by clicking Abort button.
-
DoEvents
-
If UserWantsOut Then
-
Exit For ' Drop out of the loop.
-
End If
-
-
Next
-
-
' Report whether we finished or were interrupted.
-
If UserWantsOut Then
-
MsgBox "Aborted by user!"
-
Else
-
MsgBox "Finished!"
-
End If
I think this will do the job. However, there is one enhancement I would suggest. Only report the "before" version of lines which are changed, rather than all of them. To do this you would need to move lines 7-9 after the If changeMade test, remove the string " <--- Corrected" (no longer required) and do one of the following... - Make another copy of the array before you start the corrections, and just report "before" and "after" from the two arrays. Or
- Make a copy of the first two bytes just before you change them, and use those in place of the array elements when reporting the "before" version.
Oh, one last thing. It seems to me, doing the correction within the byte array is likely to be so fast that I doubt the user will have time to click the Abort button. Unless writing all that output to the RichTextBox slows it down, I suppose.
Only report the "before" version of lines which are changed, rather than all of them. To do this you would need to move lines 7-9 after the If changeMade test, remove the string " <--- Corrected" (no longer required) and do one of the following...
Make another copy of the array before you start the corrections, and just report "before" and "after" from the two arrays. Or
Make a copy of the first two bytes just before you change them, and use those in place of the array elements when reporting the "before" version.
I cant understand what u are trying to said.Can u give some hidden plz?Killer42 thank you very much.U are realy helping me alot,from ur guidance my vb knowledge incresed.
Thank you very much for ur guidance.The explanation and the eg that u r giving to us realy great.U r realy expert in vb.Thank you again sir.
If UserWantsOut Then
MsgBox "Aborted by user!"
Else
MsgBox "Finished!"
End If
This function actualy can abort the process that running but why it cant continue back from the abort place when i click continue button.How to make it.It can stop the process but cant resume back from the point of stop.Help me on this plz
Only report the "before" version of lines which are changed ...I cant understand what u are trying to said ...
It's probably best if we skip that for now. It's just something I thought might make the user interface a bit nicer. Not important.
If UserWantsOut Then
MsgBox "Aborted by user!"
Else
MsgBox "Finished!"
End If
This function actualy can abort the process that running but why it cant continue back from the abort place when i click continue button.How to make it.It can stop the process but cant resume back from the point of stop.Help me on this plz
The particular code you have listed here doesn't actually have anything to do with aborting the process. It just shows message, telling the user what happened.
If you want to be able to continue, then you just need to make a note of where you're up to in the loop when the user says to stop. (Most likely in a global or form-level variable). For that to be any use, at the start of the process you need to check that variable and if it has been set, start from that point.
Question: Why do you want a restart process? Your byte array would have to be huge for the user to even notice the time it takes to run through it. Does displaying the results in the RichTextBox slow it down that much?
ya it take time to dispaly the data in the richtextbox.How we can solve this problem
ya it take time to dispaly the data in the richtextbox.How we can solve this problem
Good question. A couple of things come to mind... - For one, you could do the DoEvents less often.
When you issue DoEvents, that allows Windows to go off and handle other things, like updating the display and checking for user input. That's why I placed it immediately before the check for "user wants out". - Sometimes you can speed up the display by "locking" a window so it doesn't get updated, until you are ready.
I don't know whether that would help much in this particular case, though. - Have you considered using a regular TextBox instead of RichTextBox?
The simple fact that it can't do as much might mean it will update faster. - Displaying only the entries which are modified (instead of all entries) would probably give you the most "bang for your buck".
That depends, though - are you changing a very high percentage of the entries in the array?
[font=Arial]can u give some hidden how i can solve it the problem.can i used the text box instead of rich text box.is that the solution[/font]
can u give some hidden how i can solve it the problem.can i used the text box instead of rich text box.is that the solution
Some "hidden"? What does that mean?
Anyway, I gave you quite a few alternative solutions in my last message. Or if not "solutions", at least ideas which should make some difference. It's up to you to try things out and see what works in your situation.
At some point, you have to learn to take the described logic and convert it into program code for yourself. That's essentially what programming is.
And don't forget - if the speed is a problem, the solution might be as simple as leaving it to run overnight. Or in the background, while the user does something else.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Suzanne Vogel |
last post by:
I'd like to convert a double to a binary representation. I can use the
"&" bit operation with a bit mask to convert *non* float types to binary
representations, but I can't use "&" on doubles.
...
|
by: Howard |
last post by:
Hello everyone (total VB.NET beginner here),
I'm reading the "SAMS Teach Yourself VB.NET In 21 Days" book, and came
across an exercise that I can't get to work. The exercise asks that
you create...
|
by: Frank |
last post by:
I'm looking at a program I wrote long ago and I think there is much wrong -
even tho it works.
I know very little c and wish the learn.
Is BOOL correct with a dialog proc!
Are there returns that...
|
by: Ravi |
last post by:
Is this the correct way to think of "base class"?
The "base class" is a class from which other classes are derived.
The "base class" will never be derived from another class.
|
by: Stevo |
last post by:
If you split a string into an array using the split method, it's not
working the way I'd expect it to. That doesn't mean it's wrong of
course, but would anyone else agree it's working somewhat...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |