Notices


Reply
 
LinkBack Thread Tools Display Modes

Old 01-10-2007, 01:19 PM   #1 (permalink)
Junior Member

Join Date: Jan 2007
Posts: 9
Rep Power: 0 dwalker is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- API/VBA

API errors while reading Notepads

I'm using VB.NET and the RE api to read and delete all
Notepads of a certain type. The problem is that sometimes the
program tries to read into protected storage, meaning (I think) that it
is trying to read too many notepads. The 'Catch' never happens; the program just halts. The stmt given is always the first 'Next'.

The program will run without halting in Debug mode, but I'd like to find out
what's causing the problem.

Ideas anyone?

Here is the code:

Code:
 
Dim oRecords As CRecords
oRecords = New CRecords
 
oRecords.Init(RE7.SessionContext)
 
Dim oRecord As CRecord
oRecord = New CRecord
 
' scroll through each record..
For Each oRecord In oRecords
' scroll through all the Notepads....
 
If oRecord.Notepads.Count > 0 Then
For x = 1 To oRecord.Notepads.Count
 
Try
If oRecord.Notepads.Item(x).Fields(ENotepadFields.NOTEPAD_fld_NotepadType) = "AS400 Daily Feed" Then
oRecord.Notepads.Remove(x)
oRecord.Save()
Exit For
End If
Catch ex As Exception
End Try
Next
 
End If
 
Next

Last edited by Peter Gulka; 01-10-2007 at 01:40 PM. Reason: added CODE tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 01-10-2007, 01:26 PM   #2 (permalink)
Crystal Reports Guru

DrewAllen's Avatar

Join Date: May 2006
Location: Philadelphia, PA
Posts: 1,154
Rep Power: 4 DrewAllen is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- Information Edge (TIE)
- API/VBA

Don't you need an oRecord.Close() somewhere in there before moving on to the next oRecord?

Drew
__________________
J. Drew Allen
Children's Hospital of Philadelphia

Crystal Reports and SQL Server Consultant

It is better to live your destiny imperfectly than to live an imitation of somebody else's life with perfection.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 01-10-2007, 02:49 PM   #3 (permalink)
Junior Member

Join Date: Jan 2007
Posts: 9
Rep Power: 0 dwalker is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- API/VBA

Good point, I'll give it a try.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 01-10-2007, 02:59 PM   #4 (permalink)
Junior Member

Join Date: Jan 2007
Posts: 9
Rep Power: 0 dwalker is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- API/VBA

There is no Close() method for oRecord, only CloseDown(), which distroys the object.

Here is the message text:

AS400 Daily Feed...

Unhandled Exception: System.Runtime.InteropServices.COMException (0x800A005B): O
bject variable or With block variable not set
at REDotNetAPI._CRecord.get_Notepads()
at REDailyFeed.Module1.Main() in C:\Documents and Settings\dwalker\My Documen
ts\Docs\data\Visual Studio Projects in VSS\vbwork\blackbaud\REDailyFeed\REDailyF
eed\Module1.vb:line 62
Press any key to continue . . .


Line 62 is:
If oRecord.Notepads.Count > 0 Then
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 01-10-2007, 04:06 PM   #5 (permalink)
Junior Member

Join Date: Jan 2007
Posts: 9
Rep Power: 0 dwalker is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- API/VBA

Found the problem!

When you iterate through the CRecord classes from CRecords, you
need to call the CRecord.Init() function each time. This isn't stated in the documentation, but my program started working properly when I did this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 01-10-2007, 04:59 PM   #6 (permalink)
Junior Member

Join Date: Jan 2007
Posts: 9
Rep Power: 0 dwalker is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- API/VBA

Oops! Spoke too soon. That didn't fix the problem, all it did was to clear the
oRecord.Notepads.count to zero so it never tried to read any notepads.

Still working on the problem
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 01-11-2007, 03:50 AM   #7 (permalink)
Likes to customize RE!

DavidZ's Avatar

Join Date: Jul 2006
Location: London, UK
Posts: 335
Rep Power: 3 DavidZ is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- API/VBA

Did you try doing a for each for the notepads instead of counting them?

as follows:

Code:
 
Dim oNotepad as IBBNotepad
 
for each oNotepad in oRecord.Notepads
'Remainder of your code
 
Next oNotepad
It is also possible that it does not like you remove notepads as you try to iterate them. Try commenting out remove line and see if you get the same error.

You do need to closedown top level objects when iterating through them in a collection.

David
__________________
David Zeidman
Zeidman Development
http://www.zeidman.info

Check out my RE API blog
http://www.re-decoded.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 01-11-2007, 10:39 AM   #8 (permalink)
Junior Member

Join Date: Jan 2007
Posts: 9
Rep Power: 0 dwalker is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- API/VBA

OK, that seems to make sense, but how do I delete the notepad?
I get confused by the interface classes.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 01-12-2007, 03:20 AM   #9 (permalink)
Likes to customize RE!

DavidZ's Avatar

Join Date: Jul 2006
Location: London, UK
Posts: 335
Rep Power: 3 DavidZ is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- API/VBA

Quote:
Originally Posted by dwalker View Post
OK, that seems to make sense, but how do I delete the notepad?
I get confused by the interface classes.
When I use the following code I do not get a problem. Having said that I am using VBA so maybe it is more tolerant of such things:

Code:
 
Dim oRecord As New CRecord
   Dim oNote As IBBNotepad
   
    oRecord.Init SessionContext
    oRecord.LoadByField uf_Record_CONSTITUENT_ID, "3"
    For Each oNote In oRecord.Notepads
        If oNote.Fields(NOTEPAD_fld_NotepadType) = "Delete" Then
            oRecord.Notepads.Remove oNote
        End If
        
    Next oNote
However if there is an issue with deleting while iterating, you could store the notepad ids (oNote.Fields(NOTEPAD_fld_Id) ) in a collection and then later loop through the collection and remove them. The remove method takes both a notepad object and an id, that way you do not need to actually loop the collection of notepads.

David
__________________
David Zeidman
Zeidman Development
http://www.zeidman.info

Check out my RE API blog
http://www.re-decoded.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 01-12-2007, 11:35 AM   #10 (permalink)
Junior Member

Join Date: Jan 2007
Posts: 9
Rep Power: 0 dwalker is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- API/VBA

I just recently got the program working. The main problem was the .NET interface. It just doesn't seem to work right. I dug up an old box from storage, blew off the dust, and got out my old VB 6.0 CDs, then went to the thrift shop and bought a VB 6.0 book for 35 cents...

I ended up saving the indexes of the notepads to delete, then accessing them later in a loop to remove them. The .NET interface really doesn't like removing an item during an iteration of the collection. It seems to get lost and read beyond the collection boundry. VB 6.0 handles it ok.

At first, I wasn't happy about needing VB 6, but it actually made me see really how cumbersome .NET is!

If anyone is having strange problems using the API through the .NET interface, switch to VB 6.

Thanks for all your help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

Old 01-22-2007, 11:59 PM   #11 (permalink)
o o o o o o o o o o o o o o o o o o

JeffMon's Avatar

Join Date: Aug 2006
Location: Charleston, SC
Posts: 54
Rep Power: 3 JeffMon is on a distinguished road

Blackbaud Products
- Raiser's Edge (RE)
- Financial Edge (FE)
- API/VBA

Talking Garbage Collection

I totally hear ya about the overhead of .Net vs. VB6. I like to think that .Net is worth all the fuss, but I have to admit I get a great feeling of relief when I open an old VB6 project - the simplicity is refreshing. Then as soon as my code lines don't indent themselves automatically I'm ready to go back. ;-)

Anyway, I'll bet dollars to donuts that the issue you experienced is a GarbageCollection issue related to the fact that (as Drew mentioned) you are not closing down the objects. This bit me hard once with .Net. The error did not "respect" my try...catch block error handling and seemed to happen at random times. Looks like you've solved your issue using VB6, but I'll post it here in case it can help anyone in the future. There are some cases where you don't close down an object you're using (like when you're handed an object in a VBA event), but most of the time the rule of thumb is "if you opened it, you close it". In your case, you must call CloseDown on each and every record you process in your For Each loop. Also, when dealing with COM objects from .Net, it's usually a good idea to call this on your COM object when you're done with it:

System.Runtime.InteropServices.Marshal.ReleaseComObject(o)

I've created a proc that I send all my top-level RE COM objects to when I'm done with them. It handles the CloseDown for you on Top Level objects (Record, Gift, etc). I should probably add a few other interfaces to look for too. Anyway, it looks like this:

Code:
PublicSub CloseREObject(ByVal o AsObject)
'Dispose of COM objects (works on any COM objects, especially ibbTobObjects)
If o IsNothingThenExitSub
Dim oTO As Blackbaud.PIA.RE7.BBREAPI.IBBTopObject = TryCast(o, Blackbaud.PIA.RE7.BBREAPI.IBBTopObject)
If oTO IsNotNothingThen
oTO.CloseDown()
oTO = Nothing
EndIf
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(o)
Catch
Finally
o = Nothing
EndTry
EndSub 
A couple other things from above:
  • Nope, there is no need to call "Init" on the record object when you're getting it from a collection you init'ed. I believe that will "flash" your object to a brand spanking new object, which is why you saw it "clear the oRecord.Notepads.count to zero"
  • There is no need to set the record object = New Record before using it in the For Each loop
  • I recommend the For Each loop for your notepads. There shouldn't be an issue removing them while you're iterating through the loop, but it doesn't look like that would be an issue anyway since you're assuming there's only one of that notepad type per record (or at least I'm assuming that you're assuming, based on your "Exit For" in there).
  • Make sure you closedown your Records collection
  • VBA is ~great~ for this sort of stuff. Talk about low overhead!
-Jeff
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
api, notepad


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Cheap Electricity - Credit Cards - Loan - Credit Counseling
All times are GMT -6. The time now is 11:41 AM.

Miscellaneous


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by BBpixel Team 2008 :: jvbPlugin R1012.364.1

SEO by vBSEO 3.2.0 Copyright 2008 Blackbaud User SocietyAd Management by RedTyger
Inactive Reminders By Icora Web Design

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64