Giggo Posted February 11, 2022 Posted February 11, 2022 (edited) Hello Forum! I have to save a lot of data in individual boxes, I tried to modify one of your files found on the forum, the modification works well but I think I have created something spartan, I kindly ask for solutions for a more elegant version of this... Thanks! expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Compression=4 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <SQLite.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $DB, $num = 1 _SQLite_Startup() _FileEx() $hGui = GUICreate("Sqlite GUI test", 1150, 650, -1, -1) $e_Edit1 = GUICtrlCreateEdit("", 130, 5, 500, 600) GUICtrlSetLimit($e_Edit1, 0xF423F) $e_Edit2 = GUICtrlCreateEdit("", 640, 5, 500, 600) GUICtrlSetLimit($e_Edit2, 0xF423F) $e_Edit3 = GUICtrlCreateEdit("", 130, 5, 500, 600) GUICtrlSetLimit($e_Edit3, 0xF423F) GUICtrlSetState(-1, $GUI_HIDE) $e_Edit4 = GUICtrlCreateEdit("", 640, 5, 500, 600) GUICtrlSetLimit($e_Edit4, 0xF423F) GUICtrlSetState(-1, $GUI_HIDE) $b_add1 = GUICtrlCreateButton("Add", 131, 616, 75, 25) $b_del1 = GUICtrlCreateButton("Delete", 208, 616, 75, 25) $b_del2 = GUICtrlCreateButton("Delete2", 208, 616, 75, 25) GUICtrlSetState(-1, $GUI_HIDE) $b_Show1 = GUICtrlCreateButton("Mostra 1", 5, 5, 120, 30) $b_Show2 = GUICtrlCreateButton("Mostra 2", 5, 45, 120, 30) GUISetState(@SW_SHOW) _query($num) While true $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _dbclose() Case $b_Show1 GUICtrlSetState($e_Edit3, $GUI_HIDE) GUICtrlSetState($e_Edit4, $GUI_HIDE) GUICtrlSetState($e_Edit1, $GUI_SHOW) GUICtrlSetState($e_Edit2, $GUI_SHOW) GUICtrlSetState($b_del2, $GUI_HIDE) GUICtrlSetState($b_del1, $GUI_SHOW) Case $b_Show2 GUICtrlSetState($e_Edit1, $GUI_HIDE) GUICtrlSetState($e_Edit2, $GUI_HIDE) GUICtrlSetState($e_Edit3, $GUI_SHOW) GUICtrlSetState($e_Edit4, $GUI_SHOW) GUICtrlSetState($b_del1, $GUI_HIDE) GUICtrlSetState($b_del2, $GUI_SHOW) Case $b_add1 GUICtrlRead($e_Edit1) GUICtrlRead($e_Edit2) GUICtrlRead($e_Edit3) GUICtrlRead($e_Edit4) _add($num) Case $b_del1 _del($num) Case $b_del2 _del2($num) EndSwitch WEnd GUIDelete() Func _dbclose() _SQLite_Close() _SQLite_Shutdown() Exit EndFunc Func _FileEx() If NOT FileExists("database.db") Then $DB=_SQLite_Open("database.db") _SQLite_Exec(-1,"CREATE TABLE database (id,name,a,b,c);") Else $DB=_SQLite_Open("database.db") EndIf EndFunc Func _add($I_D) Local $ARR $str1 = GUICtrlRead($e_Edit1) $str2 = GUICtrlRead($e_Edit2) $str3 = GUICtrlRead($e_Edit3) $str4 = GUICtrlRead($e_Edit4) _SQLite_QuerySingleRow($DB,"SELECT id FROM database WHERE id='"&$I_D&"'",$ARR) If $ARR[0] <> "" Then _SQLite_Exec($DB,"UPDATE database SET name='"&$str1&"', a='"&$str2&"', b='"&$str3&"', c='"&$str4&"' WHERE id='"&$I_D&"'") Else _SQLite_Exec($DB,"INSERT INTO database (id,name,a,b,c) VALUES ('"&$num&"','"&$str1&"','"&$str2&"','"&$str3&"','"&$str4&"');") EndIf EndFunc Func _query($I_D) GUICtrlSetData($e_Edit1,"") GUICtrlSetData($e_Edit2,"") GUICtrlSetData($e_Edit3,"") GUICtrlSetData($e_Edit4,"") Local $ARR If _SQLite_QuerySingleRow($DB,"SELECT * FROM database WHERE id='"&$I_D&"'",$ARR) == $SQLITE_OK Then If $ARR[0] == "" Then MsgBox(0,"ERROR","Query error!") Else GUICtrlSetData($e_Edit1,$ARR[1]) GUICtrlSetData($e_Edit2,$ARR[2]) GUICtrlSetData($e_Edit3,$ARR[3]) GUICtrlSetData($e_Edit4,$ARR[4]) EndIf EndIf EndFunc ;~ 1 Func _del($I_D) Local $ARR GUICtrlSetData($e_Edit1,"") GUICtrlSetData($e_Edit2,"") _SQLite_QuerySingleRow($DB,"SELECT id FROM database WHERE id='"&$I_D&"'",$ARR) If $ARR[0] <> "" Then _SQLite_Exec($DB,"DELETE FROM database WHERE id='"&$I_D&"'") EndIf EndFunc ;~ 2 Func _del2($I_D) Local $ARR GUICtrlSetData($e_Edit3,"") GUICtrlSetData($e_Edit4,"") _SQLite_QuerySingleRow($DB,"SELECT id FROM database WHERE id='"&$I_D&"'",$ARR) If $ARR[0] <> "" Then _SQLite_Exec($DB,"DELETE FROM database WHERE id='"&$I_D&"'") EndIf EndFunc ;~ _del2() cancell all edit Edited February 11, 2022 by Giggo
Deye Posted February 11, 2022 Posted February 11, 2022 (edited) First try to implement this example into your script. and see what works for you ; at the top of your script set an array size that will match the number of controls you want to read Global $ARR[10] ; gui and controls creation .etc For $i = 1 To UBound($ARR) - 1 $ARR[$i] = GUICtrlRead(Eval("e_Edit" & $i)) Next _arraydisplay($ARR) Or otherwise use\run your controls straight from an array where you read the controls from $agui[$i][0] that keeps a control's id in example 1 till 4 #include <File.au3> #include <GuiEdit.au3> $hGui = GUICreate("Sqlite GUI test", 1150, 650, -1, -1) Local $VGui = '' _ & 'Ctrl|Placement|GUICtrlCreate|Name|' _ & @CRLF & 'id|, 130, 5, 500, 200|Edit|' _ & @CRLF & 'id|, 640, 5, 500, 200|Edit|' _ & @CRLF & 'id|, 130, 200, 500, 200|Edit|' _ & @CRLF & 'id|, 640, 200, 500, 200|Edit|' _ & @CRLF & 'id|, 131, 616, 75, 25|Button|Add' _ & @CRLF & 'id|, 208, 616, 75, 25|Button|Delete' _ & @CRLF & 'id|, 208, 616, 75, 25|Button|Delete2' _ & @CRLF & 'id|, 5, 5, 120, 30|Button|Mostra 1' _ & @CRLF & 'id|, 5, 45, 120, 30|Button|Mostra 2' Local $aGui[0][5] _ArrayAdd($aGui, $VGui) For $i = 1 To UBound($aGui) - 1 $aGui[$i][0] = Execute("GUICtrlCreate" & $aGui[$i][2] & '("' & ($aGui[$i][3] ? $aGui[$i][3] & '"' : '"') & $aGui[$i][1] & ")") Next For $i = 1 To 4 _GUICtrlEdit_SetText($aGui[$i][0], "test" & $i) Next GUISetState(@SW_SHOW) For $i = 1 To 4 $aGui[$i][4] = GUICtrlRead($aGui[$i][0]) Next _ArrayDisplay($aGui) Edited February 11, 2022 by Deye Giggo 1
Giggo Posted February 11, 2022 Author Posted February 11, 2022 i understand what your code does but i doubt i can implement it in the code i posted 😬, thank you for your support 🙂
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