kor Posted March 14, 2012 Share Posted March 14, 2012 (edited) Func _DisableInput($n1, $n2, $n3, $n4) GUICtrlSetState($n1, $GUI_DISABLE) GUICtrlSetState($n2, $GUI_DISABLE) GUICtrlSetState($n3, $GUI_DISABLE) GUICtrlSetState($n4, $GUI_DISABLE) EndFunc ;==>_DisableInput _DisableInput($aInput[0][0], $aInput[1][0], $aInput[2][0], $aInput[3][0]) The above works if I want to disable all 4 inputs. But if I only want to disable 3 and thus remove the $aInput[3][0] from the function call I get an error saying incorrect number of parameters. Basically I want to be able to disable X number of inputs up to a maximum of 4. Edited March 14, 2012 by kor Link to comment Share on other sites More sharing options...
water Posted March 14, 2012 Share Posted March 14, 2012 (edited) To make a parameter optional you have to set a default value in the parameter list. In this case I used the keyword Default but it could be any other value like 0 or "". Func _DisableInput($n1, $n2 = Default, $n3 = Default, $n4 = Default) GUICtrlSetState($n1, $GUI_DISABLE) If $n2 <> Default Then GUICtrlSetState($n2, $GUI_DISABLE) If $n3 <> Default Then GUICtrlSetState($n3, $GUI_DISABLE) If $n4 <> Default Then GUICtrlSetState($n4, $GUI_DISABLE) EndFunc ;==>_DisableInput Edited March 14, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
guinness Posted March 14, 2012 Share Posted March 14, 2012 (edited) Like this, now only the first parameter is mandatory as why would you use this without using at least one parameter. Func _DisableInput($n1, $n2 = -1, $n3 = -1, $n4 = -1) Local $aArray[5] = [4, $n1, $n2, $n3, $n4] For $i = 1 To $aArray[0] If $aArray[$i] = -1 Then ContinueLoop EndIf GUICtrlSetState($aArray[$i], $GUI_DISABLE) Next EndFunc ;==>_DisableInput Plus I love using loops, because you can adapt this to 15 parameters without adding more lines. Edited March 14, 2012 by guinness 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...
kor Posted March 14, 2012 Author Share Posted March 14, 2012 water, thank you! it's working now. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 14, 2012 Moderators Share Posted March 14, 2012 (edited) kor, Use arrays. Put all the ControlIDs into one array and then pass another array as a parameter to the function. tehn you can have as many as you want: expandcollapse popup#include <guiconstantsex.au3> Global $aInput[4], $aState[4] $hGUI = GUICreate("Test", 500, 500) For $i = 0 To 3 $aInput[$i] = GUICtrlCreateInput("", 10, 10 + (30 * $i), 200, 20) Next $cButton_1 = GUICtrlCreateButton("Disable #3", 10, 200, 100, 30) $cButton_2 = GUICtrlCreateButton("Disable #1 && #2", 10, 250, 100, 30) $cButton_3 = GUICtrlCreateButton("Disable #2 && #4", 10, 300, 100, 30) $cButton_4 = GUICtrlCreateButton("Enable all", 10, 350, 100, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton_1 Global $aState [4] = [1, 1, 0, 1] _Set_Input_State() Case $cButton_2 Global $aState [4] = [0, 0, 1, 1] _Set_Input_State() Case $cButton_3 Global $aState [4] = [1, 0, 1, 0] _Set_Input_State() Case $cButton_4 Global $aState [4] = [1, 1, 1, 1] _Set_Input_State() EndSwitch WEnd Func _Set_Input_State() For $i = 0 To UBound($aState) - 1 If $aState[$i] = 1 Then GUICtrlSetState($aInput[$i], $GUI_ENABLE) Else GUICtrlSetState($aInput[$i], $GUI_DISABLE) EndIf Next EndFunc M23 Edited March 14, 2012 by Melba23 Wrong button, too soon! 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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