Hi Mike / JR,
I played around with this a bit this weekend.
Format 2 of the CLEAR directive works the same as Format 1 when you specify a list of variables.
It will:
- reset PRECISION to the default value specified by the 'PD' parameter (2 is the default).
- clear the FOR/GOSUB/WHILE stack.
- clear the DATA (not the ATTRIBUTES) from the variable DIMensioned as a composite string.
When I run the following program...
begin
!
precision 10
!
cust:iolist custnum$,custname$,balance
dim cust$:iol=cust
cust.custnum$="123",cust.custname$="ABC Supply",cust.balance=456.78
!
print "default PRC: ",prm('PD'),'LF'
!
for 1
print "Before CLEAR"
print "precision: ",prc
print "cust$....: ",lst(iol(cust$))," - ",sub(cust$,sep,"|")
!
clear cust$
!
print 'LF',"After CLEAR"
print "precision: ",prc
print "cust$....: ",lst(iol(cust$))," - ",sub(cust$,sep,"|")
!
next
... I get the following results:
->run
default PRC: 2
Before CLEAR
precision: 10
cust$....: iolist custnum$,custname$,balance - 123|ABC Supply|456.78|
After CLEAR
precision: 2
cust$....: iolist custnum$,custname$,balance - ||0|
next
Error #28: No corresponding FOR for NEXT
Current program is D:\PxPlus\Projects\Default\rob1, line 24
I ran this test on PxPlus 2020 Ver 17.10 on Windows and PxPlus 2016 Ver 13.00 with the same result.
If you change 'cust$' to 'cust.custname$', only that field is cleared.
I think the docs are wrong. The DIM directive (Format 2 - Define Composite String) documentation states that "You can use the CLEAR directive to reset a variable that is defined as a string template". What is meant by 'reset' may be debatable, but the attributes are definitely not being cleared as stated on the CLEAR directive page.
I don't use the CLEAR directive (at least, not that I can remember). To clear the data from a composite string I use 'cust$=""', and to clear the attributes I use 'DIM cust$(0)'.
Also, something else to note: when using CLEAR, don't forget that CLEAR also affects REPEAT..UNTIL/SWITCH..END SWITCH/WITH..END WITH. I think that's the complete list...
Regards,
Rob Leighton