Giggo Posted February 5, 2022 Posted February 5, 2022 (edited) hello to all of the forum! i downloaded this script from the forum and adapted it to me, but the next button keeps going up indefinitely and should stop only at the last record found Script Autoit forums is: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=StarterDB_GUI.exe #AutoIt3Wrapper_UseX64=n ; ### Win32-DLL ### #AutoIt3Wrapper_Run_Tidy=y #AutoIt3Wrapper_Run_Au3Stripper=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; #Region ;************ Includes ************ #include <SQLite.au3> #include <ButtonConstants.au3> #EndRegion ;************ Includes ************ Global Const $SS_CENTER = 0x1 Global Const $SS_SUNKEN = 0x1000 Global Const $ES_AUTOHSCROLL = 128 Global Const $ES_READONLY = 2048 Global Const $GUI_EVENT_CLOSE = -3 Global Const $SS_SIMPLE = 0xB Global $dbn, $num = 1, $aStr[3] ; _SQLite_Startup() If Not FileExists("DataFile_DB.db") Then $dbn = _SQLite_Open("DataFile_DB.db") _SQLite_Exec(-1, "CREATE TABLE DataFile_DB (ID INTEGER PRIMARY KEY AUTOINCREMENT, Name, Surname, Address);") Else $dbn = _SQLite_Open("DataFile_DB.db") EndIf ; #Region ### START GUI section ### $hGui = GUICreate("Database", 1269, 805, -1, -1) ; ;---EditBox $e_edit1 = GUICtrlCreateEdit("", 5, 25, 250, 630) GUICtrlSetFont(-1, 12, 400, 0, "@Malgun Gothic") GUICtrlSetBkColor(-1, 0x333333) GUICtrlSetColor(-1, 0xFFFF00) $e_edit2 = GUICtrlCreateEdit("", 260, 25, 500, 630) GUICtrlSetBkColor(-1, 0xF0F0F0) GUICtrlSetFont(-1, 10, 400, 0, "@Malgun Gothic") $e_edit3 = GUICtrlCreateEdit("", 765, 25, 500, 630) GUICtrlSetFont(-1, 10, 400, 0, "@Malgun Gothic") GUICtrlSetBkColor(-1, 0xF0F0F0) GUICtrlSetFont(-1, 10, 400, 0, "@Malgun Gothic") ;--- ;---Bottoni $btnDel = GUICtrlCreateButton("-", 10, 664, 50, 50, $BS_ICON) GUICtrlSetTip(-1, "Delete Record") GUICtrlSetFont(-1, 24, 800, 0, "Bauhaus 93") $btnLeft = GUICtrlCreateButton("<", 64, 664, 50, 50) GUICtrlSetTip(-1, "Record Back") GUICtrlSetFont(-1, 24, 800, 0, "Bauhaus 93") $Count = GUICtrlCreateLabel($num, 125, 680, 50, 21, $SS_CENTER) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUICtrlSetTip(-1, "Record Count") $btnRight = GUICtrlCreateButton(">", 186, 664, 50, 50) GUICtrlSetTip(-1, "Record Next") GUICtrlSetFont(-1, 24, 800, 0, "Bauhaus 93") $btnAdd = GUICtrlCreateButton("+", 240, 664, 50, 50, $BS_ICON) GUICtrlSetTip(-1, "Add Record") GUICtrlSetFont(-1, 24, 800, 0, "Bauhaus 93") $btnSaveTxt = GUICtrlCreateButton("Save List", 340, 664, 100, 50, $BS_ICON) GUICtrlSetTip(-1, "Save Text to list.txt") GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") $btnOpenTxt = GUICtrlCreateButton("Open List", 450, 664, 100, 50, $BS_ICON) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUICtrlSetTip(-1, "Open list.txt") ;--- ;--- Label $tatuslabel = GUICtrlCreateLabel("_SQLite_Version = " & _SQLite_LibVersion(), 1130, 790, 200, 16) GUICtrlSetFont(-1, 8, 400, 0, "@Malgun Gothic") $statuslabel = GUICtrlCreateLabel("", 5, 780, 200, 20) GUICtrlSetFont(-1, 11, 400, 0, "@Malgun Gothic") GUICtrlSetTip(-1, "Total records found") ;--- GUISetState(@SW_SHOW) #EndRegion ### START GUI section ### ; _query($num) _SQLite_CountRows('DataFile_DB') ; While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _quit() Case $btnOpenTxt ShellExecute("list.txt") Case $btnRight $num += 1 GUICtrlSetData($Count, $num) _query($num) Case $btnLeft If $num == 1 Then $num = 1 GUICtrlSetData($Count, $num) Else $num -= 1 GUICtrlSetData($Count, $num) _query($num) EndIf Case $btnAdd If GUICtrlRead($e_edit1) == "" Then MsgBox ($MB_ICONERROR + $MB_TOPMOST, "ERROR", "Box is empty!") Else _add($num) Sleep(500) SplashTextOn("Database", "Database saved", 300, 50, Default, Default, 33) Sleep(2000) SplashOff() EndIf Case $btnSaveTxt $hFile = "list.txt" FileDelete("list.txt") $read = GUICtrlRead($e_edit1) $read1 = GUICtrlRead($e_edit2) $read2 = GUICtrlRead($e_edit3) If $read <> "" Then $hFile = FileOpen(@ScriptDir & '\list.txt', 128 + 1) ;FileWrite($hFile, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CRLF) FileWrite($hFile, $read & @CR) ;FileWrite($hFile, "" & @CRLF) FileWrite($hFile, $read1 & @CRLF) ;FileWrite($hFile, "" & @CRLF) FileWrite($hFile, $read2 & @CRLF) ;FileWrite($hFile, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CRLF) EndIf Sleep(300) SplashTextOn("Save Text", "Text saved", 300, 50, Default, Default, 33) Sleep(1000) SplashOff() Case $btnDel $t = MsgBox ($MB_YESNO + $MB_TOPMOST, "Delete Record" ,"You want to delete this record?") If $t = 6 Then _del($num) ElseIf $t = 7 Then endif EndSwitch WEnd ; Func _quit() _SQLite_Close() _SQLite_Shutdown() Exit EndFunc ;==>_quit ; Func _query($id) _clear() Local $retarr If _SQLite_QuerySingleRow($dbn, "SELECT * FROM DataFile_DB WHERE id='" & $id & "'", $retarr) == $SQLITE_OK Then If $retarr[0] == "" Then MsgBox ($MB_ICONERROR + $MB_TOPMOST, "ERROR" ,"Error Query!") Else GUICtrlSetData($e_edit1, $retarr[1]) GUICtrlSetData($e_edit2, $retarr[2]) GUICtrlSetData($e_edit3, $retarr[3]) EndIf EndIf EndFunc ;==>_query ; Func _add($id) _readipt() Local $retarr _SQLite_QuerySingleRow($dbn, "SELECT id FROM DataFile_DB WHERE id='" & $id & "'", $retarr) If $retarr[0] <> "" Then _SQLite_Exec($dbn, "UPDATE DataFile_DB SET Name='" & $aStr[0] & "', Surname='" & $aStr[1] & "',Address='" & $aStr[2] & "' WHERE id='" & $id & "'") Else _SQLite_Exec($dbn, "INSERT INTO DataFile_DB (ID,Name,Surname,Address) VALUES ('" & $num & "','" & $aStr[0] & "','" & $aStr[1] & "','" & $aStr[2] & "');") EndIf _SQLite_CountRows('DataFile_DB') EndFunc ;==>_add ; Func _del($id) _clear() Local $retarr _SQLite_QuerySingleRow($dbn, "SELECT id FROM DataFile_DB WHERE id='" & $id & "'", $retarr) If $retarr[0] <> "" Then _SQLite_Exec($dbn, "DELETE FROM DataFile_DB WHERE id='" & $id & "'") EndIf _SQLite_CountRows('DataFile_DB') EndFunc ;==>_del ; Func _clear() GUICtrlSetData($e_edit1, "") GUICtrlSetData($e_edit2, "") GUICtrlSetData($e_edit3, "") EndFunc ;==>_clear ; Func _readipt() $aStr[0] = GUICtrlRead($e_edit1) $aStr[1] = GUICtrlRead($e_edit2) $aStr[2] = GUICtrlRead($e_edit3) EndFunc ;==>_readipt ; Func _SQLite_CountRows($_sTable) Local $hQuery, $aQuery, $iRet = 0, $iErr If $SQLITE_OK <> _SQLite_Query(-1, "SELECT count(*) FROM " & $_sTable & ";", $hQuery) Then $iErr = _SQLite_ErrCode() _SQLite_QueryFinalize($hQuery) Return SetError(1, $iErr, -1) EndIf While _SQLite_FetchData($hQuery, $aQuery) = $SQLITE_OK $iRet = $aQuery[0] WEnd _SQLite_QueryFinalize($hQuery) ;~ Return $iRet GUICtrlSetData($statuslabel, " Total Records = " & $iRet) EndFunc ;==>_SQLite_CountRows ; Ende this script was downloaded from the forum, thanks to the author I'm translating from google Edited February 5, 2022 by Giggo
Nine Posted February 5, 2022 Posted February 5, 2022 (edited) Maybe this ? .... Case $btnRight If _query($num + 1) Then $num += 1 GUICtrlSetData($Count, $num) EndIf .... Func _query($id) Local $retarr If _SQLite_QuerySingleRow($dbn, "SELECT max(id) FROM DataFile_DB;", $retarr) <> $SQLITE_OK Then Return False If Not $retarr[0] Or $id > Number($retarr[0]) Then Return False _SQLite_QuerySingleRow($dbn, "SELECT * FROM DataFile_DB WHERE id='" & $id & "';", $retarr) _clear() If $retarr[0] Then GUICtrlSetData($e_edit1, $retarr[1]) GUICtrlSetData($e_edit2, $retarr[2]) GUICtrlSetData($e_edit3, $retarr[3]) EndIf Return True EndFunc ;==>_query Untested. Tried to run your script from scratch, but it is not working for me. I get arrays errors and I do not feel to debug the whole thing. Edited February 5, 2022 by Nine Giggo 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
Giggo Posted February 5, 2022 Author Posted February 5, 2022 (edited) 4 hours ago, Nine said: Maybe this ? .... Case $btnRight If _query($num + 1) Then $num += 1 GUICtrlSetData($Count, $num) EndIf .... Func _query($id) Local $retarr If _SQLite_QuerySingleRow($dbn, "SELECT max(id) FROM DataFile_DB;", $retarr) <> $SQLITE_OK Then Return False If Not $retarr[0] Or $id > Number($retarr[0]) Then Return False _SQLite_QuerySingleRow($dbn, "SELECT * FROM DataFile_DB WHERE id='" & $id & "';", $retarr) _clear() If $retarr[0] Then GUICtrlSetData($e_edit1, $retarr[1]) GUICtrlSetData($e_edit2, $retarr[2]) GUICtrlSetData($e_edit3, $retarr[3]) EndIf Return True EndFunc ;==>_query Untested. Tried to run your script from scratch, but it is not working for me. I get arrays errors and I do not feel to debug the whole thing. You code working ok! sorry :(... I fixed the old code and added your code, now it works but I will have to add a new button to add a new one expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=StarterDB_GUI.exe #AutoIt3Wrapper_UseX64=n ; ### Win32-DLL ### #AutoIt3Wrapper_Run_Tidy=y #AutoIt3Wrapper_Run_Au3Stripper=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; #Region ;************ Includes ************ #include <SQLite.au3> #include <ButtonConstants.au3> #EndRegion ;************ Includes ************ Global Const $SS_CENTER = 0x1 Global Const $SS_SUNKEN = 0x1000 Global Const $ES_AUTOHSCROLL = 128 Global Const $ES_READONLY = 2048 Global Const $GUI_EVENT_CLOSE = -3 Global Const $SS_SIMPLE = 0xB Global $dbn, $num = 1, $aStr[3] ; _SQLite_Startup() If Not FileExists("Famiglia_DB.db") Then $dbn = _SQLite_Open("Famiglia_DB.db") _SQLite_Exec(-1, "CREATE TABLE Famiglia_DB (ID INTEGER PRIMARY KEY AUTOINCREMENT, Name, Cognome, Indirizzo);") Else $dbn = _SQLite_Open("Famiglia_DB.db") EndIf ; #Region ### START GUI section ### $hGui = GUICreate("Family Database", 1269, 805, -1, -1) ; ;---EditBox $e_edit1 = GUICtrlCreateEdit("", 5, 25, 250, 630) GUICtrlSetFont(-1, 12, 400, 0, "@Malgun Gothic") GUICtrlSetBkColor(-1, 0x333333) GUICtrlSetColor(-1, 0xFFFF00) $e_edit2 = GUICtrlCreateEdit("", 260, 25, 500, 630) GUICtrlSetBkColor(-1, 0xF0F0F0) GUICtrlSetFont(-1, 10, 400, 0, "@Malgun Gothic") $e_edit3 = GUICtrlCreateEdit("", 765, 25, 500, 630) GUICtrlSetFont(-1, 10, 400, 0, "@Malgun Gothic") GUICtrlSetBkColor(-1, 0xF0F0F0) GUICtrlSetFont(-1, 10, 400, 0, "@Malgun Gothic") ;--- ;---Bottoni $btnDel = GUICtrlCreateButton("-", 10, 664, 50, 50, $BS_ICON) GUICtrlSetImage($btnDel,"icondb\Del.ico") GUICtrlSetTip(-1, "Elimina Record") $btnLeft = GUICtrlCreateButton("<", 64, 664, 50, 50) GUICtrlSetTip(-1, "Record Precedente") GUICtrlSetFont(-1, 24, 800, 0, "Bauhaus 93") $iptCount = GUICtrlCreateLabel($num, 125, 680, 50, 21, $SS_CENTER) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUICtrlSetTip(-1, "Conta i Record") $btnRight = GUICtrlCreateButton(">", 186, 664, 50, 50) GUICtrlSetTip(-1, "Record Successivo") GUICtrlSetFont(-1, 24, 800, 0, "Bauhaus 93") $btnAdd = GUICtrlCreateButton("+", 240, 664, 50, 50, $BS_ICON) GUICtrlSetImage($btnAdd,"icondb\Add.ico") GUICtrlSetTip(-1, "Aggiungi e Salva Record") $btnSaveTxt = GUICtrlCreateButton("Salva Testo", 340, 664, 50, 50, $BS_ICON) GUICtrlSetImage($btnSaveTxt,"icondb\save.ico") GUICtrlSetTip(-1, "Salva testo in lista.txt") $btnOpenTxt = GUICtrlCreateButton("Apri Testo", 395, 664, 50, 50, $BS_ICON) GUICtrlSetImage($btnOpenTxt,"icondb\Open.ico") GUICtrlSetTip(-1, "Apri lista.txt") ;--- ;--- Label $tatuslabel = GUICtrlCreateLabel("_SQLite_Version = " & _SQLite_LibVersion(), 1130, 790, 200, 16) GUICtrlSetFont(-1, 8, 400, 0, "@Malgun Gothic") $statuslabel = GUICtrlCreateLabel("", 5, 762, 200, 20) GUICtrlSetFont(-1, 11, 400, 0, "@Malgun Gothic") GUICtrlSetTip(-1, "Totale dei Record nel programma") ;--- GUISetState(@SW_SHOW) #EndRegion ### START GUI section ### ; _query($num) _SQLite_CountRows('Famiglia_DB') ; While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _quit() Case $btnOpenTxt If Not FileExists("lista.txt") Then MsgBox ($MB_ICONWARNING + $MB_TOPMOST, "ERRORE LISTA", "Il file [ lista.txt ] non è stato trovato!") Else ShellExecute("lista.txt") EndIf Case $btnRight If _query($num + 1) Then $num += 1 GUICtrlSetData($iptCount, $num) EndIf ;Case $btnRight ; $num += 1 ; GUICtrlSetData($iptCount, $num) ; _query($num) Case $btnLeft If $num == 1 Then $num = 1 GUICtrlSetData($iptCount, $num) Else $num -= 1 GUICtrlSetData($iptCount, $num) _query($num) EndIf Case $btnAdd If GUICtrlRead($e_edit1) == "" Then MsgBox ($MB_ICONERROR + $MB_TOPMOST, "ERRORE", "Casella Vuota!") Else _add($num) Sleep(500) SplashTextOn("Database", "Database Salvato", 300, 50, Default, Default, 33) Sleep(2000) SplashOff() EndIf Case $btnSaveTxt $hFile = "lista.txt" FileDelete("lista.txt") $read = GUICtrlRead($e_edit1) $read1 = GUICtrlRead($e_edit2) $read2 = GUICtrlRead($e_edit3) If $read <> "" Then $hFile = FileOpen(@ScriptDir & '\lista.txt', 128 + 1) ;FileWrite($hFile, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CRLF) FileWrite($hFile, $read & @CR) ;FileWrite($hFile, "" & @CRLF) FileWrite($hFile, $read1 & @CRLF) ;FileWrite($hFile, "" & @CRLF) FileWrite($hFile, $read2 & @CRLF) ;FileWrite($hFile, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CRLF) EndIf Sleep(300) SplashTextOn("SALVATAGGIO TESTO", "Testo Salvato", 300, 50, Default, Default, 33) Sleep(1000) SplashOff() Case $btnDel $t = MsgBox ($MB_YESNO + $MB_TOPMOST, "Eliminazione Record" ,"Vuoi eliminare questo record?") If $t = 6 Then _del($num) ElseIf $t = 7 Then endif EndSwitch WEnd ; Func _quit() _SQLite_Close() _SQLite_Shutdown() FileDelete("lista.txt") Exit EndFunc ;==>_quit ; Func _query($id) Local $retarr If _SQLite_QuerySingleRow($dbn, "SELECT max(id) FROM Famiglia_DB;", $retarr) <> $SQLITE_OK Then Return False If Not $retarr[0] Or $id > Number($retarr[0]) Then Return False _SQLite_QuerySingleRow($dbn, "SELECT * FROM Famiglia_DB WHERE id='" & $id & "';", $retarr) _clear() If $retarr[0] Then GUICtrlSetData($e_edit1, $retarr[1]) GUICtrlSetData($e_edit2, $retarr[2]) GUICtrlSetData($e_edit3, $retarr[3]) EndIf Return True EndFunc ;==>_query ;MsgBox ($MB_ICONERROR + $MB_TOPMOST, "ERRORE" ,"Errore Query!") ; Func _add($id) _readipt() Local $retarr _SQLite_QuerySingleRow($dbn, "SELECT id FROM Famiglia_DB WHERE id='" & $id & "'", $retarr) If $retarr[0] <> "" Then _SQLite_Exec($dbn, "UPDATE Famiglia_DB SET Name='" & $aStr[0] & "', Cognome='" & $aStr[1] & "',Indirizzo='" & $aStr[2] & "' WHERE id='" & $id & "'") Else _SQLite_Exec($dbn, "INSERT INTO Famiglia_DB (ID,Name,Cognome,Indirizzo) VALUES ('" & $num & "','" & $aStr[0] & "','" & $aStr[1] & "','" & $aStr[2] & "');") EndIf _SQLite_CountRows('Famiglia_DB') EndFunc ;==>_add ; Func _del($id) _clear() Local $retarr _SQLite_QuerySingleRow($dbn, "SELECT id FROM Famiglia_DB WHERE id='" & $id & "'", $retarr) If $retarr[0] <> "" Then _SQLite_Exec($dbn, "DELETE FROM Famiglia_DB WHERE id='" & $id & "'") EndIf _SQLite_CountRows('Famiglia_DB') EndFunc ;==>_del ; Func _clear() GUICtrlSetData($e_edit1, "") GUICtrlSetData($e_edit2, "") GUICtrlSetData($e_edit3, "") EndFunc ;==>_clear ; Func _readipt() $aStr[0] = GUICtrlRead($e_edit1) $aStr[1] = GUICtrlRead($e_edit2) $aStr[2] = GUICtrlRead($e_edit3) EndFunc ;==>_readipt ; Func _SQLite_CountRows($_sTable) Local $hQuery, $aQuery, $iRet = 0, $iErr If $SQLITE_OK <> _SQLite_Query(-1, "SELECT count(*) FROM " & $_sTable & ";", $hQuery) Then $iErr = _SQLite_ErrCode() _SQLite_QueryFinalize($hQuery) Return SetError(1, $iErr, -1) EndIf While _SQLite_FetchData($hQuery, $aQuery) = $SQLITE_OK $iRet = $aQuery[0] WEnd _SQLite_QueryFinalize($hQuery) ;~ Return $iRet GUICtrlSetData($statuslabel, " Record Trovati = " & $iRet) EndFunc ;==>_SQLite_CountRows ; Ende Old code = Autoit Forum and Nine. This a button New Case $btnNew GUICtrlSetData($e_edit1, "") GUICtrlSetData($e_edit2, "") GUICtrlSetData($e_edit3, "") $num += 1 GUICtrlSetData($iptCount, $num) _query($num) but it only works if I arrive I arrive at the end instead it should take me directly to the new one to add Edited February 5, 2022 by Giggo
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