473,471 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

exit for next loop

284 Contributor
i am using vb6
i had make a for next loop which fill data into
the table
now , some time it may needed that we want to
cancel that loop .
now what is the code to exit the for next loop

i want it like that it the user click on the button
the loop will exit
Mar 23 '08 #1
7 1845
jg007
283 Contributor
sorry, just realised you are using VB 6 and my last reply was for vb .net but what about declaring a boolean value and using do until boolean=false

ie

Expand|Select|Wrap|Line Numbers
  1. do until filltext  = false 
  2.  
  3. number=number +1
  4. label1.text=number
  5.  
  6. loop
  7.  
  8.  
then for the button you can have it set the boolean as false

again I have only just started using VB so others may have a better answer
Mar 23 '08 #2
jg007
283 Contributor
if you are using a for loop you could do this as -

Expand|Select|Wrap|Line Numbers
  1.  
  2.     For n = 1 To 10
  3.             If exitfill = true Then Exit For
  4.     Next
  5.  
  6.  
Mar 23 '08 #3
muddasirmunir
284 Contributor
is this possible that on pressing Esc button we exit from loop;
creating button and clicking it is creating problem as when if the loop
started it is not possible to click any button
Mar 23 '08 #4
jg007
283 Contributor
I don't know a lot about threading but with what I know it sounds like your best option is using a multithreaded program

I have some code but as i don't know a lot about threading and and I cant advise fullt on how to access one thread from another which my code doesn't do somebody else might be better to advise.
Mar 23 '08 #5
!NoItAll
297 Contributor
VB6 Code

For I = 0 to 365

DoEvents 'you should normally call this in any tight loop
If bEscapePressed = true then
Exit For
End if

'do all your other things here

Next I

bEscapePressed needs to be global.
Set the forms keypreview property to true and if the keydown event (in the same form) is the Esc Key you can set the boolean bEscapePressed to True.


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = 27 Then
bEscapePressed = True
End If

End sub

This will not work unless you have the DoEvents in the for loop. No need for multithreading - that's like hiring Picasso to paint your deck.
Mar 24 '08 #6
jg007
283 Contributor
This will not work unless you have the DoEvents in the for loop. No need for multithreading - that's like hiring Picasso to paint your deck.
Thanks the slightly better sugestion !, I am fairly new to VB so the threading was the only thing that came to mind :D.

always plenty to learn !
Mar 24 '08 #7
Killer42
8,435 Recognized Expert Expert
always plenty to learn !
Ain't that the truth! :)

Don't be put off - we need more people to get involved. Thanks for making the effort. (Wish I knew more about threads.)
Mar 25 '08 #8

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

Similar topics

1
by: Guinness Mann | last post by:
Pardon me if this is not the optimum newsgroup for this post, but it's the only .NET newsgroup I read and I'm certain someone here can help me. I have a C# program that checks for an error...
7
by: deko | last post by:
I have a function with a number of long loops. While the function is running, I want to be able to click a Stop button and exit the function as quickly as possible. The abbreviated code looks...
8
by: drose0927 | last post by:
Please help! I can't get my program to exit if the user hits the Escape button: When I tried exit(EXIT_SUCCESS), it wouldn't compile and gave me this error: Parse Error, expecting `'}''...
13
by: PeterZ | last post by:
Hi, Back to basics! My understanding is that the only way to exit a For-Next loop prematurely is with the 'break' keyword. How are you supposed to do that if you're inside a Switch...
3
by: Mike Johnson | last post by:
I have the following code in form1 and when the application starts this sub is called to check for a path if not found a message box is displayed and then gives the user an option to end the...
3
by: Ameen | last post by:
I am very new to programming and VB.net, and I wrote the code below, but it seem to go on an infinite loop. Please tell me what I am doing wrong. Private Sub search(ByVal indexstart) Pos1 =...
1
by: =?Utf-8?B?VGFvZ2U=?= | last post by:
Hi All, When I use applcation.exit() in winForm application, the form closed, but the process is still going!! ( The debug process is still running if debug in VS IDE). Environment.Exit(0) works...
2
by: nabman | last post by:
I am reading a txt file, I have a txt file(customers.txt) that is read, with account numbers and passwords. Once the user enters a account number and password it should read the file and if there in...
39
by: mathieu | last post by:
Hi there, I am trying to reuse a piece of code that was designed as an application. The code is covered with 'exit' calls. I would like to reuse it as a library. For that I renamed the 'main'...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.