Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting a VB6 Function to .NET

Status
Not open for further replies.

Golom

Programmer
Sep 1, 2003
5,595
CA
I have a function in VB6 with a calling list that looks like this
Code:
Public Function GetPol(Policy_Name As String, Optional Obj As Object = Nothing) As Variant
The purpose of this thing is that it can be invoked with multiple different class objects as the second argument. The code sorts out what type of object it is and does the appropriate things depending on that result.

When I ask VB.Net to convert this to .Net syntax comes up with
VB.Net said:
In Visual Basic 2005, default properties are no longer supported; all property references must be fully qualified. During upgrade, default properties for early-bound objects are resolved to the property name; however, late-bound objects cannot be resolved because it is impossible to determine a default property without knowing what the object is.
Problem is ... the default properties are not being used. All properties in the passed in, late bound classes are fully qualified.

Is this just VB.Net bitching and moaning about something that isn't a real problem or do I need to overload this routine with explicit early-bound versions of every possible class that could be passed into it?
 
Everything inherits from object - you should be able to change the line to:

Code:
Public Function GetPol(Policy_Name As String, Optional Obj As Object = Nothing) As Object

The question remains - is this a good idea? Probably not, Variants were removed for a reason, but it should get you going in the right direction.
 
A very nice feature of .NET is the upgrade visual basic 6 code option underneath the tools menu. I plugged your code in and it gave exactly what SavantMan's code is above.


Swi
 
Let us rephrase that

Nearly everything inherits from Object.

Question does String inherit from Object?

Christiaan Baes
Belgium

"My new site" - Me
 
Chrissie,

I was under the impression that everything... and I do mean everything inherits from object. From what I can see, yes, string does inherit from object.


Am I misunderstanding something? I'm not meaning to be contradictory - I just find it odd that something I understood to be an absolute in your eyes apparently isn't.
 
Yes. I too asked .Net to upgrade the code and it did indeed produce the code that SavantMan posted.

The reason for the Variant in VB6 terminology was that the function can potentially return a string, number or boolean value. I suppose I can create a simple class to deal with that since VB.Net doesn't support variants.

The real issue I'm wondering about is .Net complaining about the "default property" of the second argument to this function. The code further down in the function (sorry I didn't post it) has references like
Code:
GetPol = Obj.Customer.Name
"GetPol" is of course the function name and "Obj.Customer.Name" is a value that I want to extract, having determined that "Obj" is a class that contains an instance of another class called "Customer" and that, in turn, has a "Name" property.
 
Yes it inherits from object but its a bit special in that it is imutable among other things. And then you have the primitive type like int and double which happen to be structs. That will react not like a normal object will. It will be used differently. Unlike smalltalk where everything really is an object it only seems to be an object in .net.

Christiaan Baes
Belgium

"My new site" - Me
 
in .net you should use

return ctype(obj,whatever).customer.name

or

return directcast(obj, whatever).customer.name



Christiaan Baes
Belgium

"My new site" - Me
 
So Savantman, I think I was confussing my Java with my .net it is less apparent in .net.

Christiaan Baes
Belgium

"My new site" - Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top