Srex Posted June 4, 2014 Share Posted June 4, 2014 I'm trying to define the varible with 12 different outcomes (depending on user input) The reason for this is that the actual user input is not part of the formula the input is used in, and the input number is 100x easier for the user to find than the number I use in the formula. Var1 is the user input Var2 is the decimal number I need in the formula If $var1 = 1 Then $var2 = 0.03 If $var1 = 2 Then $var2 = 0.7 if $var1 = 3 Then $var2 = 1.2 etc etc, up to 12 inputs. The real question is what do I need to add in between the "if" statements? I tried "else" "ElseIf" To sortof make it check them 1 after 1, and when it finds the correct userinput and the assigns the correct decimal to $var2. I'm sorry guys I'm kinda new to coding, and really liking it.. Sorry if I waste your time, I really tried to read up on it. Link to comment Share on other sites More sharing options...
MrBeatnik Posted June 4, 2014 Share Posted June 4, 2014 Is there only 1 user input (that can have 12 outcomes)? If so you could use the CASE help documentation, but IF/ELSEIF/ELSE/ENDIF would work... assuming I understood your question correctly. Please correct me if I am wrong in any of my posts. I like learning from my mistakes too. Link to comment Share on other sites More sharing options...
Geir1983 Posted June 4, 2014 Share Posted June 4, 2014 Switch $var1 Case 1 $var2 = 0.03 Case 2 $var2 = 0.7 Case 3 $var2 = 0.7 EndSwitch Srex 1 Link to comment Share on other sites More sharing options...
Srex Posted June 4, 2014 Author Share Posted June 4, 2014 Is there only 1 user input (that can have 12 outcomes)? If so you could use the CASE help documentation, but IF/ELSEIF/ELSE/ENDIF would work... assuming I understood your question correctly. Yes the user is asked, and can answer the following: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or 11 So I should read up on CASE and thatwould help me? Sorry for being unclear Link to comment Share on other sites More sharing options...
MrBeatnik Posted June 4, 2014 Share Posted June 4, 2014 Yes the user is asked, and can answer the following: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or 11 So I should read up on CASE and thatwould help me? Sorry for being unclear Yep (Geir1983 posted an example of CASE too). Please correct me if I am wrong in any of my posts. I like learning from my mistakes too. Link to comment Share on other sites More sharing options...
Srex Posted June 4, 2014 Author Share Posted June 4, 2014 (edited) Switch $var1 Case 1 $var2 = 0.03 Case 2 $var2 = 0.7 Case 3 $var2 = 0.7 EndSwitch Thanks man ! Okay I will try my best and get back to you guys <3 __ Yes sorry mrbeatnik I first saw that after I posted that Edited June 4, 2014 by Srex Link to comment Share on other sites More sharing options...
Srex Posted June 4, 2014 Author Share Posted June 4, 2014 (edited) Alright I gave it my best shot, and it seems like it compiles and runs fine. However at this point I'm not able to check if the right value is being assigned to the variable Am I on the right track? Also I am Thinking about throwing a Case else in, if the user should enter a value which is not smaller or greater than max/min but doesnt fit the required numbers either, like decimals so something like: Case Else MsgBox(16, "Error", "Something has gone wrong please check your Windows Sensitivity input number again") Edited June 4, 2014 by Srex Link to comment Share on other sites More sharing options...
Solution MrBeatnik Posted June 4, 2014 Solution Share Posted June 4, 2014 Alright I gave it my best shot, and it seems like it compiles and runs fine. However at this point I'm not able to check if the right value is being assigned to the variable Thinking about throwing a Case else in something like Elseif MsgBox(16, "Error", "Something has gone wrong please check you Windows Sensitivity input number again") Am I on the right track? Not quite... You don't need the IFs - the CASE does the IF work for you. Switch $WindowSensInput Case 1 ;Checks if $WindowSensInput = 1 $ActualWindowSens = 0.031 Case 2 ;Checks if $WindowSensInput = 2 $ActualWindowSens = 0.222 Case 3 ;Checks if $WindowSensInput = 3 $ActualWindowSens = 0.333 ; Case n ;Checks if $WindowSensInput = n ; $ActualWindowSens = whatever Case Else ;Checks if $WindowSensInput = any other value not stated Msgbox(16,"Error","Your value is outside the range allowed") EndSwitch Srex 1 Please correct me if I am wrong in any of my posts. I like learning from my mistakes too. Link to comment Share on other sites More sharing options...
Geir1983 Posted June 4, 2014 Share Posted June 4, 2014 No, your $ActualWindowsSens is always 0, therefore you do not execute any of the Case. I think you want to use Switch on $WindowsSensInput? The Switch Case then evaluates the value of that variable and executes the code below, all your following IF testing is then not needed.. Srex 1 Link to comment Share on other sites More sharing options...
guinness Posted June 4, 2014 Share Posted June 4, 2014 Or you could use an array...it depends on your comfortability level. #include <MsgBoxConstants.au3> Local $aOutcomes[10] = [1, 2, 100, 24, 8, 90, 76, 65, 7, 99], _ $iOutcome = 9 If $iOutcome >= 0 And $iOutcome < UBound($aOutcomes) Then MsgBox($MB_SYSTEMMODAL, '', $aOutcomes[$iOutcome]) EndIf Srex 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Srex Posted June 4, 2014 Author Share Posted June 4, 2014 (edited) Not quite... You don't need the IFs - the CASE does the IF work for you. Switch $WindowSensInput Case 1 ;Checks if $WindowSensInput = 1 $ActualWindowSens = 0.031 Case 2 ;Checks if $WindowSensInput = 2 $ActualWindowSens = 0.222 Case 3 ;Checks if $WindowSensInput = 3 $ActualWindowSens = 0.333 ; Case n ;Checks if $WindowSensInput = n ; $ActualWindowSens = whatever Case Else ;Checks if $WindowSensInput = any other value not stated Msgbox(16,"Error","Your value is outside the range allowed") EndSwitch Aaaah so n = the number it checks for? thanks alot! Or you could use an array...it depends on your comfortability level. #include <MsgBoxConstants.au3> Local $aOutcomes[10] = [1, 2, 100, 24, 8, 90, 76, 65, 7, 99], _ $iOutcome = 9 If $iOutcome >= 0 And $iOutcome < UBound($aOutcomes) Then MsgBox($MB_SYSTEMMODAL, '', $aOutcomes[$iOutcome]) EndIfYeah then I could feel we stepped it up a few levels . Haha thanks for stopping by.. Maybe one day I'll be more comfortable And thanks for your help guys really appreciate you being so nice ! Edited June 4, 2014 by Srex Link to comment Share on other sites More sharing options...
guinness Posted June 4, 2014 Share Posted June 4, 2014 No problem. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
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