Page 1 of 1

[solved] Listbox not updating until end of subs

Posted: Monday 26th July 2021 11:19pm
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

Re: Listbox not updatiug until end of subs

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

More code...
Or
Wait 0.1

Re: Listbox not updatiug until end of subs

Posted: Tuesday 27th July 2021 1:28am
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

Re: Listbox not updatiug until end of subs

Posted: Tuesday 27th July 2021 2:25pm
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

Re: Listbox not updatiug until end of subs

Posted: Tuesday 27th July 2021 7:19pm
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?

Re: Listbox not updatiug until end of subs

Posted: Tuesday 27th July 2021 8:14pm
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.