Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I want to create my own object type called SWIFTBIC. This object will essentially be a String but it will have built in validation to ensure that the assigned value can only be a valid SWIFTBIC. Valid SWIFTBIC's are 6 characters followed by either 2 or 5 alphanumerics (Regular Expression "[A-Z]{6}([A-Z0-9]{5}|[A-Z0-9]{2})").

 

This in itself is fairly straight forward. However, my problem comes from the way I want to be able to use my SWIFTBIC. I want it to behave in the same way a String variable does, so that reading and writing to the objects value can be done directly as follows:

 

Dim mySB as SWIFTBIC
mySB = "ABCDEFGH"
myTextBox.Text = mySB

I realise that the direct assignment may not be possible without using a constructor:

 

mySB = new SWIFTBIC("ABCDEFGH")

That I can live with, but how can I get access to the objects value directly without having to specify a property? I've tried using default properties but that won't work without a parameter. I've also tried inheriting a String but that isn't allowed either.

 

Is there any way to do what I want (using VB.NET preferably)?

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted

You'll have to overload every operator that you'll need.

You might use the "+" and "=".

 

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconoperatoroverloadingusageguidelines.asp

This is the link of Microsoft help on that. It'll give all syntax in VB.NET to do a correct operator overloading.

 

The overload will obviously be made in your class.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

damn... I thought it could be possible...

Forget it... My error...

VB really sux.... not even a small operator overloading...

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted
Cheers people. Looks like it's finally time I got stuck into C#.

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted

C# not a bad choice ;)

but C++ is good also (I don't have time learn it... but if I get a week or two... I'll get my head on that)

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

Dim mySB as SWIFTBIC

mySB = "ABCDEFGH"

myTextBox.Text = mySB

 

A good (and standard) alternative is fleshing out your custom ToString() method so that you can do:

 

myTextBox.Text = mySB.ToString()

 

Not exactly what you're looking for but makes your class consistent w/ the .NET stock classes.

Posted
damn... I thought it could be possible...

Forget it... My error...

VB really sux.... not even a small operator overloading...

I really feel your pain. . .

 

Been spending the last six weeks on a VB contract working with a legacy app. The client wants it in VB because he can read VB.

 

VB is the worst thing that ever happened to software development!!!!

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

  • *Experts*
Posted

You don't necessarily have to do C# for everything. You could put the new type in a separate C# project and just reference it from your VB.NET projects.

 

Of course for what you want (a new type with a lot of operator overloading), you'll need to know a bit of semi-advanced C#. If you're just starting out at programming or willing to make the move, maybe a move to C# is warranted. But, if you have a lot of time spent learning the ins and outs of VB.NET, you might try doing the minimum to get your class implemented in C#.

 

For what you want (a direct assignment as if your type were a string) you'll need the implicit operator overloads (when you look up operator overloading look for the topics on "implicit").

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Thanks. I am an experienced VB.NET developer (been using VB since version 4) but have been considering learning C# too. It seems now is as good a time as any to get started.

 

 

By the way - is it possible to mix C# and VB within a single project/assembly?

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted

By the way - is it possible to mix C# and VB within a single project/assembly?

 

You can't mix raw .cs and .vb files in a single project/assembly but you can add references to other .NET assemblies regardless of w/c language they were written (as long as CLS rules have been dutifully conformed with). So you can instantiate (and even subclass) the public types of a compiled C# assembly in a VB.NET project.

Posted

I realise that, but what I'm worried about is having to re-work the rest of my project into C# just because I need C# for one particular object. I was hoping I could incorporate a C# class into the existing project without having to re-do all of it.

 

To clarify, the project is a common library that we use within our projects which encapsulates commonly used objects and functions. We are reluctant to split it into more than one library so it looks like we will have to convert all of it to C#.

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...