473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

now i think its correct

kirubagari
158 100+
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
Jul 23 '07 #1
16 1511
Killer42
8,435 Expert 8TB
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.
Jul 23 '07 #2
hariharanmca
1,977 1GB
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...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.      UserWantsOut = True
  3.      DoEvents
  4.      If UserWantsOut Then
  5.             GoTo ExitFor
  6.      End If
  7. ExitFor:
  8. End Sub
I think this will help you.
Jul 23 '07 #3
hariharanmca
1,977 1GB
there is no exit for...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.      UserWantsOut = True
  3.      DoEvents
  4.      If UserWantsOut Then
  5.             GoTo ExitFor
  6.      End If
  7. ExitFor:
  8. End Sub
I think this will help you.
One more thing, Give appropriate topic.
Jul 23 '07 #4
Killer42
8,435 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.      UserWantsOut = True
  3.      DoEvents
  4.      If UserWantsOut Then
  5.             GoTo ExitFor
  6.      End If
  7. ExitFor:
  8. 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.
Jul 23 '07 #5
kirubagari
158 100+
Expand|Select|Wrap|Line Numbers
  1. ' Scan the byte array and correct the constant parts.
  2. For I = 49 To mFileSize - 6 Step 6
  3.  
  4.   ' Display original version of each line.
  5.   rich1.SelStart = Len(rich1.Text)
  6.   rich1.SelText = "Before : " & FormattedBytes(I, 6) & vbNewLine
  7.  
  8.   ' Check and correct 1st two bytes of each chunk.
  9.   If arrByte(I) <> a Then
  10.     arrByte(I) = a
  11.     changeMade = True
  12.   End If
  13.   If arrByte(I + 1) <> b Then
  14.     arrByte(I + 1) = b
  15.     changeMade = True
  16.   End If
  17.  
  18.   ' If section modified, show the corrected version.
  19.   If changeMade Then
  20.     AnyChanged = True
  21.     rich1.SelText = "After : " & FormattedBytes(I, 6) & " <--- Corrected" & vbNewLine
  22.  
  23.     ' Allow user to stop process by clicking Abort button.
  24.     DoEvents
  25.     If UserWantsOut Then
  26.       Exit For
  27.     End If
  28.  
  29.   End If
  30.  
  31. Next
  32.  
  33. ' Report whether we finished or were interrupted.
  34. If UserWantsOut Then
  35.   MsgBox "Aborted by user!"
  36. Else
  37.   MsgBox "Finished!"
  38. End If
  39.  
  40. End If
  41.  
  42. End Sub
  43.  
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?
Jul 26 '07 #6
hariharanmca
1,977 1GB
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>
Jul 26 '07 #7
Killer42
8,435 Expert 8TB
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.
Jul 26 '07 #8
Killer42
8,435 Expert 8TB
... 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...
Expand|Select|Wrap|Line Numbers
  1.   ' Scan the byte array and correct the constant parts.
  2.   For I = 49 To mFileSize - 6 Step 6
  3.  
  4.     ' Clear our "change made in this section" flag.
  5.     changemade = False
  6.  
  7.     ' Display original version of each line.
  8.     rich1.SelStart = Len(rich1.Text)
  9.     rich1.SelText = "Before : " & FormattedBytes(I, 6) & vbNewLine
  10.  
  11.     ' Check and correct 1st two bytes of each section.
  12.     If arrByte(I) <> a Then
  13.       arrByte(I) = a
  14.       changemade = True
  15.     End If
  16.     If arrByte(I + 1) <> b Then
  17.       arrByte(I + 1) = b
  18.       changemade = True
  19.     End If
  20.  
  21.     ' If section modified, show the corrected version.
  22.     If changemade Then
  23.       AnyChanged = True
  24.       rich1.SelText = "After : " & FormattedBytes(I, 6) & " <--- Corrected" & vbNewLine
  25.     End If
  26.  
  27.     ' Allow user to stop process by clicking Abort button.
  28.     DoEvents
  29.     If UserWantsOut Then
  30.       Exit For ' Drop out of the loop.
  31.     End If
  32.  
  33.   Next
  34.  
  35.   ' Report whether we finished or were interrupted.
  36.   If UserWantsOut Then
  37.     MsgBox "Aborted by user!"
  38.   Else
  39.     MsgBox "Finished!"
  40.   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.
Jul 26 '07 #9
kirubagari
158 100+
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.
Jul 27 '07 #10
kirubagari
158 100+
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
Jul 27 '07 #11
Killer42
8,435 Expert 8TB
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.
Jul 27 '07 #12
Killer42
8,435 Expert 8TB
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?
Jul 27 '07 #13
kirubagari
158 100+
ya it take time to dispaly the data in the richtextbox.How we can solve this problem
Jul 27 '07 #14
Killer42
8,435 Expert 8TB
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?
Jul 27 '07 #15
kirubagari
158 100+
[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]
Jul 30 '07 #16
Killer42
8,435 Expert 8TB
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.
Jul 30 '07 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

17
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. ...
12
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...
1
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...
3
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.
14
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
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...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.