« COMLIB Cleanup »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 6:03pm

Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

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

member is offline



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.
DEF PROCcleanup
Xlapp%  += 0 : IF Xlapp%  PROC_releaseobject(Xlapp%)  : Xlapp% = 0
Xlbook% += 0 : IF Xlbook% PROC_releaseobject(Xlbook%) : Xlbook% = 0
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 ?

User IP Logged

Richard Russell

member is offline


Homepage PM

Posts: 689
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:

      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.

User IP Logged

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

Donate $6.99 for 50,000 Ad-Free Pageviews!

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls