[solved] Listbox not updating until end of subs

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 349
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

[solved] Listbox not updating until end of subs

Post by AndyGable »

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: Select all

' 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
Last edited by AndyGable on Tuesday 27th July 2021 7:20pm, edited 1 time in total.
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Listbox not updatiug until end of subs

Post by BruceSteers »

Have you tried using...
Wait
After setting label text
Label1.text = "SOME TEXT"
Wait

More code...
Or
Wait 0.1
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Listbox not updatiug until end of subs

Post by BruceSteers »

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
If at first you don't succeed , try doing something differently.
BruceS
User avatar
cogier
Site Admin
Posts: 1117
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Listbox not updatiug until end of subs

Post by cogier »

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.
Timer1 As Timer
Label1 As Label
ListBox1 As ListBox

Public Sub Form_Open()

  BuildForm

End

Public Sub Timer1_Timer()

  Timer1.Stop
  Label1.Background = Color.Default
  Label1.Text = "Main Server Ready and waiting.."

End

Public Sub BuildForm()

  With Me
    .Height = 400
    .Width = 500
    .Padding = 5
    .Arrangement = Arrange.Vertical
    .Center
  End With

  With Label1 = New Label(Me) As "Label1"
    .H = 56
    .W = 100
    .Text = "Loading System Settings...2 Second delay"
    .Font.Bold = True
    .Font.Size = 16
    .Background = Color.Yellow
    .Alignment = Align.Center
  End With

  With ListBox1 = New ListBox(Me) As "ListBox1"
    .Expand = True
    .List = Dir(User.Home, "[^.]*", gb.File)
  End With

  With Timer1 = New Timer As "Timer1"
    .Delay = 2000
    .Enabled = True
  End With

End
AndyGable
Posts: 349
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Listbox not updatiug until end of subs

Post by AndyGable »

BruceSteers wrote: Tuesday 27th July 2021 1:24am Have you tried using...
Wait
After setting label text
Label1.text = "SOME TEXT"
Wait

More code...
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?
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Listbox not updatiug until end of subs

Post by BruceSteers »

AndyGable wrote: Tuesday 27th July 2021 7:19pm
BruceSteers wrote: Tuesday 27th July 2021 1:24am Have you tried using...
Wait
After setting label text
Label1.text = "SOME TEXT"
Wait

More code...
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.
If at first you don't succeed , try doing something differently.
BruceS
Post Reply