Hi,
I have raised this issue before but it is lying unresolved till now.
The VB application is communicating through serial port for data acquisition from 21 microcontroller based instruments which respond against a ASCII code.Now to keep the main code window clean I have kept the communication in a public function of a module.

The relevant form code looks something like this:

Code:
Option Explicit

Public timeoutdelay As Integer
Public serdatain     As Boolean
Public serial_in_buffer As String
Public serial_in_count As String
Public timeoutflag  As Boolean
Public errorflag As Boolean

'This button starts the data acquisition process

Private Sub cmd_start_Click()

Dim instrumentstring(20) As String
Dim instrumentdata(20) As Single
Dim instrumentcode(20) As Byte
Dim i As Byte
Dim j As Byte
Dim k As Byte

On Error GoTo errorhandler_1

readdata:

For i = 0 To 20
 instrumentcode(i) = Asc(Chr$(97 + i))         'fil array with "w"
Next
                                                            'get all the possible 21 data
For i = 0 To 20        
    
    Call get_instrument_data(instrumentcode(i))
    instrumentstring(i) = serial_in_buffer
    instrumentdata(i) = Val(instrumentstring(i))    
Next
.................................................................................
'Here we insert code to populate an excel worksheet with the data
...............................................................................
 
GoTo  readdata                        'go on acquiring data
Exit Sub
errorhandler_1:
MsgBox "Fatal error", vbOKOnly + vbExclamation, "Error"
End Sub

'The MSComm event procedure

Private Sub MSComm1_OnComm()

Select Case MSComm1.CommEvent

    Case comEvReceive
        serial_in_buffer = serial_in_buffer & MSComm1.Input
        Debug.Print serial_in_buffer
        serdatain = True
        serial_in_count = serial_in_count + 1
    Case Else
        MsgBox "Communication error", vbOKOnly + vbExclamation, "error"
        Exit Sub
End Select
        
End Sub

The instrument calling function looks something like this which is in a separate module:

Code:
Function get_instrument_data(code As Byte) As String

'first clear the strings to hold the data & initialize booleans
frm.serial_in_buffer = vbNullString
frm.serdatain = False
frm.serial_in_count = 0
frm.errorflag = False

frm.MSComm1.PortOpen = True '
frm.MSComm1.Output = Chr$(code)

'at the same time enable timer for timeout protection
frm.Timer1.Enabled = True
frm.Timer1.Interval = frm.timeoutdelay
frm.timeoutflag = True

'wait for reception to start.If it does not start within
'timeout1 period then abort

While frm.serdatain = False
    DoEvents
        If frm.timeoutflag = False Then        'close port
            frm.MSComm1.PortOpen = False
            frm.Timer1.Enabled = False                  'stop timer
            MsgBox "Cannot get data", vbOKOnly + vbExclamation, "Error"
            frm.errorflag = True
            Exit Function
        End If
Wend

'after first character is received stop (& reset) timer

frm.Timer1.Enabled = False

'after start of reception wait for 34 characters which comprise
'each string

While frm.serial_in_count < 34
    DoEvents
Wend

frm.MSComm1.PortOpen = False        'close port which also clears receive & send buffers

End Function
My problem is that form unloading is not closing my application which is still shown as running by the windows task manager.I have tried the following:
1.A Boolean in the form unload procedure to close down the data acquisition loop.
2.I have closed the MSComm port & timer1 in the form unload procedure.

Only an "END" statement in the form unload procedure is closing my application which I think is recommended by nobody.

How to properly close my application without "END"?