Bacilic Posted April 30, 2015 Posted April 30, 2015 I want between two $iMin and $iMax numbers to choose a number $iSelectNumber and whenever the user gives a number $iInputNumber, the $iMin and the $iMax to dynamically change as many times as necessary.Example: between 1 and 100 to choose 67.Step1. Range: 1 -100Step2. InputNumber: 70 -> Range: 1 – 70Step3. InputNumber: 34 -> Range: 34 – 70Step4. InputNumber: 55 -> Range: 55 - 70Step5. InputNumber: 69 -> Range: 55 – 69Stepn. ....I created the following function which returns the range properly the first time you call. Because the $iMin and the $iMax are fixed every time when call my function initializes the $iMinNew and the $iMaxNew and do not want it.Const $iMin = 1 Const $iMax = 100 Const $iSelected = 67 Func _Range($iInputNumber, $iSelected, $iMin, $iMax) ; Returns the range of the numbers in which the selected number included Local $aRange[2] Local $iMinNew = $iMin Local $iMaxNew = $iMax If $InputNumber < $iSelected Then $aRange[0] = $iInputNumber $aRange[1] = $iMaxNew $iMinNew = $iInputNumber Else $aRange[0] = $iMinNew $aRange[1] = $iInputNumber $iMaxNew = $iInputNumber EndIf Return $aRange EndFunc ;==>_RangeI want a help in the algorithm.
JohnOne Posted April 30, 2015 Posted April 30, 2015 Make you example runnable, at present it does nothing. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Bacilic Posted May 1, 2015 Author Posted May 1, 2015 Just quote the code I use to solve the problem with the dynamic range. Someone else may use a different approach. However certainly an executable code would help even for trials.Example:expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: Bacilic Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= ; Main Form $hFormDynamicRange = GUICreate("Dynamic Ragne", 344, 147, 192, 124) ; Inputs box: Min, Max and Given Number $hInputMin = GUICtrlCreateInput("", 64, 32, 65, 21) $hInputMax = GUICtrlCreateInput("", 64, 64, 65, 21) $hInputGiveNumber = GUICtrlCreateInput("", 152, 64, 65, 21) ; Buttons: Select and Check $hButtonSelect = GUICtrlCreateButton("Select", 240, 96, 67, 25) $hButtonCheck = GUICtrlCreateButton("Check", 152, 96, 67, 25) ; Message labels: Dynamic Range, Counts and Select Number $hLabelDynamicRange = GUICtrlCreateLabel("Dynamic range", 192, 32, 75, 17) $hLabelSelectNumber = GUICtrlCreateLabel("Select Number", 240, 72, 74, 17) $hLabelShowCount = GUICtrlCreateLabel("Efforts", 112, 96, 34, 17) #EndRegion ### END Koda GUI section ### Global $iMinNumber = 0 Global $iMaxNumber = 0 Global $iSelectNumber = 0 Global $iGivenNumber = 0 Global $iCount = 0 _GuiDynamicRange() Func _GuiDynamicRange() ; Main Form $hFormDynamicRange = GUICreate("Dynamic Ragne", 344, 147, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") ; Inputs box: Min, Max and Given Number $hInputMin = GUICtrlCreateInput("", 64, 32, 65, 21) $hInputMax = GUICtrlCreateInput("", 64, 64, 65, 21) $hInputGiveNumber = GUICtrlCreateInput("", 152, 64, 65, 21) ; Buttons: Select and Check $hButtonSelect = GUICtrlCreateButton("Select", 240, 96, 67, 25) GUICtrlSetTip(-1, "Selects a number and resets the counter") GUICtrlSetOnEvent(-1, "On_Button") $hButtonCheck = GUICtrlCreateButton("Check", 152, 96, 67, 25) GUICtrlSetOnEvent(-1, "On_Button") ; Mesage labels: Dynamic Range, Counts and Select Number $hLabelDynamicRange = GUICtrlCreateLabel("Dynamic range", 192, 32, 75, 17) $hLabelSelectNumber = GUICtrlCreateLabel("Select Number", 240, 72, 74, 17, $SS_CENTER) $hLabelShowCount = GUICtrlCreateLabel("Efforts", 112, 96, 34, 17) ; Static Labels: Min, Max, Counter, Explanation and Range $hLabelMin = GUICtrlCreateLabel("Min:", 40, 32, 24, 17) $hLabelMax = GUICtrlCreateLabel("Max:", 32, 64, 27, 17) $hLabelRange = GUICtrlCreateLabel("Range:", 152, 32, 39, 17) $hLabelCounter = GUICtrlCreateLabel("Counter:", 64, 96, 44, 17) $hLabelExplanation = GUICtrlCreateLabel("Until the counter become zero, range must also change dynamically.", 8, 8, 337, 17) GUISetState() While 1 Sleep(10) WEnd EndFunc ;==>_GuiDynamicRange Func On_Close() Switch @GUI_WinHandle Case $hFormDynamicRange Exit EndSwitch EndFunc ;==>On_Close Func On_Button() Switch @GUI_CtrlId Case $hButtonSelect $iMinNumber = Number(GUICtrlRead($hInputMin)) $iMaxNumber = Number(GUICtrlRead($hInputMax)) $iSelectNumber = _GuessNumber($iMinNumber, $iMaxNumber) GUICtrlSetData($hLabelSelectNumber, $iSelectNumber) GUICtrlSetData($hLabelDynamicRange, $iMinNumber & " - " & $iMaxNumber) $iCount = 0 ; Reset counter GUICtrlSetData($hLabelShowCount, $iCount) Case $hButtonCheck $iCount = $iCount + 1 $iGivenNumber = Number(GUICtrlRead($hInputGiveNumber)) $aDynamicRange = _Range($iGivenNumber, $iSelectNumber, $iMinNumber, $iMaxNumber) GUICtrlSetData($hLabelDynamicRange, $aDynamicRange[0] & " - " & $aDynamicRange[1]) GUICtrlSetData($hLabelShowCount, $iCount) EndSwitch EndFunc ;==>On_Button Func _GuessNumber($iMin, $iMax) ; Returns a random integer between minimum and maximum $iRandomNumber = Random($iMin, $iMax, 1) Return $iRandomNumber EndFunc ;==>GuessNumber Func _Range($iInput, $iSelect, $iMin, $iMax) ; Returns the range of the numbers in which the random number included Local $aRange[2] If $iInput < $iSelect Then $aRange[0] = $iInput $aRange[1] = $iMax $iMin = $iInput Else $aRange[0] = $iMin $aRange[1] = $iInput $iMax = $iInput EndIf Return $aRange EndFunc ;==>_RangeIf something is not clear in the first description gladly explain.
mikell Posted May 1, 2015 Posted May 1, 2015 (edited) ?expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: Bacilic Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $iMinNumber = 0 Global $iMaxNumber = 0 Global $iSelectNumber = 0 Global $iGivenNumber = 0 Global $iCount = 0 ; Main Form $hFormDynamicRange = GUICreate("Dynamic Ragne", 344, 147, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") ; Inputs box: Min, Max and Given Number $hInputMin = GUICtrlCreateInput("1", 64, 32, 65, 21) $hInputMax = GUICtrlCreateInput("100", 64, 64, 65, 21) $hInputGiveNumber = GUICtrlCreateInput("", 152, 64, 65, 21) ; Buttons: Select and Check $hButtonSelect = GUICtrlCreateButton("Select", 240, 96, 67, 25) GUICtrlSetTip(-1, "Selects a number and resets the counter") GUICtrlSetOnEvent(-1, "On_Button") $hButtonCheck = GUICtrlCreateButton("Check", 152, 96, 67, 25) GUICtrlSetOnEvent(-1, "On_Button") ; Mesage labels: Dynamic Range, Counts and Select Number $hLabelDynamicRange = GUICtrlCreateLabel("Dynamic range", 192, 32, 75, 17) $hLabelSelectNumber = GUICtrlCreateLabel("Select Number", 240, 72, 74, 17, $SS_CENTER) $hLabelShowCount = GUICtrlCreateLabel("Efforts", 112, 96, 34, 17) ; Static Labels: Min, Max, Counter, Explanation and Range $hLabelMin = GUICtrlCreateLabel("Min:", 40, 32, 24, 17) $hLabelMax = GUICtrlCreateLabel("Max:", 32, 64, 27, 17) $hLabelRange = GUICtrlCreateLabel("Range:", 152, 32, 39, 17) $hLabelCounter = GUICtrlCreateLabel("Counter:", 64, 96, 44, 17) $hLabelExplanation = GUICtrlCreateLabel("Until the counter become zero, range must also change dynamically.", 8, 8, 337, 17) GUISetState() While 1 Sleep(10) WEnd Func On_Close() Switch @GUI_WinHandle Case $hFormDynamicRange Exit EndSwitch EndFunc ;==>On_Close Func On_Button() Switch @GUI_CtrlId Case $hButtonSelect $iMinNumber = Number(GUICtrlRead($hInputMin)) $iMaxNumber = Number(GUICtrlRead($hInputMax)) $iSelectNumber = _GuessNumber($iMinNumber, $iMaxNumber) GUICtrlSetData($hLabelSelectNumber, $iSelectNumber) GUICtrlSetData($hLabelDynamicRange, $iMinNumber & " - " & $iMaxNumber) $iCount = 0 ; Reset counter GUICtrlSetData($hLabelShowCount, $iCount) Case $hButtonCheck $iCount = $iCount + 1 $iGivenNumber = Number(GUICtrlRead($hInputGiveNumber)) $aDynamicRange = _Range($iGivenNumber, $iSelectNumber, $iMinNumber, $iMaxNumber) GUICtrlSetData($hLabelDynamicRange, $aDynamicRange[0] & " - " & $aDynamicRange[1]) GUICtrlSetData($hLabelShowCount, $iCount) GUICtrlSetData($hInputMin, $aDynamicRange[0]) GUICtrlSetData($hInputMax, $aDynamicRange[1]) EndSwitch EndFunc ;==>On_Button Func _GuessNumber($iMin, $iMax) ; Returns a random integer between minimum and maximum $iRandomNumber = Random($iMin, $iMax, 1) Return $iRandomNumber EndFunc ;==>GuessNumber Func _Range($iInput, $iSelect, $iMin, $iMax) ; Returns the range of the numbers in which the random number included Local $aRange[2] If $iInput < $iSelect Then $aRange[0] = $iInput $aRange[1] = $iMax $iMinNumber = $iInput Else $aRange[0] = $iMin $aRange[1] = $iInput $iMaxNumber = $iInput EndIf Return $aRange EndFunc ;==>_Range Edited May 1, 2015 by mikell Bacilic 1
Bacilic Posted May 1, 2015 Author Posted May 1, 2015 Thanks for the hint – assistance mikell and incorporated into the code of the Basic program.Of course there needed to create two new variables, the $iMinNumberNew and $iMaxNumberNew where do equal to $iMinNumber and $iMaxNumber respectively so as not to affect the code in other places that call the $iMinNumber and $iMaxNumber.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now