Hi
The loop inside my code runs infinite. I couldn't figure out why. -
Private Sub Command50_Click()
-
Dim bFlag As Boolean
-
bFlag = False
-
-
Do While (bFlag = False)
-
Me.timeDisplay = Time()
-
-
If Me.txtHour = CStr(Hour(Time())) And _
-
Me.txtMinute = CStr(Minute(Time())) And _
-
Me.txtSecond = CStr(Second(Time())) Then
-
MsgBox "Some message"
-
bFlag = True
-
End If
-
Loop
-
-
End Sub
-
I put in hour, minute, second in textboxes on form and comparing thier values with system time. If time matches, MsgBox will run.
The loop runs all the time - as if condition is never met ?
Can anyone help?
Thanks
Qi
5 4567
Hi
The loop inside my code runs infinite. I couldn't figure out why. -
Private Sub Command50_Click()
-
Dim bFlag As Boolean
-
bFlag = False
-
-
Do While (bFlag = False)
-
Me.timeDisplay = Time()
-
-
If Me.txtHour = CStr(Hour(Time())) And _
-
Me.txtMinute = CStr(Minute(Time())) And _
-
Me.txtSecond = CStr(Second(Time())) Then
-
MsgBox "Some message"
-
bFlag = True
-
End If
-
Loop
-
-
End Sub
-
I put in hour, minute, second in textboxes on form and comparing thier values with system time. If time matches, MsgBox will run.
The loop runs all the time - as if condition is never met ?
Can anyone help?
Thanks
Qi
Try displaying the values of Hours, Mins and seconds to see if they actually match.
Atlernatively, to stop you having a infinite loop, you can have a counter and when it reaches a value, exit the loop.
like - dim counter as integer
-
dim value as integer
-
-
If Me.txtHour = CStr(Hour(Time())) And _
-
Me.txtMinute = CStr(Minute(Time())) And _
-
Me.txtSecond = CStr(Second(Time())) Then
-
MsgBox "Some message"
-
bFlag = True
-
else
-
counter = counter +1
-
if counter = value then
-
bFlag = True
-
end if
-
End If
istya
its working now..
thanks
qi
Try displaying the values of Hours, Mins and seconds to see if they actually match.
Atlernatively, to stop you having a infinite loop, you can have a counter and when it reaches a value, exit the loop.
like
dim counter as integer
dim value as integer
If Me.txtHour = CStr(Hour(Time())) And _
Me.txtMinute = CStr(Minute(Time())) And _
Me.txtSecond = CStr(Second(Time())) Then
MsgBox "Some message"
bFlag = True
else
counter = counter +1
if counter = value then
bFlag = True
end if
End If
Hi
There is one problem left. The same code: -
Private Sub Command50_Click()
-
Dim bFlag As Boolean
-
bFlag = False
-
-
-
Do While (bFlag = False)
-
-
Me.timeDisplay = Time() <----- never displayed on Form
-
-
If Me.txtHour = CStr(Hour(Time())) And _
-
Me.txtMinute = CStr(Minute(Time())) And _
-
Me.txtSecond = CStr(Second(Time())) Then
-
-
MsgBox "Some message"
-
bFlag = True
-
End If
-
-
Loop
-
-
End Sub
-
When the above while loop is running, the first statement : Me.timeDisplay = Time() runs but its result is not shown on the Form because the form is disabled/inactivated while the loop runs. what is the solution to this problem?
thanks
Qi
istya
its working now..
thanks
qi
I have sorted my problem out by just adding DoEvents within the Loop.
I have still 2 questions:
1- How can i stop that loop or exit from the Sub (Command50_Click()) on a Button Click
2- DoEvents uses 100% PC's resource, is there any alternative?
Code: -
Private Sub Command50_Click()
-
-
bFlag = False
-
-
Do While (bFlag = False)
-
-
Me.timeDisplay = Time()
-
-
If Me.txtHour = CStr(Hour(Time())) And _
-
Me.txtMinute = CStr(Minute(Time())) And _
-
Me.txtSecond = CStr(Second(Time())) Then
-
-
MsgBox "Some message"
-
bFlag = True
-
End If
-
DoEvents
-
Loop
-
-
End Sub
-
Thanks
Qi
Hi
There is one problem left. The same code: -
Private Sub Command50_Click()
-
Dim bFlag As Boolean
-
bFlag = False
-
-
-
Do While (bFlag = False)
-
-
Me.timeDisplay = Time() <----- never displayed on Form
-
-
If Me.txtHour = CStr(Hour(Time())) And _
-
Me.txtMinute = CStr(Minute(Time())) And _
-
Me.txtSecond = CStr(Second(Time())) Then
-
-
MsgBox "Some message"
-
bFlag = True
-
End If
-
-
Loop
-
-
End Sub
-
When the above while loop is running, the first statement : Me.timeDisplay = Time() runs but its result is not shown on the Form because the form is disabled/inactivated while the loop runs. what is the solution to this problem?
thanks
Qi
Rabbit 12,516
Recognized Expert Moderator MVP
This question has already been answered in another one of your posts a while back. This one will be closed.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Gremlin |
last post by:
If you are not familiar with the halting problem, I will not go into
it in detail but it states that it is impossible to write a program
that can tell if a loop is infinite or not. This is a fallacy built
on the assumption of mythical infinite all powerfull machines. In
reality we deal with finite machines that are capable of two states in...
|
by: mailpitches |
last post by:
Hello,
Is there any way to kill a Javascript infinite loop in Safari without
force-quitting the browser?
MP
|
by: LOPEZ GARCIA DE LOMANA, ADRIAN |
last post by:
Hi all,
I have a question with some code I'm writting:
def main():
if option == 1:
function_a()
|
by: Vector |
last post by:
Is any infinite loop better than other? Is there any difference between
there efficiency?
|
by: Steven Woody |
last post by:
i have a program which always run dead after one or two days, i think
somewhere a piece of the code is suspicious of involving into a
infinite loop. but for some reason, it is very hard to debug. so i
thing there might be tool which can statically analysis the code and
notice me this kind of potential problems if found. any suggestion? (
i...
| |
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 .
|
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...
|
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...
|
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...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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...
| |
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |