Jump to content

Recommended Posts

Posted

Hope someone can help I am writing a function to create a random number to 3 decimal places between two parameters.

I am setting error levels in the func but would like these to end the function if the error values happen.

Run("notepad.exe")

WinWaitActive("Untitled - Notepad")

; Now that the Notepad window is active type the random decimal numbers
$nMin = 0
$nMax = 19999.9999
For $counter = 1 to 50
    $RandDim = _RandomDecDim($nMin, $nMax)  
    Send($RandDim&"{ENTER}")
Next
Sleep(3500)

    
Func _RandomDecDim($nMin, $nMax)
; Set the limits for min and max with error codes
    If $nMin < 0 Then  
        SetError(1); Min less than 0
    EndIf
    If $nMax > 999.999 Then 
        SetError(2); Max greater than range allowed
    EndIf

;Create the number    
$nRandDec = Round(Random($nMin, $nMax), 3)

Return $nRandDec

EndFunc; _RandomDecDim($nMin, $nMax)

The problem I have here is that I have to deal with the @errors outside of the function with a message box or something. I would like the fact that the max value above is too large to stop the function from within the function, currently it doesn't do this.

Thanks

  • Developers
Posted

What if you do it this way: on an error retunr -1 or -2 else return a value ....

Just test on the returned value if is -1 or -2 for errors...

Func _RandomDecDim($nMin, $nMax)
  ; Set the limits for min and max with error codes
   If $nMin < 0 Then  
      SetError(-1; Min less than 0
   ElseIf $nMax > 999.999 Then 
      SetError(-2; Max greater than range allowed
   Else
     ;Create the number    
      $nRandDec = Round(Random($nMin, $nMax), 3)
   EndIf
   Return $nRandDec
   
EndFunc  ;==>_RandomDecDim

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...