Updating text box before code ends

rede96

Registered User.
Local time
Today, 22:11
Joined
Apr 2, 2004
Messages
134
I have a bit of code which runs on the 'On Click' event of a command button on a form.

The code checks for a connection status to an external device. If the status is ok, it changes a rectangle's back colour to green, if not changes it to red. The code should then pause 3 seconds (Which will allow the user to see the back colour of the rectangle.) and then change it back to white to show the test has finished.

The problem is my code doesn't change the colour of this rectangle until it finishes running. Is there a way to do this during the code, before the end?

I can’t use the TimerInterval / OnTimer because it is in use for something else.
Code:
Private Sub cmdConnect_Click()
Dim AdamCon As Long
Dim IPCon As Long
'Set parameters for connection.
ADAMTCP0.TCPPort = 502
ADAMTCP0.ConnectionTimeout = 400
ADAMTCP0.SendTimeout = 400
ADAMTCP0.ReceiveTimeout = 400
ADAMTCP0.RWCount = Me.txtRecordsCount
ADAMTCP0.RWStartAddress = 1
ADAMTCP0.DeviceID = 1
'check ActiveX control initialises ok
AdamCon = ADAMTCP0.Open
If AdamCon <> 0 Then
'Did not initialise, change rectangle to orange
Me.boxStatus.BackColor = 33023
GoTo Disconnect
End If
'Check the connection status
IPCon = ADAMTCP0.Connect(Me.txtIPAddress)
If IPCon <> 0 Then 
'Did not connect, change rectangle to Red
Me.boxStatus.BackColor = 255
Else
'connection OK. change rectangle to Green
Me.boxStatus.BackColor = 32768
End If

Disconnect:
ADAMTCP0.Disconnect
ADAMTCP0.Close
Call Sleep(3000) 'this is a proceedure to pause for 3 seconds to allow the user to see the results of the test.
'Change the rectangle back to white to show test ended.
Me.boxStatus.BackColor = 16777215
End Sub
 

Users who are viewing this thread

Back
Top Bottom