473,588 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Breaking a "Do While" Infinite Loop using a command button

5 New Member
Hello, I'm a 2nd year Computer Engineering student and I have a problem with my VB6 code. I've just started learning VB6 for a project in which we have to create a form which displays the knight-rider light sequence. Obviously, this means using a loop and our lecturer has told us to use timers to control how long the sequence lasts for. I don't want to use timers ((this is not due to laziness, I would have been finished long ago had I used timers!! I just want to see if there is another way to do this project) , and I've read everywhere that the only way to break out of an infinite loop is Ctl+Alt+Del! What I am asking is - is there any code I could use to over-write the loop which I could also link with a command button (i.e. when I hit my 'exit' button on my form, the program stops runnning). If this is not possible, a way in which the user could input a number which would stop the program would also be a great help. The module I'm studying this for is interfacing, so user-compatability is paramount. Perhaps there is a different loop I could use which offers more flexibility?

Here is an outline of my code so far:

Private Sub cmdstart_click( )
Dim Index As Integer

Do While x < 50 (There's no particular reason why I chose 50, I just wanted to create an infinite loop)

For x = 0 To 7

DoEvents

Next x

For x = 6 To 0 Step -1

Do Events

Next x

Loop




End Sub

Code for 'Exit' Button

Private Sub Command1_Click( )
Unload Me
End Sub

I haven't posted the 'events' in the code, as the posting guidlines advise that you shouldn't post all of your code. I need to have this done in two days, so any help is appreciated! Thanks in advance, Anna.
Oct 3 '07 #1
13 17926
hariharanmca
1,977 Top Contributor
Your code doesn’t make any sense. Because X will not go beyond 50.
use boolen Flag, timer control if the flag is false then run loop if it true then stop.
Oct 3 '07 #2
code937
24 New Member
Surely you'd just set a flag?

at the top of your project set userexit as boolian

then in your loop check if userexit = true is so then exit the loop

then on the command button (user input) just set userexit = true.


in 'theory' that would work, try it :)
Oct 3 '07 #3
code937
24 New Member
lol, same idea, posted the same time :)
Oct 3 '07 #4
hariharanmca
1,977 Top Contributor
lol, same idea, posted the same time :)
Cheer up code937.

(The message you have entered is too short. Please lengthen your message to at least 20 characters)
Oct 3 '07 #5
Sunbags
5 New Member
Your code doesn’t make any sense. Because X will not go beyond 50.
use boolen Flag, timer control if the flag is false then run loop if it true then stop.
That was the idea, that it never goes beyond x, simply because I wanted to loop to run until the user decides to exit. However, exiting a loop is not so easy! What is a flag and how can I use it? I only started learning VB6 a week or two ago, so I'm not familiar with every nook and cranny, as it were! Thanks for your reply.
Oct 3 '07 #6
code937
24 New Member
= What is a flag and how can I use it?
right at the top of your code out of any routiene put this:

Expand|Select|Wrap|Line Numbers
  1. dim userxit as Boolean
in your module code put this

Expand|Select|Wrap|Line Numbers
  1. if userexit = true then exit sub
then on the command button put this

Expand|Select|Wrap|Line Numbers
  1. userexit = true
That will do it :)
Oct 3 '07 #7
Sunbags
5 New Member
right at the top of your code out of any routiene put this:

Expand|Select|Wrap|Line Numbers
  1. dim userxit as Boolean
in your module code put this

Expand|Select|Wrap|Line Numbers
  1. if userexit = true then exit sub
then on the command button put this

Expand|Select|Wrap|Line Numbers
  1. userexit = true
That will do it :)
Cheers, will try that now!
Oct 3 '07 #8
hariharanmca
1,977 Top Contributor
Expand|Select|Wrap|Line Numbers
  1. Do While x < 50 
  2. For x = 0 To 7
  3. DoEvents
  4. Next x
  5. For x = 6 To 0 Step -1
  6. Do Events
  7. Next x
  8. Loop
  9. End Sub
First 'for' will not do any thing (only Do events)
and also Same to second 'for'.
for this why don't you use a timer control?
Oct 3 '07 #9
Sunbags
5 New Member
right at the top of your code out of any routiene put this:

Expand|Select|Wrap|Line Numbers
  1. dim userxit as Boolean
in your module code put this

Expand|Select|Wrap|Line Numbers
  1. if userexit = true then exit sub
then on the command button put this

Expand|Select|Wrap|Line Numbers
  1. userexit = true
That will do it :)
Hello again, I implemented your code and the program still crashes. Also, when you said to place the
Expand|Select|Wrap|Line Numbers
  1. dim userexit as Boolean
at the top of the code outside of all routines, I presumed you meant that I was to put it above the
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdStart_Click()
line as opposed to underneath it. However, when I try to compile this, I get a message saying "Compile Error: Member already exists in an object module from which this object module derives". Am I placing the code you've given me in the wrong place?
Oct 4 '07 #10

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

Similar topics

15
2119
by: Jordan Rastrick | last post by:
First, a disclaimer. I am a second year Maths and Computer Science undergraduate, and this is my first time ever on Usenet (I guess I'm part of the http generation). On top of that, I have been using Python for a grand total of about a fortnight now. Hence, I apologise if what follows is a stupid suggestion, or if its already been made somewhere else, or if this is not the appropriate place to make it, etc. But I did honestly do some...
6
37201
by: Lauren Wilson | last post by:
Hello group, Somehow, I have not yet fully understood the meaning and purpose of "DoEvents". Can someone post or point me to a clear, concise explanation of it -- one that includes situational examples of how and why it is used? The Access on-line help is not as helpful as I need for my mental density! Sorry to be so dense. Please indulge me.
1
5205
by: Jim P. | last post by:
I'm having trouble returning an object from an AsyncCallback called inside a threaded infinite loop. I'm working on a Peer2Peer app that uses an AsyncCallback to rerieve the data from the remote peer. I have no problem connecting the peers and streaming Network Streams. When the incoming data is finished recieving, I act upon it. This works great as long as all of the code is inside my form. I want to build the networking code into a...
6
71958
by: John Pass | last post by:
What is the difference between a While and Do While/Loop repetition structure. If they is no difference (as it seems) why do both exist?
9
3491
by: haijin.biz | last post by:
why the following program using "char" gives me an infinite loop? If I change char to int, it works fine. #include <iostream> using namespace std; int main(int argc, char** argv) { for(char i=64; i<128; i++ ) cout<<i<<endl;
3
2133
by: archeryguru2000 | last post by:
Hello, I've been stumped for several weeks on this particlar program. At work here, we have 30 machines that we record scrap data on. I take this data and create spreadsheets (boring) that can be used for analysis. Anyway, I was wondering how I could change this "for" statement to a much more condensed amount of code. for i in range(30): while hold == 1: hold_01.append( hold ) hDate_01.append( hold ) ...
44
4320
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
8
8299
by: Pivot_Tables | last post by:
Hi, I have created a recursive SQL Query in DB2 and it works fine until some point in the tree where the data gets into infinite loop. Below are some sample data from my relationship table. Relationship Table PARENT FIELD CHILD FIELD AAA BBB AAA CCC
1
4579
by: robotlizz | last post by:
Hello - I am a brand new at Java and I am having a hard time with a program I have to turn in tomorrow. I can not get the 'Q' option to work and the loop goes on forever. I've tried to go over the tutorials but when I change it from here I then get compiling issues... Can someone explain what I've done wrong? import javax.swing.JOptionPane; public class LloydPage_Assignment5 { public static void main (String args) { // Enter Y to...
0
7929
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7862
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8228
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7987
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6634
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3847
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2372
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1459
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1196
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.