Jump to content

~ a number


Recommended Posts

Hi, I am wondering if its possible to have a number "around" the value, for example

$Pz=60
$z=100
While $Pz <> $z

I want to know if there's any way to give a variable a "threshold" like making $z = 50 to 150

Hello, World!... LAME lol

Link to comment
Share on other sites

Hard to tell what you mean. Maybe something like this?

$Pz=60
$z=50
While $Pz <> $z
    ConsoleWrite("Loop:  " & $Pz & " <> " & $z & @LF)
    $z += 1
WEnd
ConsoleWrite("Exited loop:  " & $Pz & " = " & $z & @LF)

If that's it, then more sensible would be:

For $z = 50 To 59
    ConsoleWrite("Loop:  $z = " & $z & @LF)
Next
ConsoleWrite("Exited loop:  $z = " & $z & @LF)

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Sound like he is thinking something fussy. (AutoIt for neural networks ... Maybe in the far, far, future.)

@OP

Currently the number variable type only has one distinct value, and thats it. (ignoring float exceptional behaviors.)

If you care to explain why you think you need something like that. Others might post some ideas on how to go about it in AutoIt.

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Yeah, that kind of thing would be easy to implement with some UDFs, but would not be supported by the native functions and operators.

$Pz=60
$z = _RangeCreate(50, 150)
While _RangeIsInRange($Pz, $z)
    ConsoleWrite("Loop:  $Pz = " & $Pz & "; is in range" & @LF)
    $Pz += 1
WEnd
ConsoleWrite("Exited loop:  $Pz = " & $Pz & "; is out of range" & @LF)


Func _RangeCreate($Min, $Max)
    Local $Range[2] = [$Min, $Max]
    Return $Range
EndFunc

Func _RangeIsInRange($val, $Range)
    If ($val >= $Range[0]) And ($val <= $Range[1]) Then
        Return True
    Else
        Return False
    EndIf
EndFunc

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Switch $number
    Case 50 To 150
        ;; Do something
    Case Else
        ;; Do something else
EndSwitch

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I am new to AutoIt but how I would try it in java would be to have a starting number then set an upper and lower boundary by doing addition and subtraction on that value and setting those to two new values. You could then use the high and low boundaries in comparisons. Not sure if that helps at all.

Edited by ClayB
Link to comment
Share on other sites

#include <Array.au3>
Dim $Array[101]
For $i = 0 to 100
    $Array[$i] = $i + 50
Next
_ArrayDisplay($Array)

$Array now has values 50 through 150 in there.

$Variable = Floor(Random(50, 150))
MsgBox(64, 'Example', $Variable)

If you want a random number between 50 and 150, use this second one.

Edited by Epdmk
Link to comment
Share on other sites

If you want it as a function then here is the simplest IMHO

Func _InRange($iVal, $iMin, $iMax)
   Switch $iVal
       Case $iMin To $iMax
           Return True
       Case Else
           Return False
   EndSwitch
EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

That's a good one, George, but it still makes the point that these kinds of operations will require a roll-your-own approach. AutoIt does not support fuzzy logic natively.

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Very true but when having to "roll your own" I try to keep it as simple as possible.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Or...

RangeTest(13)
RangeTest(135)
RangeTest(211)
RangeTest(72)

Func RangeTest($num)
    Local $base = 100, $threshhold = 50 ; range  50 to 150
    If Abs($base - $num) <= $threshhold Then MsgBox(1,"", "Number " & $num  & " is within range")
EndFunc

Edit: Or , UDF'ed:

Func RangeTest($num, $base, $threshhold)
    If Abs($base - $num) <= $threshhold Then Return 1
EndFunc
Edited by Spiff59
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...