Announcement

Collapse
No announcement yet.

Dialog Message to cancel not working with script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dialog Message to cancel not working with script

    Hi All
    I am using the script below with a button on click event.

    PHP Code:
    --%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$--
    --  
    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: " .. nLastErrorSQLite.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 

    When I add this script with the Dialog Message like below it still deletes the entry if I cancel.

    PHP Code:
    result Dialog.Message("Warning""Are you sure you want to DELETE this entry."MB_OKCANCELMB_ICONINFORMATIONMB_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: " .. nLastErrorSQLite.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 

    How can I get the Dialog message to work if I click cancel so that it wont delete the entry with the code I have.

  • #2
    Well, you would actually need to test what the user clicked, wouldn't you? You need to add an if and test the result of Dialog.Message(), and only execute the code if the condition was satisfied.

    Ulrich

    Comment


    • #3
      Thanks Ulrich
      I also tried this code and still deletes the entry when I cancel

      Code:
      result = Dialog.Message("Warning", "Are you sure you want to DELETE this entry.", MB_OKCANCEL, MB_ICONINFORMATION, MB_DEFBUTTON1); 
      if result == 2 then
      
      end
      Code:
      result = Dialog.Message("Warning", "Are you sure you want to DELETE this entry.", MB_OKCANCEL, MB_ICONINFORMATION, MB_DEFBUTTON1); 
      if result == 2 then
      
      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

      Comment


      • #4
        Attach a project so we can see where you are putting your code.

        Comment


        • #5
          Hi Shrek
          The code is with the Button On Click

          Comment


          • #6
            Try this below

            PHP Code:
            WarningResult Dialog.Message("Warning""Are you sure you want to DELETE this entry."MB_OKCANCELMB_ICONINFORMATIONMB_DEFBUTTON1); 
            if 
            WarningResult == IDOK then
            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: " .. nLastErrorSQLite.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 
            Plugins or Sources MokoX
            BunnyHop 2021 Here

            Comment


            • #7
              This code is now working thanks all.

              Code:
              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

              Comment

              Working...
              X