B4J Question Refresh UI

moore_it

Active Member
Licensed User
Hello,

what's the bet technique for refreshing the user interface ?

Thanks in advice
 

moore_it

Active Member
Licensed User
hello,

i tried with timer nothing happen, i tried with callsubdelayed noting happen too ...

this is my code

Sub go
l_progress.Visible = True
For counter = 0 To trl.Size - 1
l_progress.Text = "Found " & trl.Size & " select " & counter & " ."
CallSubDelayed(Me,"search")
Next
End Sub

Sub search
Dim sf As StringFunctions
Dim row As String
row = trl.get(counter)
Dim org As String
org = sf.Mid(row,1,4)
If org = "Z001" Then
Dim art As String
art = sf.Mid(row,49,18)
Dim can As String
can = sf.Mid(row,5,2)
Dim rs As ResultSet = mySQL.ExecQuery("SELECT * FROM controllo where organizzazione = '" & org & "' and canale = '" & can & "' and articolo = '" & art & "'")
Do While rs.NextRow
Dim foto As String
foto = rs.GetString("Nomefoto")
If foto <> "" Then
row = row & foto
wr.WriteLine(row)
Else
End If
Loop
rs.Close
End If
wr.Close
End Sub

sorry for the code i don't remeber how to insert it

Thanks in advice
 

Erel

Administrator
Staff member
Licensed User
Please use [code]code here...[/code] tags when posting code.

There are several problems with this code.

1. You should never write such queries. Use ExecQuery2 instead and pass the variables in an arrau.
2. Where is wr opened?
3. Counter value will be incorrect. It will have the value of the last item. You need to send it as a paramter.

Which part of this code is slow? The query? If yes then you might need to add an index to your database. You can also use ExecQueryAsync to create an asynchronous query. However I recommend you to start with a simpler solution.
 

moore_it

Active Member
Licensed User
Hi,

yes the code is a part of the program, sorry

no the program is not slow , but not refresh the gui ...
 

moore_it

Active Member
Licensed User
Hi

for example :

i have a minimal gui, an label and an button.
when i push the button start for next cycle

how i do to refresh the gui ?

thanks

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    l.Initialize("lab")
    l.Text = "Start"
    MainForm.RootPane.AddNode(l,20,20,200,20)
    b.Initialize("avvi")
    b.Text = "Avvia"
    MainForm.RootPane.AddNode(b,20,100,80,20)
    MainForm.Show
End Sub

Sub avvi_action
    For i = 0 To 10000000000
        l.Text = i
    Next
End Sub
 

moore_it

Active Member
Licensed User
Hi
another example with timer ...

B4X:
#Region  Project Attributes 
    #MainFormWidth: 437
    #MainFormHeight: 239 
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
   
    Private b As Button
    Private l As Label
   
    Private t As Timer
   
    Private count As Int
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    l.Initialize("lab")
    l.Text = "Start"
    MainForm.RootPane.AddNode(l,20,20,200,20)
    b.Initialize("avvi")
    b.Text = "Avvia"
    MainForm.RootPane.AddNode(b,20,100,80,20)
    MainForm.Show
End Sub

Sub avvi_action
    t.Initialize("tim",1)
    t.Enabled = True
    CallSubDelayed(Me,"conta")
End Sub

Sub conta
    For count = 0 To 10000000000
    Next
    t.Enabled = False
End Sub

Sub tim_tick
    l.Text = count
End Sub
[\code]
 

moore_it

Active Member
Licensed User
Thanks Erel,

this technique is perfect but ...
why the refresh of the label is dirty ?

See the image .
 

Attachments

Top