B4J Question Refresh UI

Discussion in 'B4J Questions' started by moore_it, Feb 25, 2015.

  1. moore_it

    moore_it Active Member Licensed User

    Hello,

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

    Thanks in advice
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    The UI is refreshed automatically. Which problem have you encountered?
     
  3. moore_it

    moore_it Active Member Licensed User

    i need to refresh a label when i'm into a for next cicle
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    It is not possible. There is no DoEvents call in B4J. Usually there are two types of solutions:
    - Use a timer instead of this loop.
    - Break the task to smaller tasks and use CallSubDelayed to run each task.
     
  5. moore_it

    moore_it Active Member Licensed User

    ok thanks
     
  6. moore_it

    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
     
  7. Erel

    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.
     
  8. moore_it

    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 ...
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    I'm sorry but I don't understand. Where is the UI updated?
     
  10. moore_it

    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

    Code:
    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
     
  11. moore_it

    moore_it Active Member Licensed User

    Hi
    another example with timer ...

    Code:
    #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]
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Not sure what you expect from the codes above but they cannot work.

    If you want to update a label then you should update it in the timer event:
    Code:
    Sub tim_tick
     count = count + 
    1
     l.Text = count
     
    if count = 10000000 Then tim.Enabled = false
    End Sub
     
  13. moore_it

    moore_it Active Member Licensed User

    Thanks Erel,

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

    See the image .
     

    Attached Files:

  14. Erel

    Erel Administrator Staff Member Licensed User

    Maybe it is updated too fast.
    Update it every 100 counts.
     
  15. moore_it

    moore_it Active Member Licensed User

    WOW you're fast ...

    Thanks very much !
    Toni
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice