FrancescoDiMuro Posted June 16, 2016 Share Posted June 16, 2016 Good mornign everyone. How are you? Hope fine. My today's questione is: "How can I set a focus on a input ( code ) if an error has occured?" GUICtrlCreateInput Best explanation... I make a control on $cPath and $cIstances... How can I set a focus on each of them if the control is not passed? And consequently, how can I make loop it until the control is passed? Because I don't want to store the content of $cPath and $cIstances until they don't pass the controls. I tried with create a variable in which store a bit with the "control passed or not", so I can keep this loop but, I know that is not so funcionally as it seems. By the way, thanks again to M23 who has suggested me the ".ini strategy". Thanks to all. I felt in love with this language! expandcollapse popup; ===== Include section ===== #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> ;===== INI Variables section ===== Local Const $Config = "configurazione.ini" Local Const $cSection = "CONFIG" Local Const $cKey1 = "PATH" Local Const $cKey2 = "ISTANCES" Local $cKeyValue1 = "", $cKeyValue2 = "", $cPath, $cIstances, $CheckPath, $CheckIstances ;===== Does the .ini file exist? ===== If NOT FileExists($Config) Then IniWrite($Config, $cSection, $cKey1, $cKeyValue1) IniWrite($Config, $cSection, $cKey2, $cKeyValue2) Else $cPath = IniRead($Config, $cSection, $cKey1, "-1") $cIstances = IniRead($Config, $cSection, $cKey2, "-1") ;===== GUI Creation ===== $Form = GUICreate("MULTISCREEN",300,130) Local $Label1 = GUICtrlCreateLabel("Percorso:",10,10,280,20) Local $Input1 = GUICtrlCreateInput($cPath,10,30,280,20) Local $Label2 = GUICtrlCreateLabel("Istanze:",10,55,280,20) Local $Input2 = GUICtrlCreateInput($cIstances,10,75,40,20) Local $Label3 = GUICtrlCreateLabel("Scrivi il numero di volte che il programma dev'essere lanciato",52.5,72.5,280,30) Local $Button1 = GUICtrlCreateButton("Salva",200,100,40,20) Local $Button2 = GUICtrlCreateButton("Invia",250,100,40,20) While 1 GUISetState(@SW_SHOW) Switch GUIGetMsg() Case $Button1 $cPath = GUICtrlRead($Input1,0) $cIstances = GUICtrlRead($Input2,0) Do If StringIsAlNum($cPath) = 0 Then MsgBox($MB_ICONERROR,"ERRORE!","Il testo inserito non è alfanumerico." & @CRLF & "Inserire un indirizzo valido.") $CheckPath = 0 Else $CheckPath = 1 EndIf Until $CheckPath = 1 Do If StringIsInt($cIstances) = 0 Then MsgBox($MB_ICONERROR, "ERRORE","Il valore inserito non è intero." & @CRLF & "Inserire un numero valido.") $CheckIstances = 0 Else If $cIstances < 2 OR $cIstances > 4 Then MsgBox($MB_ICONERROR, "ERRORE!", "Il numero non può essere minore di 2 o più grande di 4." & @CRLF & "Inserire un numero valido.") $CheckIstances = 0 EndIf EndIf Until $CheckIstances = 1 IniWrite($Config, $cSection, $cKey1, $cPath) IniWrite($Config, $cSection, $cKey2, $cIstances) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd EndIf Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 16, 2016 Moderators Share Posted June 16, 2016 (edited) FrancesoDiMuro, Something like this should work: While 1 GUISetState(@SW_SHOW) Switch GUIGetMsg() Case $Button1 $cPath = GUICtrlRead($Input1, 0) $cIstances = GUICtrlRead($Input2, 0) If StringIsAlNum($cPath) = 0 Then MsgBox($MB_ICONERROR, "ERRORE!", "Il testo inserito non è alfanumerico." & @CRLF & "Inserire un indirizzo valido.") GUICtrlSetState($Input1, $GUI_FOCUS) Else If StringIsInt($cIstances) = 0 Then MsgBox($MB_ICONERROR, "ERRORE", "Il valore inserito non è intero." & @CRLF & "Inserire un numero valido.") GUICtrlSetState($Input2, $GUI_FOCUS) Else MsgBox(0, "CHECKED", "Writing to ini file") ;IniWrite($Config, $cSection, $cKey1, $cPath) ;IniWrite($Config, $cSection, $cKey2, $cIstances) EndIf EndIf Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd M23 Edit: Sorry - forgot the focus bit. Edited June 16, 2016 by Melba23 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...
FrancescoDiMuro Posted June 16, 2016 Author Share Posted June 16, 2016 Thanks a lot M23. "The script works like a champ!" ( Cit. from a thread I've read over this forum! ) Just another question. I have to "send" the istances of the program I launch to several screens ( 4 screens )... I thought that I could do this with the Windows Key Combination "Shift + WinKey + Right Arrow ( or left )", sending them with the function Send() that made me discover this wonderful language. I thought something like this: $Index = 0 ; Indice che viene incrementato ogni qualvolta viene aperta un'istanza del file FileCheDeveEssereAperto.txt Do ShellExecute($sFileName & $sExtension, "", $sDrive & $sDir) Sleep(2000) Switch $Index Case 1 Send("+#{Right}") ; 2° Schermo - Combinazione di tasti che il programma "invia" al computer, la quale combinazione permette di shiftare la schermata verso destra ( per multischermi, schermi estesi! ) Case 2 Send("+#{Right}{Right}") ; 3° Schermo Case 3 Send("+#{Right}{Right}{Right}") ; {Right}{Right}{Right} ; 4° Schermo EndSwitch $Index += 1 Until $Index = $Line2 EndSwitch Tell me if it could be correct or it can be improved. I don't know how to say thank you, literally! Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 16, 2016 Moderators Share Posted June 16, 2016 FrancescoDiMuro, I would do it like this - using AutoIt to count the loop rather then doing it in the code: For $Index = 1 To $Line2 ; Indice che viene incrementato ogni qualvolta viene aperta un'istanza del file FileCheDeveEssereAperto.txt ShellExecute($sFileName & $sExtension, "", $sDrive & $sDir) Sleep(2000) Switch $Index Case 1 Send("+#{Right}") ; 2° Schermo - Combinazione di tasti che il programma "invia" al computer, la quale combinazione permette di shiftare la schermata verso destra ( per multischermi, schermi estesi! ) Case 2 Send("+#{Right}{Right}") ; 3° Schermo Case 3 Send("+#{Right}{Right}{Right}") ; {Right}{Right}{Right} ; 4° Schermo EndSwitch Next M23 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...
FrancescoDiMuro Posted June 16, 2016 Author Share Posted June 16, 2016 Yeah, it works fine. I don't know if it will work when I'll connect 4 screens. Will it send the same program to different screens? Does exist other ways to have the same result? Thank you M23. Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 16, 2016 Moderators Share Posted June 16, 2016 FrancescoDiMuro, As we have no idea what program you are running and how it reacts, how can we answer? WinMove might well be another solution worth investigating. M23 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...
FrancescoDiMuro Posted June 16, 2016 Author Share Posted June 16, 2016 As I have te opportunity to test out the script, you'll be the first person I'll write to. Thanks a lot M23. Have a wonderful day. -Francesco Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette 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