Página 1 de 1

Dialog Message to cancel not working with script

Publicado: 17 Ene 2015 19:23
por mecivic
Hi All
I am using SQLite with ListBox. I have a delete button to delete an entry within the ListBox. I want to add a Dialog Message confirming if you want to continue to delete the entry but it still deletes the entry by pressing cancel

This is the script below before adding the Dialog Message.

Código: Seleccionar todo

--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$-- 
--  Get the selected row number.  If nothinh is selected, do nothing 
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&&&&&&-- 
tSelected = ListBox.GetSelected("ListBox_SiteList"); 
if tSelected then 
    nSelected = tSelected[1]; 
    tItemRowNumber = String.ToNumber(ListBox.GetItemData("ListBox_SiteList", tSelected[1])); 
     
    --Delete the entry from the database 
    SQLite.Query(db, "DELETE FROM Websites WHERE RecordID = '" .. tWebsites.Data[tItemRowNumber]["RecordID"] .. "'"); 
    nLastError = Application.GetLastError(); 
    if nLastError ~= SQLite.OK then 
        Dialog.Message("Error: " .. nLastError, SQLite.GetLastErrorString()); 
    end 
     
    FillSitesList(); 
     
    -- Reselect the next item in the list... 
    nReselect = nSelected; 
    nNumItems = ListBox.GetCount("ListBox_SiteList"); 
    if(nNumItems > 0)then 
        if(nReselect > nNumItems)then 
            nReselect = nNumItems; 
        end 
         
        ListBox.SelectItem("ListBox_SiteList",nReselect); 
    end 
end 
This is the Dialog Message added to the script below.

Código: Seleccionar todo

result = Dialog.Message("Warning", "Are you sure you want to DELETE this entry.", MB_OKCANCEL, MB_ICONINFORMATION, MB_DEFBUTTON1); 






--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$-- 
--  Get the selected row number.  If nothinh is selected, do nothing 
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&&&&&&-- 
tSelected = ListBox.GetSelected("ListBox_SiteList"); 
if tSelected then 
    nSelected = tSelected[1]; 
    tItemRowNumber = String.ToNumber(ListBox.GetItemData("ListBox_SiteList", tSelected[1])); 
     
    --Delete the entry from the database 
    SQLite.Query(db, "DELETE FROM Websites WHERE RecordID = '" .. tWebsites.Data[tItemRowNumber]["RecordID"] .. "'"); 
    nLastError = Application.GetLastError(); 
    if nLastError ~= SQLite.OK then 
        Dialog.Message("Error: " .. nLastError, SQLite.GetLastErrorString()); 
    end 
     
    FillSitesList(); 
     
    -- Reselect the next item in the list... 
    nReselect = nSelected; 
    nNumItems = ListBox.GetCount("ListBox_SiteList"); 
    if(nNumItems > 0)then 
        if(nReselect > nNumItems)then 
            nReselect = nNumItems; 
        end 
         
        ListBox.SelectItem("ListBox_SiteList",nReselect); 
    end 
end 
Can anyone help with this thank you

Re: Dialog Message to cancel not working with script

Publicado: 17 Ene 2015 20:04
por Dow Sher
Te falta un pequeño filtro if

Verás, al hacer clic el alguno de los botones de un Dialog.Message este retorna algo.
Imagen

EL filtro que usted necesita es:
result = Dialog.Message("Warning", "Are you sure you want to DELETE this entry.", MB_OKCANCEL, MB_ICONINFORMATION, MB_DEFBUTTON1); 
if result == 1 then
  -- Todo el código para eliminar la fila de la base de datos
end
Espero haber podido ayudarte.
Saludos Dow Sher :friends:

Re: Dialog Message to cancel not working with script

Publicado: 17 Ene 2015 20:24
por mecivic
Hi Thanks for the help
I added your code to the button and the entry still deletes on cancel.

This is how I put your code, is it correct.

Código: Seleccionar todo

result = Dialog.Message("Warning", "Are you sure you want to DELETE this entry.", MB_OKCANCEL, MB_ICONINFORMATION, MB_DEFBUTTON1); 
if result == 2 then
  -- All code for deleting the row of the database
end



--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$--
--  Get the selected row number.  If nothinh is selected, do nothing
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&&&&&&--

tSelected = ListBox.GetSelected("ListBox_SiteList");
if tSelected then
	nSelected = tSelected[1];
	tItemRowNumber = String.ToNumber(ListBox.GetItemData("ListBox_SiteList", tSelected[1]));
	
	--Delete the entry from the database
	SQLite.Query(db, "DELETE FROM Websites WHERE RecordID = '" .. tWebsites.Data[tItemRowNumber]["RecordID"] .. "'");
	nLastError = Application.GetLastError();
	if nLastError ~= SQLite.OK then
		Dialog.Message("Error: " .. nLastError, SQLite.GetLastErrorString());

	end
	
	FillSitesList();
	
---------- Reselect the next item in the list ----------
	nReselect = nSelected;
	nNumItems = ListBox.GetCount("ListBox_SiteList");
	if(nNumItems > 0)then
		if(nReselect > nNumItems)then
			nReselect = nNumItems;
		end
		
		ListBox.SelectItem("ListBox_SiteList",nReselect);
	end
end

Re: Dialog Message to cancel not working with script

Publicado: 17 Ene 2015 21:37
por Dow Sher
Es así, :) creo que no entendió el comentario "Todo el código para eliminar la fila de la base de datos" jejeje me refería a que sustituyera el comentario con el código que está usando para eliminar la fila de la DB :focus:
result = Dialog.Message("Warning", "Are you sure you want to DELETE this entry.", MB_OKCANCEL, MB_ICONINFORMATION, MB_DEFBUTTON1); 
if result == 1 then
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$--
--  Get the selected row number.  If nothinh is selected, do nothing
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&&&&&&--

tSelected = ListBox.GetSelected("ListBox_SiteList");
if tSelected then
   nSelected = tSelected[1];
   tItemRowNumber = String.ToNumber(ListBox.GetItemData("ListBox_SiteList", tSelected[1]));
   
   --Delete the entry from the database
   SQLite.Query(db, "DELETE FROM Websites WHERE RecordID = '" .. tWebsites.Data[tItemRowNumber]["RecordID"] .. "'");
   nLastError = Application.GetLastError();
   if nLastError ~= SQLite.OK then
      Dialog.Message("Error: " .. nLastError, SQLite.GetLastErrorString());

   end
   
   FillSitesList();
   
---------- Reselect the next item in the list ----------
   nReselect = nSelected;
   nNumItems = ListBox.GetCount("ListBox_SiteList");
   if(nNumItems > 0)then
      if(nReselect > nNumItems)then
         nReselect = nNumItems;
      end
      
      ListBox.SelectItem("ListBox_SiteList",nReselect);
   end
end
end

Re: Dialog Message to cancel not working with script

Publicado: 17 Ene 2015 22:13
por mecivic
Hi dowsher

I don't get it. I have tried different ways and still deletes the entry when I click Cancel on the Dialog Message.
I have attached my apz if you could please take a look.

https://mega.co.nz/#!UpRVDRbZ!P5ZoFr4N5 ... Q6FHvKaiHM

Re: Dialog Message to cancel not working with script

Publicado: 17 Ene 2015 23:10
por Dow Sher
Problema resuelto jejejejejeje error mio :lol:
En el filtro if se debe de usar 1 en lugar de 2
if result == 1 then
:) jejejejejejeje :)
Estaba en el celular y no recordaba bien que es lo que retornaba cada botón del dialogo jajajajaja ni porque publiqué una imagen me dí cuenta :lol:

Re: Dialog Message to cancel not working with script

Publicado: 17 Ene 2015 23:17
por mecivic
Hi dowsher
Thank you for the help
The first time i put your code in it didn't work but for some reason i restarted my project and it worked.

Thank you for the help
much appreciated