Xojo Conferences
MBSOct2019CologneDE

Is this a bug or just not working for me? (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: Editfield bug in 4.02?
Next thread: KeyDown event


Re: WWDC Conferences   -   Troy A. Dix
  Is this a bug or just not working for me?   -   Graphireg4 aol.com
   Re: Is this a bug or just not working for me?   -   Will Leshner
    Re: Is this a bug or just not working for me?   -   Will Leshner
   Re: Is this a bug or just not working for me?   -   Totte Alm
   Re: Is this a bug or just not working for me?   -   Norman Palardy
    Re: Is this a bug or just not working for me?   -   Totte Alm
     Re: Is this a bug or just not working for me?   -   Norman Palardy
    Re: Is this a bug or just not working for me?   -   Thomas Reed
     Re: Is this a bug or just not working for me?   -   Norman Palardy
    Re: Is this a bug or just not working for me?   -   Eric M. Williams
    Re: Is this a bug or just not working for me?   -   Lars Jensen

Is this a bug or just not working for me?
Date: 07.05.02 03:46 (Tue, 7 May 2002 02:46:31 EDT)
From: Graphireg4 aol.com
Hi, I'm making a program for my college, that protects the computer from any
software installation. I've been having too much trouble with my code. I'm
using REALbasic 3.2.1 PPC MacOS 9.2.2 and 9.2.1. Here is the snippet of
code for everyone to see.

dim f as folderItem
dim i as integer
f=getfolderItem("Testing")
if f<>nil then
for ito f.count
f.item(i).delete
next
end if

What am I doing wrong? If I have 6 (or 5 or 10 or whatever amount) files in
the "testing" folder, it only ereases 3 (or more) and then gives me a
unhandle nilobject exception. can someone here help me with this? Am I
looping wrong? please help. This should be something very simple right?
Thanks in advance!

Beto

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Is this a bug or just not working for me?
Date: 07.05.02 07:52 (Mon, 6 May 2002 23:52:44 -0700)
From: Will Leshner
That may be because you are deleting the files out from under yourself
in the middle of the loop. Why don't you try first looping over the
items of the parent, making an array of the names of the children. Then
loop again deleting them by name:

f.child(name).delete

On Monday, May 6, 2002, at 11:46 PM, <email address removed> wrote:

> Hi, I'm making a program for my college, that protects the computer
> from any
> software installation. I've been having too much trouble with my
> code. I'm
> using REALbasic 3.2.1 PPC MacOS 9.2.2 and 9.2.1. Here is the snippet
> of
> code for everyone to see.
>
> dim f as folderItem
> dim i as integer
> f=getfolderItem("Testing")
> if f<>nil then
> for ito f.count
> f.item(i).delete
> next
> end if
>
> What am I doing wrong? If I have 6 (or 5 or 10 or whatever amount)
> files in
> the "testing" folder, it only ereases 3 (or more) and then gives me a
> unhandle nilobject exception. can someone here help me with this? Am I
> looping wrong? please help. This should be something very simple right?
> Thanks in advance!
>
> Beto
>
> ---
> Subscribe to the digest:
> <mailto:<email address removed>>
> Unsubscribe:
> <mailto:<email address removed>>

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Is this a bug or just not working for me?
Date: 07.05.02 07:56 (Mon, 6 May 2002 23:56:03 -0700)
From: Will Leshner
And, of course, it isn't going to work on any items that themselves are
folders.

On Monday, May 6, 2002, at 11:52 PM, Will Leshner wrote:

> That may be because you are deleting the files out from under yourself
> in the middle of the loop. Why don't you try first looping over the
> items of the parent, making an array of the names of the children. Then
> loop again deleting them by name:
>
> f.child(name).delete
>
> On Monday, May 6, 2002, at 11:46 PM, <email address removed> wrote:
>
>> Hi, I'm making a program for my college, that protects the computer
>> from any
>> software installation. I've been having too much trouble with my
>> code. I'm
>> using REALbasic 3.2.1 PPC MacOS 9.2.2 and 9.2.1. Here is the snippet
>> of
>> code for everyone to see.
>>
>> dim f as folderItem
>> dim i as integer
>> f=getfolderItem("Testing")
>> if f<>nil then
>> for ito f.count
>> f.item(i).delete
>> next
>> end if
>>
>> What am I doing wrong? If I have 6 (or 5 or 10 or whatever amount)
>> files in
>> the "testing" folder, it only ereases 3 (or more) and then gives me a
>> unhandle nilobject exception. can someone here help me with this? Am I
>> looping wrong? please help. This should be something very simple right?
>> Thanks in advance!
>>
>> Beto
>>
>> ---
>> Subscribe to the digest:
>> <mailto:<email address removed>>
>> Unsubscribe:
>> <mailto:<email address removed>>
> ---
> Subscribe to the digest: <mailto:realbasic-nug-
> <email address removed>>
> Unsubscribe:
> <mailto:<email address removed>>

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Is this a bug or just not working for me?
Date: 07.05.02 08:04 (Tue, 7 May 2002 09:04:16 +0200)
From: Totte Alm

On tisdag, maj 7, 2002, at 08:46 , <email address removed> wrote:

> Hi, I'm making a program for my college, that protects the computer
> from any
> software installation. I've been having too much trouble with my
> code. I'm
> using REALbasic 3.2.1 PPC MacOS 9.2.2 and 9.2.1. Here is the snippet
> of
> code for everyone to see.
>
> dim f as folderItem
> dim i as integer
> f=getfolderItem("Testing")
> if f<>nil then
> for ito f.count
> f.item(i).delete

just do f.item(1).delete

What happes is:

You delete file index 1, and all files have thier idnex lowered by one.

Think of it like a queue. When the first person gets his Star Wars
Episode II Tickets and leave the queue, number 2 becomes number one.

OK??

// Totte

> next
> end if
>
> What am I doing wrong? If I have 6 (or 5 or 10 or whatever amount)
> files in
> the "testing" folder, it only ereases 3 (or more) and then gives me a
> unhandle nilobject exception. can someone here help me with this? Am I
> looping wrong? please help. This should be something very simple right?
> Thanks in advance!
>
> Beto
>
> ---
> Subscribe to the digest:
> <mailto:<email address removed>>
> Unsubscribe:
> <mailto:<email address removed>>
----------------------------------------------------------------------------------------------
exec /bin/laden
mv /bin/laden /dev/null

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Is this a bug or just not working for me?
Date: 07.05.02 16:17 (Tue, 7 May 2002 09:17:19 -0600)
From: Norman Palardy
Always delete item 1
As you delete items their relative number changes and then you will get
an error about halfway through the list of them

ie
if you have 5 items (1,2,3,4,5)
now delete item 1
you now have (1,2,3,4) <<<<< NOTE not (2,3,4,5)
now delete item 2
you now have items (1,2,3)
delete item 3
you now have item (1,2)
and if you try to delete item 4 you're dead

On Tuesday, May 7, 2002, at 12:46 AM, <email address removed> wrote:

> Hi, I'm making a program for my college, that protects the computer
> from any
> software installation. I've been having too much trouble with my
> code. I'm
> using REALbasic 3.2.1 PPC MacOS 9.2.2 and 9.2.1. Here is the snippet
> of
> code for everyone to see.
>
> dim f as folderItem
> dim i as integer
> f=getfolderItem("Testing")
> if f<>nil then
> for ito f.count
> f.item(i).delete
> next
> end if
>
> What am I doing wrong? If I have 6 (or 5 or 10 or whatever amount)
> files in
> the "testing" folder, it only ereases 3 (or more) and then gives me a
> unhandle nilobject exception. can someone here help me with this? Am I
> looping wrong? please help. This should be something very simple right?
> Thanks in advance!
>
> Beto
>
> ---
> Subscribe to the digest:
> <mailto:<email address removed>>
> Unsubscribe:
> <mailto:<email address removed>>

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Is this a bug or just not working for me?
Date: 07.05.02 16:22 (Tue, 7 May 2002 17:22:26 +0200)
From: Totte Alm

On tisdag, maj 7, 2002, at 05:17 , Norman Palardy wrote:

> Always delete item 1
> As you delete items their relative number changes and then you will get
> an error about halfway through the list of them
>
> ie
> if you have 5 items (1,2,3,4,5)
> now delete item 1
> you now have (1,2,3,4) <<<<< NOTE not (2,3,4,5)
> now delete item 2
> you now have items (1,2,3)
> delete item 3
> you now have item (1,2)
> and if you try to delete item 4 you're dead
>

Norman,

didnt you think my "Star Wars Ticket Line" metaphore was good enough??

//Totte

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Is this a bug or just not working for me?
Date: 07.05.02 16:33 (Tue, 7 May 2002 09:33:31 -0600)
From: Norman Palardy
ummmm .... I wrote this before I saw your reply :-)

On Tuesday, May 7, 2002, at 09:22 AM, Totte Alm wrote:

>
> On tisdag, maj 7, 2002, at 05:17 , Norman Palardy wrote:
>
>> Always delete item 1
>> As you delete items their relative number changes and then you will
>> get an error about halfway through the list of them
>>
>> ie
>> if you have 5 items (1,2,3,4,5)
>> now delete item 1
>> you now have (1,2,3,4) <<<<< NOTE not (2,3,4,5)
>> now delete item 2
>> you now have items (1,2,3)
>> delete item 3
>> you now have item (1,2)
>> and if you try to delete item 4 you're dead
>>
> Norman,
>
> didnt you think my "Star Wars Ticket Line" metaphore was good enough??
>
> //Totte
>
> ---
> Subscribe to the digest: <mailto:realbasic-nug-
> <email address removed>>
> Unsubscribe:
> <mailto:<email address removed>>

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Is this a bug or just not working for me?
Date: 07.05.02 19:25 (Tue, 7 May 2002 13:25:38 -0500)
From: Thomas Reed
>if you have 5 items (1,2,3,4,5)
>now delete item 1
>you now have (1,2,3,4) <<<<< NOTE not (2,3,4,5)
>now delete item 2
>you now have items (1,2,3)
>delete item 3
>you now have item (1,2)
>and if you try to delete item 4 you're dead

Actually, note that this is not neccessarily the case! Note that the
original code was:

for ito f.count
f.item(i).delete
next

The way REALbasic handles loops means that f.count will be re-evaluated
each time through the loop. In most cases, the count won't actually
change until you're done with the loop and the Finder has had time to
update things, and you'll get the described behavior.

However, in a thread, things may be different. If you're running this
code in a thread, and you have 5 items (a,b,c,d,e), the first time
through the loop i is 1 and file 1 is deleted, to make the list
(b,c,d,e). The next time, i is bumpted up to 2 and the list becomes
(b,d,e). Next, i is bumped up to 3, and the list becomes (b,d). And the
last time, i becomes 4, but f.count is only 2 at this point, so it should
exit the loop with no reported errors.

In this case, it doesn't matter, the end result is wrong either way. But
you should be aware of how the end of the for loop is re-evaluated in RB
and how this can change your results.

-Thomas

Personal web page: http://home.earthlink.net/~thomasareed/
My shareware: http://home.earthlink.net/~thomasareed/shareware/
REALbasic page: http://home.earthlink.net/~thomasareed/realbasic/
Pixel Pen web pub. guide: http://home.earthlink.net/~thomasareed/pixelpen/

Any closet is a walk-in closet if you try hard enough.

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Is this a bug or just not working for me?
Date: 08.05.02 00:50 (Tue, 7 May 2002 17:50:12 -0600)
From: Norman Palardy
In fact you're right.
I just quickly, and wrongly, scanned it and assumed he evaluated count
once and used a local variable

On Tuesday, May 7, 2002, at 12:25 PM, Thomas Reed wrote:
>
> Actually, note that this is not neccessarily the case! Note that the
> original code was:
>
> for ito f.count
> f.item(i).delete
> next
>

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Is this a bug or just not working for me?
Date: 07.05.02 07:54 (Mon, 6 May 2002 23:54:37 -0700)
From: Eric M. Williams
You needed to delete "from the bottom up":

for iðcount downto 1
if f.directoryúlse then'is it a directory?
f.item(i).delete
else 'do something for directories, like recurse

end if
next

If you don't delete from the bottom up, you'll soon have nothing left
to delete, but the loop is still operating on the original f.count.

Enjoy -

Eric M. Williams
Seattle, Washington

>Hi, I'm making a program for my college, that protects the computer from any
>software installation. I've been having too much trouble with my code. I'm
>using REALbasic 3.2.1 PPC MacOS 9.2.2 and 9.2.1. Here is the snippet of
>code for everyone to see.
>
> dim f as folderItem
> dim i as integer
> f=getfolderItem("Testing")
> if f<>nil then
> for ito f.count
> f.item(i).delete
> next
> end if
>
>What am I doing wrong? If I have 6 (or 5 or 10 or whatever amount) files in
>the "testing" folder, it only ereases 3 (or more) and then gives me a
>unhandle nilobject exception. can someone here help me with this? Am I
>looping wrong? please help. This should be something very simple right?
>Thanks in advance!
>
>Beto
>
>---
>Subscribe to the digest:
><mailto:<email address removed>>
>Unsubscribe:
><mailto:<email address removed>>

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>

Re: Is this a bug or just not working for me?
Date: 07.05.02 15:03 (Tue, 07 May 2002 10:03:15 -0400)
From: Lars Jensen
Also, depending on what you want to delete, be aware that if you
encounter an alias, Item(i) will return the file the alias points to,
whereas TrueItem(i) will return the alias itself.

lj

---
Subscribe to the digest:
<mailto:<email address removed>>
Unsubscribe:
<mailto:<email address removed>>