reload

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

reload

Post by link76 » Fri Nov 04, 2011 3:17 pm

I want to set up an automated reload after (60) seconds of my script in the button.
This script connects to the database and displays data in a datagrid

sorry for my English :oops:

Thanks

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: reload

Post by jmburnod » Fri Nov 04, 2011 4:17 pm

Hi,

You can use
send "myhandler" to me in 1000 milliseconds
Look at pendingmessages in the LC dictionary
sorry for my English
Welcome to this forum and specialy in the " terrible english team" :wink:

Best regards

Jean-Marc
https://alternatic.ch

link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

Re: reload

Post by link76 » Sat Nov 05, 2011 1:50 pm

Thanks Jean-Marc for your answer :D , but I have difficulty with your suggestion :oops:
this is my code in the button, I want to reload the script automatically every 60 seconds to update my datagrid

Code: Select all

global theDBHost
   global theDBName
   global theDBUser
   global theDBPassword
   global theDBType
   global tTableMissioniAttive
   local sScrollerId 
   
   ## START GESTIONE DATABASE
   ## Connect to the database
    
   put revOpenDatabase( theDBType, theDBHost, theDBName, theDBUser, theDBPassword ) into theConnectionID
           if theConnectionID is an integer then
              ## Query the database for data
             put revQueryDatabase( theConnectionID, "SELECT * FROM " & tTableMissioniAttive & " where ID_CLASSIFCZ = 1  order by ID_MISSIONE DESC" ) into theCursor
                            if theCursor is an integer then
                     ConvertSQLCursorToArray theCursor, theDataGridArray
                     put the result into theError
                                 if theError is empty then
                            ## The cursor was successfully converted to an array.         
            ## Assign it to the data grid.
            ## from the database cursor will appear in the matching columns         
            ## in the data grid.
               set the dgData of group "DataGridOne" to theDataGridArray
            
         end if
       ## Close the database cursor 
      revCloseCursor theCursor
end if
     
      ## Close the database connection
              revCloseDatabase theConnectionID
       else
              answer "Error connecting to the database:" && theConnectionID & "."
       end if
end mouseUp

.......
thx

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: reload

Post by jmburnod » Sat Nov 05, 2011 2:25 pm

HI THX (238?)
I have difficulty with your suggestion
Everyone in this forum can remember this experience :)

Have a look at this script (no tested). Maybe it work
and you can see how pendingmessages work
Type "ExitNajDB" in the messagesbox to stop the loop

Best

Jean-Marc

Code: Select all

-- Btn script
on mouseUp
 DoMajDB
end mouseUp
-- Btn script end

--Card or stack script
on DoMajDB
   global theDBHost
   global theDBName
   global theDBUser
   global theDBPassword
   global theDBType
   global tTableMissioniAttive
   local sScrollerId 
   
   ## START GESTIONE DATABASE
   ## Connect to the database
   
   put revOpenDatabase( theDBType, theDBHost, theDBName, theDBUser, theDBPassword ) into theConnectionID
   if theConnectionID is an integer then
      ## Query the database for data
      put revQueryDatabase( theConnectionID, "SELECT * FROM " & tTableMissioniAttive & " where ID_CLASSIFCZ = 1  order by ID_MISSIONE DESC" ) into theCursor
      if theCursor is an integer then
         ConvertSQLCursorToArray theCursor, theDataGridArray
         put the result into theError
         if theError is empty then
            ## The cursor was successfully converted to an array.         
            ## Assign it to the data grid.
            ## from the database cursor will appear in the matching columns         
            ## in the data grid.
            set the dgData of group "DataGridOne" to theDataGridArray
            
         end if
         ## Close the database cursor 
         revCloseCursor theCursor
      end if
      
      ## Close the database connection
      revCloseDatabase theConnectionID
   else
      answer "Error connecting to the database:" && theConnectionID & "."
   end if
   
   --Added jmb 051111
   if DoMajDB is not in the pendingMessages then
      send DoMajDB to me in 1000 milliseconds
   end if
      --Added jmb 051111 end
end DoMajDB

--Added jmb 051111
on ExitNajDB
   repeat for each line aLine in the pendingMessages
      if aLine contains "DoMajDB" then 
         cancel item 1 of aLine
      end if
   end repeat
   exit to top
end ExitNajDB
--Added jmb 051111 end
--Card or stack script enda
https://alternatic.ch

link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

Re: reload

Post by link76 » Sat Nov 05, 2011 2:52 pm

Everyone in this forum can remember this experience :)
sorry for my English, I don't speak English very well, I'm Italian.
This script is for IOS platform, the complete code of the button is:

Code: Select all

on mouseUp

   
   global theDBHost
   global theDBName
   global theDBUser
   global theDBPassword
   global theDBType
   global tTableMissioniAttive
   local sScrollerId 
   
   ## START GESTIONE DATABASE
   ## Connect to the database
    
   put revOpenDatabase( theDBType, theDBHost, theDBName, theDBUser, theDBPassword ) into theConnectionID
    
    
   if theConnectionID is an integer then
        
      ## Query the database for data
       
      put revQueryDatabase( theConnectionID, "SELECT * FROM " & tTableMissioniAttive & " where ID_CLASSIFCZ = 1  order by ID_MISSIONE DESC" ) into theCursor
        
        
      
      if theCursor is an integer then
            
         ConvertSQLCursorToArray theCursor, theDataGridArray
            
         put the result into theError
            
            
         if theError is empty then
                
            ## The cursor was successfully converted to an array.
                
            ## Assign it to the data grid. The 'firstname' and 'lastname' columns
                
            ## from the database cursor will appear in the matching columns
                
            ## in the data grid.
                
            set the dgData of group "DataGridOne" to theDataGridArray
            
         end if
            
            
         ## Close the database cursor 
            
         revCloseCursor theCursor
        
      end if
        
        
      ## Close the database connection
        
      revCloseDatabase theConnectionID
    
   else
        
      answer "Error connecting to the database:" && theConnectionID & "."
    
   end if
end mouseUp
   
command ConvertSQLCursorToArray pCursor, @pOutArrayA
    
   local i
    
   local theFields
    
   local theError
    
    
   
   local count_verde -- imposto variabile conteggio Verdi 
   local count_giallo -- imposto variabile conteggio Gialli
   local count_rosso -- imposto variabile conteggio Rossi
   
   ## Get the names of all the columns in the database cursor
    
   put revDatabaseColumnNames(pCursor) into theFields
    
   if theFields begins with "revdberr," then
        
      put item 2 to -1 of theFields into theError
    
   end if
    
    
   
   if theError is empty then
        
      put 0 into i
  
      put 0 into count_verde -- azzerro contatore 
      put 0 into count_giallo -- azzerro contatore 
      put 0 into count_rosso -- azzerro contatore 
      
      ## Loop through all rows in cursor
        
      repeat until revQueryIsAtEnd(pCursor)
            
         add 1 to i
            
            
         
         ## Move all fields in row into next dimension of the array
            
         repeat for each item theField in theFields
                
            put revDatabaseColumnNamed(pCursor, theField) into pOutArrayA[i][ theField ]        
         end repeat
  
              
         -- Conteggio i codici colore
         switch pOutArrayA[i]["ID_CODICE_E"]
            case "V"
               add 1 to count_verde 
               break
            case "G"
               add 1 to count_giallo 
               break
            case "R"
               add 1 to count_rosso
 
               break
         end switch
              
            
         revMoveToNextRecord pCursor
        
      end repeat  
      
       -- Popolo le label sulla schermata Missioni
      put "MISSIONI IN CORSO : " &i into field "Label Missioni" of card "LiveMissioni"
      put "VERDI : " &count_verde into field "Label Verdi" of card "LiveMissioni"
      put "GIALLI : " &count_giallo into field "Label Gialli" of card "LiveMissioni"
      put "ROSSI : " &count_rosso into field "Label Rossi" of card "LiveMissioni" 
      ## END GESTIONE DATABASE
      
      ## START GESTIONE OGGETTO SCROLLER TOUCH
      
      ## 50 è l'altezza della riga nel row template, moltiplico per il numero di missioni presenti
      put i*50 into tAltezza
      
      lock screen
      set the unboundedHScroll of group "ScrollerGroup" to false
      set the unboundedVScroll of group "ScrollerGroup" to true
      
      iphoneControlCreate "scroller"
      put the result into sScrollerId
      
      -- general properties
      iphoneControlSet sScrollerId, "visible", "true"
      iphoneControlSet sScrollerId, "canBounce", "false"
      iphoneControlSet sScrollerId, "pagingEnabled", "false"
      iphoneControlSet sScrollerId, "canScrollToTop", "true"
      iphoneControlSet sScrollerId, "vIndicator", "false"
      iphoneControlSet sScrollerId, "contentRect",  (0, 0, 320, tAltezza)  
      --iphoneControlSet sScrollerId, "rect", "0,62,320,412"
      iphoneControlSet sScrollerId, "rect", "0,112,320,412"  
      unlock screen
   end if
    
    
   return theError

end ConvertSQLCursorToArray

end mouseUp

on scrollerDidScroll OffsetX, OffsetY
   set the hScroll of group "ScrollerGroup" to OffsetX
   set the vScroll of group "ScrollerGroup" to OffsetY
end scrollerDidScroll


on closeCard
   if the environment is not "mobile" then
      exit closeCard
   end if
   
   iphoneControlDelete sScrollerId
end closeCard
## END GESTIONE OGGETTO SCROLLER TOUCH
I have written your code, but does not work, sorry I'm beginner

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: reload

Post by jmburnod » Sat Nov 05, 2011 9:56 pm

Hi,

I see you want an update every 60 seconds.
(my previous script set it to one seconds. I changed it to 60 seconds)
the complete code of the button
I see an "on closecard". Are you sur that is in the script btn ?

Look at the stack in attachment.
Start btn send a "DoMajDB" message and the script cd catch and do it


Best regards

Jean-Marc
Attachments
reloadUpdateDB.livecode.zip
(2.71 KiB) Downloaded 266 times
https://alternatic.ch

link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

Re: reload

Post by link76 » Sun Nov 06, 2011 3:26 pm

thank you very much Jean Mark, it is ok! :D

but I have a problem with the scroll object.
I see the reload but not reset the information immediately. It updates when I touch the screen and move the scroll on top.

how can I reset automatically every reload?

I catch this code:

Code: Select all

set the dgData of group "DataGridOne" to empty 
but it reset only the contents

best regards

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: reload

Post by jmburnod » Sun Nov 06, 2011 6:22 pm

Hi
it is ok!
Glad it is useful :D
I see the reload but not reset the information immediately
Sorry. I can't test this part of your script
It updates when I touch the screen and move the scroll on top.
It update the array but not the fields of the dg ?

Best

Jean-Marc
https://alternatic.ch

link76
Posts: 99
Joined: Fri Nov 04, 2011 1:52 pm

Re: reload

Post by link76 » Sun Nov 06, 2011 7:07 pm

After reload, I see the updated fields, but only if I touch the screen it returns to the first line.
I would like to return it to the top!

Thanks for your patience and availability

best regards
Luca

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: reload

Post by jmburnod » Mon Nov 07, 2011 9:54 pm

Hi Luca,

Sorry no idea at this moment.

Best regards

Jean-marc
https://alternatic.ch

Post Reply