Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 511
  • Last Modified:

deleteItem is not deleting the item

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

0
coperations07
Asked:
coperations07
  • 5
  • 5
1 Solution
 
sandeep_patelCommented:
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
0
 
coperations07Author 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
0
 
sandeep_patelCommented:
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

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
coperations07Author 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
0
 
sandeep_patelCommented:
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
0
 
sandeep_patelCommented:
put,
ll_return = ddlb_sheet.deleteitem(i)
and check value of ll_return in debug mode
0
 
coperations07Author 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.
0
 
coperations07Author 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.
0
 
sandeep_patelCommented:
Are you sure you don't have any other code which populates this ddlb. Or is this the same ddlb you are referencing in code?

I know I am asking very foolish questions. But sometimes we do mistake.
Few tests...

1. make sure you don't have the other copy of the same window with same name
2. Once do full build.
3. First keep the code to remove brackets. Then add the code to delete items which are less than 8 chars. then add code to remove items for other conditions.
in other PBLs
4. In code change ddlb_sheet to ddlb_sheet1 and then hit save it will give error then go to layout and change the name of this ddlb.
5. create some sample window, put ddlb and a command button and test on that window.

Hope you will find something.
0
 
coperations07Author 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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now