cancel
Showing results for 
Search instead for 
Did you mean: 

VB Crashes when accessing any UDF thru DIAPI

Former Member
0 Kudos

I'm using 2005A, PL05 (6.80.123)

Whenever I access any property of a User Defined object, VB crashes (no jokes, please ;-). It can be somthing as simple as this:


Dim sboCompany As SAPbobsCOM.Company
' connect to SBO...

Dim sboPoHead As SAPbobsCOM.Documents
Set sboPoHead = sboCompany.GetBusinessObject(oPurchaseOrders)
sboPoHead.GetByKey(poNum)

Dim sboUf As SAPbobsCOM.UserFields 
Set sboUf = sboPoHead.UserFields

Dim sboField As SAPbobsCOM.Field
       
For Each sboField In sboUf.Fields
    Debug.Print sboField.Name
    Debug.Print sboField.Description
Next sboField

You get the idea: connect to SBO; get a PO; get its UDFs; look at them one by one.

That first "Debug" line, where I'm trying to print the Name property of the first UDF object, that's where VB bites it. Full blown "do you want to send an error report" and close the app crash. It happens when I try to do this too:


sboPoHead.UserFields.Fields(0).Name

I just wanted to see exactly where the error occurred.

Anyone seen this? Is it fixed in PL06? I'm I doing something grossly stupid?

Accepted Solutions (1)

Accepted Solutions (1)

barend_morkel2
Active Contributor
0 Kudos

Knute,

Add a try-exception block and show the exception message (with a message box). Then you should see what is causing the crashes. It's always good practice to have these try-exception block around code - very safe and it's keeps your application from falling over (or even crashing)

Former Member
0 Kudos

It's VB6 (that's why I said don't laugh) so no try-catch, but all my important code is under an "On Error Goto". I can try writing a test in VB.NET.

But more importantly, it's not just my app that craches, but VB6.EXE, the actual development environment that crashes. I don't go to the exception code, I get a message from Windows saying that VB6.EXE encountered an error and has to shut down. Perhaps in my attempt to be jocular I wasn't clear.

Former Member
0 Kudos

Well what do you know? It works in VB.NET. That'll teach me to use old technology.

But seriously, wow, someone should say (maybe they have?) that the 2005 SDK is not compatible with VB6. Looks like I'll be rewriting my app.


Try
    using VB6
Catch ex As Exploding.Program
    write to forum
Finally
    rewrite in VB.NET
End Try

former_member185703
Active Contributor
0 Kudos

I am terribly sorry that I have to tell you that <b>your code works</b> - without any issue - <b>in VB6 on 2005 SDK</b> (build 6.80.120 PL 01).

<b>I.e. there's no issue with VB6 and 2005 SDK in general!</b> ... since the APIs are still COM bound anything else would be a big surprise.

Maybe there's some issue with the exact patch you are on?

Please try the latest patch and report your error to SAP Support through SAP Service Marketplace when you can't get it working.

Thanks,

Frank

Former Member
0 Kudos

Don't be sorry! Thanks for testing it.

I'm on patch PL05, or more accurately, my client is. I have support message started on the issue.

My collegue (who knows Windows programming better than I do) was also surprised that a COM would act differently on VB6 and VB.NET. I'll check the patches on my VB6.

Answers (1)

Answers (1)

former_member185703
Active Contributor
0 Kudos

Hi Knute,

first-of-all you should check the (boolean) return value of the GetByKey!

Then - as Barend recommended - capture the error + check the error text (I assume that there is such a thing in VB6 as well?).

>sboPoHead.UserFields.Fields(0).Name

Please check in CUFD whether there is a field in that table with FieldID = 0 - since the FieldIDs of the subsequent UDFs in a particular table will asfaik not be updated when you remove the first UDF!

Maybe I overlooked something else, but I...

...HTH,

Frank

Former Member
0 Kudos

> first-of-all you should check the (boolean) return value of the GetByKey!

I do; I left it out in the interest of brevity.

> then - as Barend recommended - capture the error + check the error text

See above.

> Please check in CUFD whether there is a field in that table with FieldID = 0

You're right, there is no FieldID = 0 for OPOR (the table I'm looking at). I was wondering how you know what "index" to use (as the Help File puts it). Originally, the code looked more like this:

sboPoHead.UserFields.Fields("U_MP2_PoNum").Value

When the system kept crashing I figured I'd loop through the Fields collection to look for valid names. That's when I discovered that any reference to the UDF's properties causes a crash.