[solved] Listbox not updating until end of subs

Post

Posted
Rating:
#1 (In Topic #715)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Hi Everyone,

I am using this section of code to wait a seconds for the appliation to start up before begining to do anything but for some reason the
 listbox i have on screen is not updated until the end of the fucntions even with me adding in

fmain.ListBox1.Refresh
fmain.Refresh

even the Label1.Text = "Loading System Settings…" is not working

am I doing this correctly or is there something else i need to do to get the app to update my list box so I know what it is doing.


Code

' Gambas class file

Public hConsoleTimer As Timer


Public Sub Form_Open()
hConsoleTimer = New Timer As "MyTimer"
    hConsoleTimer.Delay = 1000
    hConsoleTimer.Enabled = True
End


Public Sub MyTimer_Timer()
    hConsoleTimer.Stop
    hConsoleTimer.Enabled = False
 
    Label1.Text = "Loading System Settings..."

    Startup.LoadSystemFiles

    Label1.Text = "Main Server Address :" & Global.ServerDatabaseLocation & " Database Name : " & Global.ServerDatabaseDatabaseName
    
    Label1.Refresh
       
 
    
    Global.AddToListBox("Checking for Connection to Main Database server")
    DatabaseFunctions.CheckForDatabaseConnection

End
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
Have you tried using…
Wait
After setting label text

Code (gambas)

  1. Label1.text = "SOME TEXT"
  2.  
  3. More code...
  4.  

Or
Wait 0.1
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
 Notes..
Timer default is 1000 so that code is not needed.

Also
Timer.Stop and Timer.Enabled = False is the same thing so you can lose one of those lines
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
Consider the following code. Note that the Timer will not process anything until the 'Delay' period has passed.  Your code had the line Label1.Text = "Loading System Settings… in the Timer routine. That would not have been processed until the delay period had expired.

Code (gambas)

  1. Timer1 As Timer
  2. Label1 As Label
  3. ListBox1 As ListBox
  4.  
  5. Public Sub Form_Open()
  6.  
  7.   BuildForm
  8.  
  9.  
  10. Public Sub Timer1_Timer()
  11.  
  12.   Timer1.Stop
  13.   Label1.Background = Color.Default
  14.   Label1.Text = "Main Server Ready and waiting.."
  15.  
  16.  
  17. Public Sub BuildForm()
  18.  
  19.   With Me
  20.     .Height = 400
  21.     .Width = 500
  22.     .Padding = 5
  23.     .Arrangement = Arrange.Vertical
  24.     .Center
  25.  
  26.   With Label1 = New Label(Me) As "Label1"
  27.     .H = 56
  28.     .W = 100
  29.     .Text = "Loading System Settings...2 Second delay"
  30.     .Font.Bold = True
  31.     .Font.Size = 16
  32.     .Background = Color.Yellow
  33.     .Alignment = Align.Center
  34.  
  35.   With ListBox1 = New ListBox(Me) As "ListBox1"
  36.     .Expand = True
  37.     .List = Dir(User.Home, "[^.]*", gb.File)
  38.  
  39.   With Timer1 = New Timer As "Timer1"
  40.     .Delay = 2000
  41.     .Enabled = True
  42.  
Online now: No Back to the top

Post

Posted
Rating:
#5
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

BruceSteers said

Have you tried using…
Wait
After setting label text

Code (gambas)

  1. Label1.text = "SOME TEXT"
  2.  
  3. More code...
  4.  

Or
Wait 0.1

Thank-you BruceSteers that worked prefectly

Sorry for the delay in Replaying I was not getting any Emails to say you had posted.

What does the wait 0.1 function do?
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’

AndyGable said

BruceSteers said

Have you tried using…
Wait
After setting label text

Code (gambas)

  1. Label1.text = "SOME TEXT"
  2.  
  3. More code...
  4.  

Or
Wait 0.1

Thank-you BruceSteers that worked prefectly

Sorry for the delay in Replaying I was not getting any Emails to say you had posted.

What does the wait 0.1 function do?

Waits a tenth of a second.
Sometimes just Wait is not enough.

Wait is supposed to allow events waiting to be processed to finish but I think some things dont wait , or wait continues as soon as a slot is free, so specifying a fraction of a second can do the job while other things catch up.

You're welcome. I tackled the same issue yesterday so was fresh in my mind.
Online now: No Back to the top
1 guest and 0 members have just viewed this.