# How do I clear a GROUP containing a GROUP with a DIM() Array?

**URL:** <https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502>\
**Category:** uncategorized\
**Created:** [September 28, 2024, 5:20pm UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502 "2024-09-28T17:20:28Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [September 30, 2024, 4:19pm UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502/22 "2024-09-30T16:19:27Z")

</div>

No need to be abusive when nice people are trying to help you out.

---

<div class="post-metadata">

**Author:** ![Genricke](https://clarionhub.com/user_avatar/clarionhub.com/genricke/32/5271_2.png) [@Genricke](https://clarionhub.com/u/Genricke)\
**Post date:** [September 30, 2024, 4:41pm UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502/23 "2024-09-30T16:41:52Z")

</div>

No ! Translation difficulties are possible …  
I am ready to read any answers, but I wanted to clarify my task.

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [September 30, 2024, 7:06pm UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502/24 "2024-09-30T19:06:10Z")

</div>

For testing I would change CSTRING to PSTRING because the 1st byte contains the length so messages clearly show Length=32 indicating it contains a Space i.e. \<20h\> = CHR(32). The Length of a CSTRING is based on finding the first CHR(0) which is not going to exist in a Group cleared to all Spaces, so LEN() returns is ???

* * *

You have proven that `Clear(gBarCode.overlay)` works. The Overlay GROUP has a DIM(3) so the Topic of “How do I clear a GROUP with an Array?” is not complete.

You have proven that `Clear(gBarCode)` fails to clear an inner child GROUP with a DIM(). So adjusting topic to note somethng about “inside a Parent GROUP”.

Note this problem will also happen on CLEAR of a RECORD or QUEUE containing a GROUP with DIM().

* * *

The `Clear(gBarCode)` works if there is no DIM() on Overlay. So the RTL properly handles clearing Group child fields … It fails that it treats Groups with DIM as a big STRING:

 ![image](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/b/b766f446d445e65d607e428feca2b5170175e613.png)

* * *

What will work for you is moving the DIM from the GROUP onto the Child fields:

 ![image](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/1/1b3431ffdfb8cb023707962565e64cca2a79186a.png)

 ![image](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/b/b8133e4e4e5dfdef892b00931f4ebf281439e451.png)

What also would work is changing CSTRING to a normal Clarion STRING. But Clear() has trouble with all types e.g. DECIMAL would = -2020.20.

---

<div class="post-metadata">

**Author:** ![Gustavo\_Saracca](https://clarionhub.com/user_avatar/clarionhub.com/gustavo_saracca/32/5355_2.png) [@Gustavo\_Saracca](https://clarionhub.com/u/Gustavo_Saracca)\
**Post date:** [September 30, 2024, 10:14pm UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502/25 "2024-09-30T22:14:35Z")

</div>

I understand your need to generate a Clear for any type of group.  
You could create a custom data type and store the original values to restore them when necessary. This way, you avoid depending on specific types.

Regarding the use of the STACK to clear a structure recursively, I don’t find a clear justification. However, it could be useful in more complex scenarios, such as generating JSON or XML from data structures.

```auto

TPrintList group,type
Task group,Dim(3)
Flag long,Dim(3)
Print bool(false)
type cstring(21)
text cstring(129)
Doc group,Dim(3)
Page long,Dim(3,3)
                        end
                    end 
                end
...
PrintListCleared like(TPrintList) ! Clear Structure.
PrintList like(TPrintList) ! Working Structure.
...

```

---

<div class="post-metadata">

**Author:** ![vitesse](https://clarionhub.com/user_avatar/clarionhub.com/vitesse/32/837_2.png) [@vitesse](https://clarionhub.com/u/vitesse)\
**Post date:** [October 1, 2024, 1:27am UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502/26 "2024-10-01T01:27:11Z")

</div>

> [@Genricke](#):
>
> I couldn’t do it. The idea was as follows:
> 
> ```auto
> EasyClear Procedure(*Group MyGroup)
> 
> ```

Hello again Genricke

I have made changes to your EasyClear to use howmany() for arrays as mentioned in my earlier message above.

```clarion
EasyClear Procedure(*Group MyGroup) !,long,proc
lCount Long
aFieldRef Any,Auto
pGroupRef &Group
dimCount long,auto
x long,auto
  code  
  loop
    lCount += 1
    aFieldRef &= What(MyGroup, lCount)
    if aFieldRef &= Null then break. ! End of Group

    dimCount = howmany(MyGroup, lCount)
    x = 1
    if dimCount > 1 then aFieldRef &= What(MyGroup, lCount, 1).
    loop
      if IsGroup(MyGroup, lCount)
        pGroupRef &= GetGroup(MyGroup, lCount, choose(dimCount > 1,x,0))
        if x >= dimCount
          lCount += easyClear(pGroupRef)
        else
          easyClear(pGroupRef)   
        end
      else
        clear(aFieldRef)
      end
      if x >= dimCount then break.
      x += 1
      aFieldRef &= What(MyGroup, lCount, x)
      if aFieldRef &= Null then break. ! just in case - should NOT happen
    end
  end
  return lCount - 1

```

> [@Genricke](#):
>
> If you show me your version, I’ll try to explain why it won’t work… 🤦‍♂️

OK well hopefully that works. If it doesn’t then please show an example where it fails and I will have a look at it - but as Jeff suggests, it is good to be polite and kind to those who are trying to help!

cheers again

Geoff R

---

<div class="post-metadata">

**Author:** ![Julian](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@Julian](https://clarionhub.com/u/Julian)\
**Post date:** [October 1, 2024, 1:35am UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502/27 "2024-10-01T01:35:17Z")

</div>

Have a look at the c function “memset” & try something like ..  
memset(address(theGroup),0,size(theGroup))

---

<div class="post-metadata">

**Author:** ![Mike\_Duglas](https://clarionhub.com/user_avatar/clarionhub.com/mike_duglas/32/1061_2.png) [@Mike\_Duglas](https://clarionhub.com/u/Mike_Duglas)\
**Post date:** [October 1, 2024, 6:32pm UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502/28 "2024-10-01T18:32:38Z")

</div>

BTW much easier without a recursion, just iterate over group fields one by one and CLEAR those that are a GROUP (and optionally HOWMANY \> 1).

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [October 2, 2024, 3:55am UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502/29 "2024-10-02T03:55:24Z")

</div>

> [@Julian](#):
>
> Have a look at the c function “memset” & try something like …  
> `memset(address(theGroup),0,size(theGroup))`

Interesting idea. For his Group it would work.

It would not work well if the Group contained the typical Clarion STRING types as they are not blank when filled with Chr(0).

It would work for CSTRING, PSTRING and all the numeric types. I think ASTRING is a LONG so it should work.

---

<div class="post-metadata">

**Author:** ![Genricke](https://clarionhub.com/user_avatar/clarionhub.com/genricke/32/5271_2.png) [@Genricke](https://clarionhub.com/u/Genricke)\
**Post date:** [October 2, 2024, 4:17am UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502/30 "2024-10-02T04:17:46Z")

</div>

> [@vitesse](#):
>
> OK well hopefully that works.

Thanks ! This is a beautiful and correct solution to my question.  
I checked the nested GROUPS, arrays and ANY fields - everything is OK !  
I need to learn how to make such code on my own …

---

<div class="post-metadata">

**Author:** ![vitesse](https://clarionhub.com/user_avatar/clarionhub.com/vitesse/32/837_2.png) [@vitesse](https://clarionhub.com/u/vitesse)\
**Post date:** [October 2, 2024, 12:56pm UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502/31 "2024-10-02T12:56:47Z")

</div>

> [@Genricke](#):
>
> Thanks ! This is a beautiful and correct solution to my question.

great thanks Genricke - glad you appreciated it - it is not everyday that someone comments that your code is “beautiful” 😊

I guess everyone has their own idea of beauty, but by chance I was recently reading a book that may be of interest:

_Beautiful Code: Leading Programmers Explain How They Think_  
_Edited by Andy Oram and Greg Wilson_

You can often learn from reading other people’s code and this book has contributions from 33 different developers. The foreword mentions:

_In May 2006, I asked some well-known (and not so well-known) software designers to dissect and discuss the most beautiful piece of code they knew. As this book shows, they have found beauty in many different places. For some, it lives in the small details of elegantly crafted software. Others find beauty in the big picture—in how a program’s structure allows it to evolve gracefully over time, or in the techniques used to build it._

---

<div class="post-metadata">

**Author:** ![Genricke](https://clarionhub.com/user_avatar/clarionhub.com/genricke/32/5271_2.png) [@Genricke](https://clarionhub.com/u/Genricke)\
**Post date:** [October 2, 2024, 2:51pm UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502/32 "2024-10-02T14:51:38Z")

</div>

Thanks for the recommendation - I’ll try to find such a book.  
I have such a desktop book with almost 900 pages.  
There are also a lot of examples of beautiful code in it. 😃

 ![2](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/b/bf98ae03a5ae0c9a9b07da806cda66e84241865d.jpeg)

---

<div class="post-metadata">

**Author:** ![PurpleEdge2214](https://clarionhub.com/user_avatar/clarionhub.com/purpleedge2214/32/5109_2.png) [@PurpleEdge2214](https://clarionhub.com/u/PurpleEdge2214)\
**Post date:** [October 3, 2024, 2:05am UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502/33 "2024-10-03T02:05:17Z")

</div>

> [@vitesse](#):
>
> Beautiful Code: Leading Programmers Explain How They Think

And it happens to be available as a PDF download!

I’ll definitely be having a browse, it will make an interesting change from the SciFi I’m reading ATM!

---

<div class="post-metadata">

**Author:** ![RchdR](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/d78d45/32.png) [@RchdR](https://clarionhub.com/u/RchdR)\
**Post date:** [October 3, 2024, 10:33am UTC](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502/34 "2024-10-03T10:33:06Z")

</div>

Ive never found a device thats easy on the eyes, and legible to read electronic txt. Still prefer paper.

[Previous page](https://clarionhub.com/t/how-do-i-clear-a-group-containing-a-group-with-a-dim-array/7502.md?page=1)
