ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem with Do While loop (https://www.excelbanter.com/excel-programming/359648-problem-do-while-loop.html)

alecbowman[_2_]

Problem with Do While loop
 
I am using a Do While loop to find when a time has been reached in a list of
measurements e.g.

Dim Time_Now As Double
Dim Calc_End_Time As Double

Calc_End_Time = Time_Now + Slew_Settle_Time

Do While Time_Now < Calc_End_Time
Time_Now = Sheets("Synchro.LFSS_Training_Tellback").Cells(p, 2)
p = p + 1
Loop
p = p - 1

This seems to work rather unreliably in that the condition should be met
when the two times are equal or Time_Now is later than Calc_End_Time.

Sometimes Time_Now < Calc_End_Time is shown as False when the times are the
same, (Calc_End_Time = 36552.0671068634 and Time_Now = 36552.0671068634).

This same code works correctly for other data and is consistently wrong in
other areas.

Any help would be gratefully received.

Alec

mudraker[_365_]

Problem with Do While loop
 

What data is in column 2 that is time_now is using?

It could be that you need to specify do command as

Do While timeserial(Time_Now) < timeserial(Calc_End_Time)


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=535734


alecbowman[_2_]

Problem with Do While loop
 
Column 2 contains a Date/Time as a serial number e.g. 36552.0671851736. Am
using a customformat to display this as a date/time down to 1mS.

Will try your suggestion.



"mudraker" wrote:


What data is in column 2 that is time_now is using?

It could be that you need to specify do command as

Do While timeserial(Time_Now) < timeserial(Calc_End_Time)


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=535734



alecbowman[_2_]

Problem with Do While loop
 
Can't use TimeSerial as this is only good for seconds as an integer.

"mudraker" wrote:


What data is in column 2 that is time_now is using?

It could be that you need to specify do command as

Do While timeserial(Time_Now) < timeserial(Calc_End_Time)


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=535734



mudraker[_366_]

Problem with Do While loop
 

Sorry I meant to say try Timevalue

Do While TimeValue(Time_Now)) < TimeValue(Calc_End_Time)

You may also need to use datevalue if you need check date as well as
time

Do While DateValue(Time_Now)) < DateValue(Calc_End_Time)

Also have you looked at the wait command - I have never used it myself


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=535734


alecbowman[_2_]

Problem with Do While loop
 
The problem is that I need to look at both the Date and Time. The data is
engineering information on the position of a servo. To plot this correctly
over midnight needs the date. Also on startup there is a time
synchronisation where the machinechanges from its default time starting in
1970 to current time. Again i need to take that into account.

Data typically looks like this with update rates of either 64Hz or 100Hz.
Timestamps are down to less than miliseconds so Excel has a problem here
anyway.

Serial No. Time Elevation
25772 27 Jan 2000 01:36:34.925 0.033
25786 27 Jan 2000 01:36:34.941 0.082
25800 27 Jan 2000 01:36:34.956 0.159
25810 27 Jan 2000 01:36:34.972 0.253
25824 27 Jan 2000 01:36:34.987 0.368
25834 27 Jan 2000 01:36:35.003 0.511
25848 27 Jan 2000 01:36:35.019 0.698
25859 27 Jan 2000 01:36:35.034 0.824
25873 27 Jan 2000 01:36:35.050 1.011
25887 27 Jan 2000 01:36:35.066 1.148
25897 27 Jan 2000 01:36:35.081 1.318
25911 27 Jan 2000 01:36:35.097 1.478
25921 27 Jan 2000 01:36:35.112 1.653
25935 27 Jan 2000 01:36:35.128 1.796
25945 27 Jan 2000 01:36:35.144 1.950
25959 27 Jan 2000 01:36:35.159 2.109
25969 27 Jan 2000 01:36:35.175 2.307
25983 27 Jan 2000 01:36:35.191 2.428
25997 27 Jan 2000 01:36:35.206 2.604
26007 27 Jan 2000 01:36:35.222 2.763
26021 27 Jan 2000 01:36:35.237 2.911
26031 27 Jan 2000 01:36:35.253 3.071
26045 27 Jan 2000 01:36:35.269 3.236

"Wait" halts the macro running until a time has been reached whereas I need
to find the specified periods of time (in the record) where the servo
performance is to be measured.


"mudraker" wrote:


Sorry I meant to say try Timevalue

Do While TimeValue(Time_Now)) < TimeValue(Calc_End_Time)

You may also need to use datevalue if you need check date as well as
time

Do While DateValue(Time_Now)) < DateValue(Calc_End_Time)

Also have you looked at the wait command - I have never used it myself


--
mudraker
------------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...fo&userid=2473
View this thread: http://www.excelforum.com/showthread...hreadid=535734




All times are GMT +1. The time now is 01:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com