PxPlus User Forum

Twitter Twitter Twitter

Author Topic: CLEAR vs CLEAR Composite string  (Read 708 times)

Mike Hatfield

  • Gold Member
  • ****
  • Posts: 58
    • View Profile
CLEAR vs CLEAR Composite string
« on: May 15, 2019, 05:47:28 AM »
I know what CLEAR does to the program space.
I think the documentation is a bit ambiguous for CLEAR composite string
I can't see any difference in the two forms.
I interpreted CLEAR composite String to ONLY clear the Composite string but it CLEARS the stack as well

CLEAR
CLEAR MORDER${all}
Both clear the for/next/gosub stack
Is this correct?
If so, what is the point of having a separate format 2?
Mike H

JR

  • Member
  • **
  • Posts: 8
    • View Profile
Re: CLEAR vs CLEAR Composite string
« Reply #1 on: February 11, 2021, 12:18:16 PM »
Hi,

I ran into the same conclusion.
CLEAR MORDER${all}
clear the FOR stack ?

To avoid this, is it better to use DIM MORDER$ ?

JR

  • Member
  • **
  • Posts: 8
    • View Profile
Re: CLEAR vs CLEAR Composite string
« Reply #2 on: February 12, 2021, 12:32:53 AM »
->list
0010 REM
0020 BEGIN
0030 FOR I=1 TO 10
0040 CLEAR T${ALL}
0050 NEXT I
->run
0050 NEXT I
Error #28: No corresponding FOR for NEXT
Current program is /tmp/pvx/poub, line 50

RobL

  • Member
  • **
  • Posts: 13
    • View Profile
Re: CLEAR vs CLEAR Composite string
« Reply #3 on: February 14, 2021, 05:10:58 PM »
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