We help IT Professionals succeed at work.

deleteItem is not deleting the item

coperations07
on
534 Views
Last Modified: 2013-12-26
Hi,
I'm using PB10.5
The attached code starts out by filling the ddlb w/ names of all folders and files(which I don't really want but am not sure how to avoid bringing in).  Then since all the folder names are surrounded by brackets when brought into the ddlb, the first loop in the code takes the brackets off.
The second loop is where the problem is located. First it checks if the sheetname is less than 8 char long. If it is less than 8 then it deletes it from the ddlb. This part works.
Else, if the sheetname does not start with 2 numbers and a letter then it should delete the item. This part DOES NOT work. When I debug the sheets that do not start w/ nbr,nbr,letter are caught in the IF statement and it gets into the "ddlb_sheet.deleteitem(i)" line and it looks like everything is working fine, but when the window comes up and I click the ddlb all the names are still there(except the ones that are less than 8 because that part works).

Any Ideas on this?

Thx,
Dave
//get sheet names from folders on harddrive.
ddlb_sheet.DirList("C:\Digital",16)
 
 
//clean-up sheet names in ddlb_sheet.
i = 1
maxRowCnt = ddlb_sheet.TotalItems()
 
do until i = maxRowCnt + 1
	ddlb_sheet.SelectItem(i)
	sCurrSheet = Trim(ddlb_sheet.Text(i))
	iSheetChars = Len(sCurrSheet)
	sCleanSheet = Mid(sCurrSheet,2,(iSheetChars - 2))
	ddlb_sheet.deleteitem(i)
	ddlb_sheet.additem(sCleanSheet)
	i = i+1
loop
 
 
//filter out non-sheets from ddlb_sheet
i = 1
maxRowCnt = ddlb_sheet.TotalItems()
 
do until i = maxRowCnt + 1
	
	ddlb_sheet.SelectItem(i)
	sCurrSheet = Trim(ddlb_sheet.Text(i))
	iSheetChars = Len(sCurrSheet)
	
	If iSheetChars < 8 then
		ddlb_sheet.deleteitem(i)
	else
		if not match(sCurrSheet, "^[0-9][0-9][A-Za-z]") then
			ddlb_sheet.deleteitem(i)
		end if
	end if
	i = i + 1
loop

Open in new window

Comment
Watch Question

Ok...The problem is that you are deleting items and increasing value of i hence it is skipping the items..change you conditions like below....

//filter out non-sheets from ddlb_sheet
maxRowCnt = ddlb_sheet.TotalItems()
i = maxRowCnt
do until i = 0
      ddlb_sheet.SelectItem(i)
      sCurrSheet = Trim(ddlb_sheet.Text(i))
      iSheetChars = Len(sCurrSheet)
      If iSheetChars < 8 then
            ddlb_sheet.deleteitem(i)
      else
            if not match(sCurrSheet, "^[0-9][0-9][A-Za-z]") then
                  ddlb_sheet.deleteitem(i)
            end if
      end if
      i = i - 1
loop

Regards,
Sandeep

Author

Commented:
I switched the code, but the items are still not deleting and showing up in the ddlb. I attached a couple of screen shots from when I debugged.

thx,
Dave
Doc1.doc
I doubt, you also changed
i = maxRowCnt and placed after maxRowCnt = ddlb_sheet.TotalItems() ???

see in my previous comment. If you have already changed it let us know what are all files and folders under 'c:\digital' Hence i can replicate in my local machine with the same code.

Regards,
Sandeep

Author

Commented:
I attached the code that I have now. I did change the row count variables.
I also attached a screen shot of the file & folder names on C:Digital.
//filter out non-sheets from ddlb_sheet
 
maxRowCnt = ddlb_sheet.TotalItems()
i = maxRowCnt
do until i = 0
	
	ddlb_sheet.SelectItem(i)
	sCurrSheet = Trim(ddlb_sheet.Text(i))
	iSheetChars = Len(sCurrSheet)
	
	If iSheetChars < 8 then
		ddlb_sheet.deleteitem(i)
	else
		if not match(sCurrSheet, "^[0-9][0-9][A-Za-z]") then
			ddlb_sheet.deleteitem(i)
		end if
	end if
	
	i = i - 1
loop

Open in new window

Doc1.doc
Really wierd...works great in my system...Here is the screen shot and code attached. Try once more copying the same code from document.

I m using PB 10.5 Build 4523
ee-deleteitem.doc
put,
ll_return = ddlb_sheet.deleteitem(i)
and check value of ll_return in debug mode

Author

Commented:
(insert frustrated smiley face here...banging head on keyboard)

I commented out the code I had and pasted yours in. Then I ran it and it still fiiled the ddlb w/ all the items except the ones that were < 8.  I put ll_return in there and it ends up w/ a value of 10 which is the number of items that should be in the box.  Everytime it got into the if statement the ll_return would subtract 1. But still all the items showed in the ddlb.

Now this next part is what's really throwing me for a loop (pardon the pun).
I took out the code that deletes the items that are < 8. But it changed nothing. All the items < 8 still get deleted, but none of the rest!?!?? I'm completely lost.

Author

Commented:
Geez. I took the whole loop out and ran it. The items < 8  are still getting taken out even without the loop that takes them out. So I added a new folder called "00000000" and ran it. The new folder showed up in the box. Then I renamed it "0000" and it still shows up, but not the other ones that are less than 8 chars. It's like it's stuck in memory or something.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Well...guess I just needed a weekend to refresh.
I found what the problem was. The code we had been looking at was tied to the open event of the window. There are also 2 option buttons on the window with code that changes the contents of the ddlb when they are ticked. I hadn't thought about that event getting triggered when the form opened, but I guess it does. The code in the option button was the same as what I had in the open event to fill the ddlb, but then I added the Match function and it wasn't in the option button. The only reason I realized what was happening was because I accidentally clicked the other option button while I was going through your steps(sandeep) and I realized that the contents of the ddlb changed when I clicked the option button.

Maybe I'm not going crazy after all...

Thanks for all the help,
Dave

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.