Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Rnd function to hh:mm:ss

johnl12johnl12 Posts: 1Member
Hi,

I'm wanting to add +- 30 seconds to a field within my code.

I've got it somewhat working, but it seems to add a random number outside the ranges of the ones I've set.

Below is the code I'm using:
[code]
' Set random number generator limits
upperBound = (0.000347001 * 2) * 1000 ' 60 seconds
lowerBound = 0 ' 0 seconds

' Loop around
For lp = 0 To j - 2

rnd_adjustment = (upperBound - lowerBound + 1) * Rnd + lowerBound
rnd_adjustment = rnd_adjustment / 1000

If (rnd_adjustment > 0.000347001) Then
rnd_adjustment = -rnd_adjustment / 2
End If
[/code]

My thinking behind the code is as follows:

1. 0.000347001 is equal to 30 seconds when converted to hh:mm:ss format.
2. To use the Rnd function I decided to create a number between 0 and (0.000347001*2) and then if above 0.000347001 divice by 2 and turn negative.

The output of my code does change the original hh:mm:ss but the changes are not limited to +-30 seconds as intended.

Could anyone shed light on this? Is it my method or is it something to do with the datatype (as it 0.000347001 it needs to be a Double?)
Any help sorting this out would be hugely appreciated.

Thanks!

John


Sign In or Register to comment.