FrancescoDiMuro Posted February 6, 2017 Posted February 6, 2017 (edited) Good morning guys How are you? Hope you're fine I'm doing some field checking... Can you suggest me something? Something like: If the user doesn't prompt anything in a field, MsgBox and focus on the "blank" field, else, keep up with the script. I thought on a nested If...Else, but I have something like 10+ edit to control... Thanks guys! EDIT: And I would like to know either how to retrieve all listview item ( 2 columns ) from a ListView... Column A|Column B abcd | 1234 bcda | 1432 How can I retrieve an array with abcd|1234|bcda|1432 ? Thanks Edited February 6, 2017 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Danyfirex Posted February 6, 2017 Posted February 6, 2017 You can do something like this. expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIToolTip.au3> ; Create a GUI with various controls. Global $hGUI = GUICreate("Example", 210, 670) Global $idBtnCheck = GUICtrlCreateButton("Check", 60, 630, 80, 30) Global $aEdit[20] For $i = 0 To UBound($aEdit) - 1 $aEdit[$i] = GUICtrlCreateInput("", 30, ($i + 1) * 30, 150,20) Next ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBtnCheck If _CheckEdits() Then MsgBox(0,"","All fields OK") EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) Func _CheckEdits() For $i=0 to UBound($aEdit)-1 If GUICtrlRead($aEdit[$i])="" Then ConsoleWrite($i & @CRLF) Local $aGUIPos = WinGetPos($hGUI) Local $aCtrlPos = ControlGetPos($hGUI, "", $aEdit[$i]) ToolTip("You must fill this input", $aGUIPos[0] + $aCtrlPos[0] + 150, $aGUIPos[1] + $aCtrlPos[1] + 30,"",0,1) AdlibRegister(_HideToolTip,2000) _ColorNotification($aEdit[$i]) Return False EndIf Next Return True EndFunc Func _ColorNotification($ID) For $i=1 to 15 GUICtrlSetBkColor($ID,Random(0, 0xFFFFFF, 1)) Sleep(50) Next GUICtrlSetBkColor($ID,0xFFFFFF) EndFunc Func _HideToolTip() ToolTip("") AdlibUnRegister(_HideToolTip) EndFunc Saludos FrancescoDiMuro 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
Subz Posted February 6, 2017 Posted February 6, 2017 For your latter query: _GUICtrlListView_GetItemTextArray
FrancescoDiMuro Posted February 6, 2017 Author Posted February 6, 2017 @Danyfirex Thanks for your reply It's literally what I was looking for... But, I was asking to me... There's nothing a little "easier"? Because, I have edit(s) with different names, so, I don't know how to apply your great code to my case... 4 minutes ago, Subz said: For your latter query: _GUICtrlListView_GetItemTextArray I did with that function, but it returns me an array with a number instead of data... Thanks guys Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Danyfirex Posted February 6, 2017 Posted February 6, 2017 If you want to apply to your code just create the array $aEdit with the id of your inputs. If you have 3 inputs just do global $aEdit[3]=[$yourinput1,$yourinput2,$yourinput3] and add the required functions. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
FrancescoDiMuro Posted February 6, 2017 Author Posted February 6, 2017 @Danyfirex And If I have these edit in a function, how can I do it? I have something like this: ; I work with Opt(GUIOnEventMode, "1")... Global $input_1 Func Example() $sInput = GUICtrlRead($input_1) ; There's no other way to get what I would like to do ( see above ) ; If all "required" inputs have been filled, then do a query... EndFunc Thanks for your help Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
jguinch Posted February 6, 2017 Posted February 6, 2017 @Danyfirex : you can replace WinGetPos($hGUI) + ControlGetPos($hGUI, "", $aEdit[$i]) by WinGetPos( GUICtrlGetHandle( $aEdit[$i] ) ) WinGetPos works with controls. Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Danyfirex Posted February 6, 2017 Posted February 6, 2017 It should be something like this: Global $input_1,$input_2,$input_3 Global $aEdit[3] Func Example() $sInput1 = GUICtrlRead($input_1) $sInput2 = GUICtrlRead($input_2) $sInput3 = GUICtrlRead($input_3) $aEdit[0]=$input_1 $aEdit[1]=$input_2 $aEdit[2]=$input_3 ; There's no other way to get what I would like to do ( see above ) ; If all "required" inputs have been filled, then do a query... ;in Your botton or event add If _CheckEdits() Then ;do the query EndIf EndFunc @jguinch I know. I just stole a Melba23's old snippet. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
FrancescoDiMuro Posted February 6, 2017 Author Posted February 6, 2017 @jguinch, @Danyfirex What about the reading of a listview? Thanks Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Subz Posted February 6, 2017 Posted February 6, 2017 You can try the following function, just change the second parameter to False to return a string or True for an Array Func _GuiCtrlListView_GetArray($hWnd, $bArray = True) Local $iListView = _GUICtrlListView_GetItemCount($hWnd) Local $aListViewItem If $iListView > 0 Then Local $aListView[1][_GUICtrlListView_GetColumnCount($hWnd)] For $i = 0 To $iListView - 1 $aListViewItem = _GUICtrlListView_GetItemTextArray($hWnd, $i) _ArrayDelete($aListViewItem, 0) _ArrayTranspose($aListViewItem) _ArrayAdd($aListView, _ArrayToString($aListViewItem)) Next EndIf $aListView[0][0] = UBound($aListView) - 1 If $bArray = True Then Return $aListView Else $sListView = _ArrayToString($aListView, '|', 1, -1, '|') Return $sListView EndIf EndFunc
FrancescoDiMuro Posted February 6, 2017 Author Posted February 6, 2017 @Subz It works perfectly, thanks! But, why does _GUICtrlListView_GetItemTextArray() doesn't work? Maybe I'm not using it properly? Theoretically, If I use it in this way: Local $aArray = _GUICtrlListView_GetItemTextArray($lv_Listview) _ArrayDisplay($aArray) it should return all the listview item, or not? Because, in my case, it returns just the number 2... Can you please explain me why? Thanks Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Subz Posted February 6, 2017 Posted February 6, 2017 It only gets one line item, however you need to give it the index of the row, if you don't it returns just the number of columns in your case 2.
FrancescoDiMuro Posted February 6, 2017 Author Posted February 6, 2017 @Subz Thanks for your explanation and for your help buddy! I mentioned you in my script as I promised to everyone who would help me Have a wonderful day Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
FrancescoDiMuro Posted February 7, 2017 Author Posted February 7, 2017 (edited) @Subz Good morning How can I access to single elements of the array that your function returns? Thanks EDIT: I found how... I asked because I don't know how to write them through _Excel_RangeWrite() EDIT2: The array returns with 1 blank line... How could I fix it? Thanks EDIT3: Done Edited February 7, 2017 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
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