Jump to content

Recommended Posts

Posted

Hi,

 

I dont remember what is the name of an AutoIT function that allows you to set a value to another value.

For example I have 2 variables:

a = 4 and b = 14

this function allows me to say that 4 = 0 and 14 = 100

 

then if i would use the function value of 50, my return value is the middle between 4 and 14.

 

Sorry if i didnt explained it correctly.

Posted
  On 4/12/2020 at 7:32 PM, rony2006 said:

this function allows me to say that 4 = 0 and 14 = 100

Expand  

4 = 4.

14 = 14.

If you want to set variable by it's value, you should hold an array of those variables.

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

  • Moderators
Posted

rony2006,

i think you want something like this:

$iA = 4

$iB = 14

$iPercentage = 50

$iRet = _Rony($iA, $iB, $iPercentage)

ConsoleWrite($iRet & @CRLF)

Func _Rony($iMin, $iMax, $iPer)

    ; Get the difference between the maximum and minimum values
    $iDiff = $iMax - $iMin
    ; Calculate the required percentage of that difference
    $iValue = Round($iDiff * $iPer / 100)
    ; And add it to the minimum value
    Return $iMin + $iValue

EndFunc

Am I right?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

Sorry i think i didnt explained correctly. 

Let me give another example: 

I have a slider, minimum value return by slider is 0 and maximum value returned by slider is 100.

I have a car that have a speed between 20 km/h (minimum) and 120 km/h maximum. 

In my function I will input 20 as min and 120 as max (considering that 0 and 100 are always standard).

Now I will move my slider at a value of 64 (as I said, slider can go from 0 to 100), and I want to have the speed of my car. How I can calculate this?

  • Moderators
Posted

rony2006,

That sounds as if my function is exactly what you want. Please ask if you have any questions.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)
#include <GUIConstantsEx.au3>

$iMin = 20
$iMax = 80

$hGUI = GUICreate('', 200, 200)
$iSlider = GUICtrlCreateSlider(10, 20, 180, 20)
GUICtrlSetLimit($iSlider, $iMax, $iMin)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iSlider
            $iSpeed = GUICtrlRead($iSlider)
            ConsoleWrite('Speed: ' & $iSpeed & @CRLF)
    EndSwitch
WEnd

 

Edited by MrCreatoR

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted (edited)

Or using Melba23's function:

#include <GUIConstantsEx.au3>

$iMin = 20
$iMax = 120

$hGUI = GUICreate('', 200, 200)

$iSlider = GUICtrlCreateSlider(10, 20, 180, 20)

GUICtrlCreateLabel('Slider Pos:', 20, 60, 80, 20)
GUICtrlCreateLabel('Speed:', 20, 80, 80, 20)
$iSliderPos_Lbl = GUICtrlCreateLabel('', 100, 60, 40, 20)
$iSpeed_Lbl = GUICtrlCreateLabel('', 100, 80, 40, 20)

GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iSlider
            $iPos = GUICtrlRead($iSlider)
            $iSpeed = _MinMax($iMin, $iMax, $iPos)
            
            GUICtrlSetData($iSliderPos_Lbl, $iPos)
            GUICtrlSetData($iSpeed_Lbl, $iSpeed)
    EndSwitch
WEnd

Func _MinMax($iMin, $iMax, $iPer)
    ; Get the difference between the maximum and minimum values
    Local $iDiff = $iMax - $iMin
    ; Calculate the required percentage of that difference
    Local $iValue = Round($iDiff * $iPer / 100)
    ; And add it to the minimum value
    Return $iMin + $iValue
EndFunc

 

Edited by MrCreatoR

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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
  • Recently Browsing   0 members

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