Hello Everyone,
I occasionally receive the following error message:
Error 496 In Program.Bas(148:1): Destination File Write Error Line 148:End Function
When I get this error I can type "(ctrl)+(alt)+(del)" to bring up a list of programs that
are executing on my machine and I see 'Program.bas' on the list. What drives me crazy is
that the program terminates properly about 80% of the time (luck i guess) and that there
does not seem to be any reason as to when it does and does not terminate properly.
I have posted an abbreviated version of the code (but one that does contain the problem)
below and would appreciate any help to find the problem.
Thanks in Advance
Wesley
------------------
[This message has been edited by Wesley Brown (edited February 22, 2001).]
I occasionally receive the following error message:
Error 496 In Program.Bas(148:1): Destination File Write Error Line 148:End Function
When I get this error I can type "(ctrl)+(alt)+(del)" to bring up a list of programs that
are executing on my machine and I see 'Program.bas' on the list. What drives me crazy is
that the program terminates properly about 80% of the time (luck i guess) and that there
does not seem to be any reason as to when it does and does not terminate properly.
I have posted an abbreviated version of the code (but one that does contain the problem)
below and would appreciate any help to find the problem.
Thanks in Advance

Wesley
Code:
'Wesley Brown 'February 22, 2001 #Compile Exe #Register None #Dim All #Include "WIN32API.INC" '=========================================================================================== 'Define Constants $AppTitle = "Program That Has Problems" $ComPort = "COM1" %Exit = 200 'Button, Exit Program %Idt_Timer1 = 300 'Timer, Money & Volumn Update %Idt_Timer2 = 301 'Timer, Screen Update %MesgBox = 400 'TextBox, Status Messages '------------------------------------- 'Define Globals Global hComm As Long Global hDlg As Long Global hListen As Long Global hLogic As Long Global LogicClose As Long Global ListenClose As Long Global Result As Long Global TtlBytes As Long Global BytesIn As String Global LBR As String '------------------------------------- Function EndComms() As Long Dim dummy As String If Comm(#hComm, RxQue) Then Comm Recv #hComm, Comm(#hComm, RxQue), dummy Comm Close #hComm End Function '=========================================================================================== Function TxRxData(ByVal hWnd As Long) As Long While IsFalse ListenClose& While (IsFalse ListenClose&) And (LBR$ <> "x") If (IsFalse ListenClose&) And (Comm(#hComm, RxQue) = 0 ) Then Iterate Loop Comm Recv #hComm, 1, LBR$ If LBR$ = Chr$(&H05) Then LBR$ = "x" BytesIn = LBR$ TtlBytes = 1 Wend While (IsFalse ListenClose&) And (LBR$ <> "z") If (IsFalse ListenClose&) And (Comm(#hComm, RxQue) = 0 ) Then Iterate Loop Comm Recv #hComm, 1, LBR$ If (LBR$ = Chr$(&H17)) Then LBR$ = "y" If (LBR$ = Chr$(&H04)) Then LBR$ = "z" BytesIn = BytesIn & LBR$ Incr TtlBytes Wend 'Process BytesIn Wend Function = %True End Function '=========================================================================================== Function StartComms As Long Comm Open $COMPORT As #hComm If ErrClear Then Exit Function ' Exit if port cannot be opened Comm Set #hComm, Baud = 9600 ' 9600 baud Comm Set #hComm, Byte = 8 ' 8 bits Comm Set #hComm, Parity = %False ' No parity Comm Set #hComm, CtsFlow = 0 ' Disable CTS Flow Comm Set #hComm, RtsFlow = 0 ' Disable RTS Flow Comm Set #hComm, Xinpflow = 0 ' Disable Xon/Xoff on Input Comm Set #hComm, Stop = 0 ' 1 stop bit Comm Set #hComm, TxBuffer = 4096 ' 4k transmit buffer Comm Set #hComm, RxBuffer = 4096 ' 4k receive buffer Function = %True End Function '=========================================================================================== 'Dialog Control Callback Functions '=========================================================================================== CallBack Function Dialog_Callback() Select Case CbMsg Case %Wm_Timer Select Case CbWparam Case %Idt_Timer1 'Timer1 Routine Case %Idt_Timer2 'Timer2 Routine End Select 'CbWparam Case %Wm_InitDialog SetTimer hDlg, %Idt_Timer1, 100, ByVal %Null SetTimer hDlg, %Idt_Timer2, 500, ByVal %Null Case %Wm_Destroy KillTimer hDlg, %Idt_Timer1 KillTimer hDlg, %Idt_Timer2 End Select 'CbMsg End Function '=========================================================================================== CallBack Function Quit_Callback() As Long ' Kill the dialog and let PBMAIN() continue Dialog End hDlg, 0 End Function '=========================================================================================== Function PbMain 'Initialize Serial Port If IsFalse StartComms Then MsgBox "Failure to start communications!",, $AppTitle Exit Function End If 'Create a Modal Dialog Box Dialog New 0, $AppTitle,,, 500, 380, %Ws_PopUp Or %Ws_Visible Or %Ws_ClipChildren _ Or %Ws_Caption Or %Ws_SysMenu Or %Ws_MinimizeBox, 0 To hDlg Control Add Button, hDlg, %Exit, "Exit", 373, 350, 50, 14, Call Quit_Callback '=========================================================================================== 'Create A "Listen" Thread To Monitor Input From Serial Port Thread Create TxRxData(hDlg) To hListen 'Create "Logic" Thread (main program) Thread Create MainProg(hDlg) To hLogic 'Start the dialog box & run until DIALOG END executed. Dialog Show Modal hDlg, Call Dialog_Callback To Result 'Close Down "Logic" Thread LogicClose& = %True Thread Suspend hLogic To Result Do Thread Close hLogic To Result Loop Until IsTrue Result 'Close Down "Listen" Thread ListenClose& = %True Thread Suspend hListen To Result Do Thread Close hListen To Result Loop Until IsTrue Result ' Flush & Close Comm Port Call EndComms Function = %True End Function '=========================================================================================== Function MainProg(ByVal hWnd As Long) As Long While IsFalse LogicClose& 'Main Program Code Wend '(While IsFalse ThreadClose) Function = %True End Function
------------------
[This message has been edited by Wesley Brown (edited February 22, 2001).]
Comment