BBC BASIC
« COMLIB Cleanup »

Welcome Guest. Please Login or Register.
Mar 31st, 2018, 10:44pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Cross-platform BBC BASIC (Windows, Linux x86, Mac OS-X, Android, iOS, Raspberry Pi)
BBC BASIC Resources
BBC BASIC Help Documentation
BBC BASIC for Windows Home Page
BBC BASIC Programmers' Reference
BBC BASIC Beginners' Tutorial
BBC BASIC for SDL 2.0 Home Page
BBC BASIC Discussion Group

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: COMLIB Cleanup  (Read 312 times)
Edja
New Member
Image


member is offline

Avatar




PM


Posts: 22
xx COMLIB Cleanup
« Thread started on: Jan 19th, 2017, 09:54am »

I've written a program making use of COMLIB to manipulate Excel sheets. I use PROCcleanup as documented on the WIKI.
Code:
DEF PROCcleanupXlapp%  += 0 : IF Xlapp%  PROC_releaseobject(Xlapp%)  : Xlapp% = 0Xlbook% += 0 : IF Xlbook% PROC_releaseobject(Xlbook%) : Xlbook% = 0ENDPROC 
All works fine !
But I fail to understand the purpose of the statements Xlapp% +=0 and Xlbook% += 0
Are Xlapp% and Xlbook% changed after execution of those statements ?

Edja
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: COMLIB Cleanup
« Reply #1 on: Jan 19th, 2017, 2:13pm »

on Jan 19th, 2017, 09:54am, Edja wrote:
But I fail to understand the purpose of the statements Xlapp% +=0 and Xlbook% += 0

It's a standard technique to avoid the reporting of 'No such variable' errors. Commonly, a cleanup routine will be called from an ON ERROR handler, and in that case you may not easily be able to guarantee that variables used in the cleanup process have ever been created. In your specific example, what would happen if the error occurred before the code which assigns a value to Xlapp% or Xlbook% had been executed?

What is needed is some code that will create a variable if it does not already exist, but leave its value unchanged if it does. There are three pretty-much equivalent methods to achieve this:

Code:
      variable += 0      variable *= 1      variable = variable 

My habit is to use the first, but apart from possibly being slightly faster there's not a lot to choose between them.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls