Efo74 Posted July 10, 2020 Share Posted July 10, 2020 Hello Autoit Users, I have write with forum suggestions and snippets, this code, it works, but it is not confortable to handle when there are for example 10 or more Date controls in the form, how can I best handle for example 50 Date controls in the form with some for-next cicle, my date control is already an 1d array ... must I convert controls to 2d array. Can someone make me an example ? the code below is far from being done well. Date.au3 :rolleyes: Link to comment Share on other sites More sharing options...
Dan_555 Posted July 10, 2020 Share Posted July 10, 2020 (edited) Is this what you wanted to achieve ? : expandcollapse popup#include <GUIConstantsEx.au3> #include <Misc.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPISysWin.au3> #include <Date.au3> Local $InputMax = 50 $gui = GUICreate("", 300, 600) Global $aDataInput[$InputMax + 1] $y = 20 $z = 0 $zz = 0 For $x = 1 To $InputMax If $x > 25 And $zz = 0 Then ;Set the offset for the 2nd column $y = 170 $z = 550 $zz = 1 EndIf $aDataInput[0] = $aDataInput[0] + 1 ;$aDataInput[0] holds the number of available controls $aDataInput[$x] = _GUICtrlCreateDataGGMMAAAA($y, ($x * 22) - $z, 20) _DataGGMMAAAA_SetColors($aDataInput[$x], $COLOR_BLACK, $COLOR_SKYBLUE) Next _DataGGMMAAAA_SetFocus($aDataInput[1]) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND_DataGGMMAAAA") GUISetState() Local $hDLL = DllOpen("user32.dll") While 1 $nMsg = GUIGetMsg() If $nMsg = $GUI_EVENT_CLOSE Then ExitLoop For $x = 1 To $aDataInput[0] _ManageBackSpaceDataGGMMAAAA($aDataInput[$x], $hDLL) Next WEnd DllClose($hDLL) ;MsgBox(0,"",_DataGGMMAAAA_ReadData($aDataInput)) ;MsgBox(0,"",_DataGGMMAAAA_ReadData($aDataInput1)) ;******************************************************************************************************************************* Func WM_COMMAND_DataGGMMAAAA($hWnd, $Msg, $wParam, $lParam) ;******************************************************************************************************************************* $nNotifyCode = BitShift($wParam, 16) $nID = BitAND($wParam, 0x0000FFFF) $hCtrl = $lParam Local $x Switch $nNotifyCode Case $EN_UPDATE For $x = 1 To $aDataInput[0] Manage_WM_COMMAND_DataGGMMAAAA($aDataInput[$x], $hCtrl) Next EndSwitch EndFunc ;==>WM_COMMAND_DataGGMMAAAA ;******************************************************************************************************************************* Func _GUICtrlCreateDataGGMMAAAA($x_func, $y_Func, $AltezzaCampo_Func) ;******************************************************************************************************************************* $DimCampoGG = 20 $DimCampoMM = 20 $DimCampoAAAA = 40 $DimBarraSeparatore = 15 $DimFont = 10 $AttributoFont = 400 Local $aDataInput_Func[3] $aDataInput_Func[0] = GUICtrlCreateInput("", $x_func, $y_Func, $DimCampoGG, $AltezzaCampo_Func, $ES_NUMBER) GUICtrlSetLimit(-1, 2) GUICtrlSetFont($aDataInput_Func[0], $DimFont, $AttributoFont, 1) $aDataInput_Func[1] = GUICtrlCreateInput("", $x_func + $DimCampoGG + $DimBarraSeparatore, $y_Func, $DimCampoMM, $AltezzaCampo_Func, $ES_NUMBER) GUICtrlSetLimit(-1, 2) GUICtrlSetFont($aDataInput_Func[1], $DimFont, $AttributoFont, 1) $aDataInput_Func[2] = GUICtrlCreateInput("", $x_func + $DimCampoGG + $DimBarraSeparatore + $DimCampoMM + $DimBarraSeparatore, $y_Func, $DimCampoAAAA, $AltezzaCampo_Func, $ES_NUMBER) GUICtrlSetLimit(-1, 4) GUICtrlSetFont($aDataInput_Func[2], $DimFont, $AttributoFont, 1) GUICtrlCreateLabel("/", $x_func + $DimCampoGG, $y_Func, $DimBarraSeparatore, $AltezzaCampo_Func) GUICtrlSetColor(-1, $CLR_BLACK) GUICtrlSetFont(-1, $DimFont + 4, $AttributoFont, 1) GUICtrlSetStyle(-1, $ES_CENTER) GUICtrlCreateLabel("/", $x_func + $DimCampoGG + $DimBarraSeparatore + $DimCampoMM, $y_Func, $DimBarraSeparatore, $AltezzaCampo_Func) GUICtrlSetColor(-1, $CLR_BLACK) GUICtrlSetFont(-1, $DimFont + 4, $AttributoFont, 1) GUICtrlSetStyle(-1, $ES_CENTER) Return $aDataInput_Func EndFunc ;==>_GUICtrlCreateDataGGMMAAAA ;******************************************************************************************************************************* Func _ManageBackSpaceDataGGMMAAAA($aDataInput_Func, $IsPressed_DLL_Func) ;******************************************************************************************************************************* If _IsPressed("08", $IsPressed_DLL_Func) Then While _IsPressed("08", $IsPressed_DLL_Func) Sleep(25) WEnd If _WinAPI_GetFocus() = GUICtrlGetHandle($aDataInput_Func[2]) Then If StringLen(GUICtrlRead($aDataInput_Func[2])) = 0 Then GUICtrlSetState($aDataInput_Func[1], $GUI_FOCUS) EndIf Return 0 EndIf If _WinAPI_GetFocus() = GUICtrlGetHandle($aDataInput_Func[1]) Then If StringLen(GUICtrlRead($aDataInput_Func[1])) = 0 Then GUICtrlSetState($aDataInput_Func[0], $GUI_FOCUS) EndIf Return 0 EndIf EndIf EndFunc ;==>_ManageBackSpaceDataGGMMAAAA ;******************************************************************************************************************************* Func Manage_WM_COMMAND_DataGGMMAAAA($aDataInput_Func, $hCtrl_Func) ;******************************************************************************************************************************* ;Giorno If $hCtrl_Func = GUICtrlGetHandle($aDataInput_Func[0]) Then If Number(GUICtrlRead($aDataInput_Func[0])) > 31 Then GUICtrlSetData($aDataInput_Func[0], "") EndIf If StringLen(GUICtrlRead($aDataInput_Func[0])) = 2 Then GUICtrlSetState($aDataInput_Func[1], $GUI_FOCUS) EndIf Return 0 EndIf ;Mese If $hCtrl_Func = GUICtrlGetHandle($aDataInput_Func[1]) Then If Number(GUICtrlRead($aDataInput_Func[1])) > 12 Then GUICtrlSetData($aDataInput_Func[1], "") EndIf If StringLen(GUICtrlRead($aDataInput_Func[1])) = 2 Then GUICtrlSetState($aDataInput_Func[2], $GUI_FOCUS) EndIf Return 0 EndIf EndFunc ;==>Manage_WM_COMMAND_DataGGMMAAAA ;******************************************************************************************************************************* Func _DataGGMMAAAA_SetFocus($aDataInput_Func) ;******************************************************************************************************************************* GUICtrlSetState($aDataInput_Func[0], $GUI_FOCUS) EndFunc ;==>_DataGGMMAAAA_SetFocus ;******************************************************************************************************************************* Func _DataGGMMAAAA_ReadData($aDataInput_Func) ;******************************************************************************************************************************* $tmp_anno = GUICtrlRead($aDataInput_Func[2]) $tmp_mese = GUICtrlRead($aDataInput_Func[1]) $tmp_giorno = GUICtrlRead($aDataInput_Func[0]) If _DateIsValid($tmp_anno & "/" & $tmp_mese & "/" & $tmp_giorno) = 1 Then Return $tmp_giorno & "/" & $tmp_mese & "/" & $tmp_anno Else Return "" EndIf EndFunc ;==>_DataGGMMAAAA_ReadData ;******************************************************************************************************************************* Func _DataGGMMAAAA_SetColors($aDataInput_Func, $ColoreTestoCampi_Func, $ColoreBackground_TestoCampi_Func) ;******************************************************************************************************************************* For $i = 0 To UBound($aDataInput_Func) - 1 GUICtrlSetColor($aDataInput_Func[$i], $ColoreTestoCampi_Func) GUICtrlSetBkColor($aDataInput_Func[$i], $ColoreBackground_TestoCampi_Func) Next EndFunc ;==>_DataGGMMAAAA_SetColors p.s. assigning the x and y coordinates needs tweaking. Edited July 10, 2020 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Efo74 Posted July 11, 2020 Author Share Posted July 11, 2020 Thanks Dan_555 was just what i wanted. I didn't know you could do such a thing ... arrays with elements inside which are also arrays. Thanks for your help. :rolleyes: Link to comment Share on other sites More sharing options...
Efo74 Posted July 11, 2020 Author Share Posted July 11, 2020 Only one note, backspace no longer works ... I'm investigating. Thanks again. :rolleyes: Link to comment Share on other sites More sharing options...
Efo74 Posted July 11, 2020 Author Share Posted July 11, 2020 I noticed that even in my code the backspace doesn't work. that is, it works only for the first control. :rolleyes: Link to comment Share on other sites More sharing options...
Efo74 Posted July 11, 2020 Author Share Posted July 11, 2020 solved, _IsPressed was the problem put inside the procedure. Thanks again :rolleyes: Link to comment Share on other sites More sharing options...
Dan_555 Posted July 11, 2020 Share Posted July 11, 2020 (edited) Strange, but looks like my code shouldn't work, i have missed out that you are returning the array. Other/standard gui functions return the id of the control, and it would work in that case. I'v just used the array display to check it, and surprisingly the array does hold the returned array ! So it's all ok. Quote ... arrays with elements inside which are also arrays. I'v learned something new too ! Edited July 11, 2020 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Efo74 Posted July 11, 2020 Author Share Posted July 11, 2020 it was a surprise for me too. I hadn't tried your solution because I thought it wouldn't work. :rolleyes: 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