The Variant is back!!

J

Jon Davis

Hi guys!

Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days.

// Here is an example of use:
// start with a string of "1"
Variant da = new Variant("1");
// add an integer of 2, becomes 3
da += 2;
// add a float of 1.3, becomes 4.3
da += 1.3F;
// add a string, becomes "4.3wow"
da += "wow";
// write "4.3wow"
Console.WriteLine(da);

I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give it 5 stars if you find it useful.

http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=2854&lngWId=10

Regards,
Jon Davis
 
L

Lloyd Dupont

I'm not sure it's really usefull...
anyway, in the case you do (which is most likely :)
I would suggest that instead of having
public short Short { get { } }

it could be better to have something like (not sure of the syntax)
public static explicit operator short(Variant v) {}
Hi guys!

Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days.

// Here is an example of use:
// start with a string of "1"
Variant da = new Variant("1");
// add an integer of 2, becomes 3
da += 2;
// add a float of 1.3, becomes 4.3
da += 1.3F;
// add a string, becomes "4.3wow"
da += "wow";
// write "4.3wow"
Console.WriteLine(da);

I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give it 5 stars if you find it useful.

http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=2854&lngWId=10

Regards,
Jon Davis
 
J

Jon Davis

Excellent idea. Will modify. Thanks, how did I miss this??

Jon


I'm not sure it's really usefull...
anyway, in the case you do (which is most likely :)
I would suggest that instead of having
public short Short { get { } }

it could be better to have something like (not sure of the syntax)
public static explicit operator short(Variant v) {}
Hi guys!

Just wanted to let you all know that I created a Variant structure,
inspired by the old VB6 days.

// Here is an example of use:
// start with a string of "1"
Variant da = new Variant("1");
// add an integer of 2, becomes 3
da += 2;
// add a float of 1.3, becomes 4.3
da += 1.3F;
// add a string, becomes "4.3wow"
da += "wow";
// write "4.3wow"
Console.WriteLine(da);

I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give
it 5 stars if you find it useful.


http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=2854&lngWId=10

Regards,
Jon Davis
 
D

Drebin

*Drops to knees, clenching fists skyward* "NOOOOOOOOOOOO!!!!!!!!!!!!"

That is the most evil scheme I've read about today. :-( Why in God's Green
Earth would you do this? You took the one MAJOR thing that Microsoft (very
wisely) did not perpetuate forward, and you made a workaround.

Is there anything more evil than the variant? If there is, I don't want to
know what it is.. :-(

(sigh)


All that aside, that is a cool little class/struct!! :) I just wish you'd
use your powers for good!!! :)




Hi guys!

Just wanted to let you all know that I created a Variant structure, inspired
by the old VB6 days.

// Here is an example of use:
// start with a string of "1"
Variant da = new Variant("1");
// add an integer of 2, becomes 3
da += 2;
// add a float of 1.3, becomes 4.3
da += 1.3F;
// add a string, becomes "4.3wow"
da += "wow";
// write "4.3wow"
Console.WriteLine(da);

I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give it
5 stars if you find it useful.

http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=2854&lngWId=10

Regards,
Jon Davis
 
J

Jon Davis

OK, I've completed this change.

Jon

I'm not sure it's really usefull...
anyway, in the case you do (which is most likely :)
I would suggest that instead of having
public short Short { get { } }

it could be better to have something like (not sure of the syntax)
public static explicit operator short(Variant v) {}
Hi guys!

Just wanted to let you all know that I created a Variant structure,
inspired by the old VB6 days.

// Here is an example of use:
// start with a string of "1"
Variant da = new Variant("1");
// add an integer of 2, becomes 3
da += 2;
// add a float of 1.3, becomes 4.3
da += 1.3F;
// add a string, becomes "4.3wow"
da += "wow";
// write "4.3wow"
Console.WriteLine(da);

I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give
it 5 stars if you find it useful.


http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=2854&lngWId=10

Regards,
Jon Davis
 
J

Jon Davis

Is there anything more evil than the variant? If there is, I don't want to
know what it is.. :-(

All that aside, that is a cool little class/struct!!

LOL. :) Well like I said in the header, many people view the variant as
ugly. I am somewhat among them, ... but then again, I kinda miss the little
booger.

Jon
 
W

W.G. Ryan eMVP

How about creating a class with No methods or properties, just GoTo
Statements ;-)

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
Hi guys!

Just wanted to let you all know that I created a Variant structure, inspired
by the old VB6 days.

// Here is an example of use:
// start with a string of "1"
Variant da = new Variant("1");
// add an integer of 2, becomes 3
da += 2;
// add a float of 1.3, becomes 4.3
da += 1.3F;
// add a string, becomes "4.3wow"
da += "wow";
// write "4.3wow"
Console.WriteLine(da);

I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give it
5 stars if you find it useful.

http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=2854&lngWId=10

Regards,
Jon Davis
 
J

Jon Davis

The thing about THIS variant is that it is still strongly typed... Sort of.
You still have access to the type information of the value, and you must
still be explicit in typecasting from it.

But I understand why Microsoft left this out. But IMO, if you're desperate
enough for a Variant that you're willing to copy the source code, you're
inevitably going to learn about the dangers of using it anyway. :)

Jon
 
S

SpotNet

Just when I got my programming act together dropping VB 6's kindness to advance my skills to C#'s preciseness, you're trying to do what to me? Nooooooooo!!! I've come too far for a Variant type. It's like going to the pub after an A.A. meeting with your A.A. mates. Jon don't look back you may turn to salt, you've already displayed alot of skill in what you've constructed, ironically you don't need a Variant type. Just a friendly opinion.

Regards,
SpotNet
Hi guys!

Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days.

// Here is an example of use:
// start with a string of "1"
Variant da = new Variant("1");
// add an integer of 2, becomes 3
da += 2;
// add a float of 1.3, becomes 4.3
da += 1.3F;
// add a string, becomes "4.3wow"
da += "wow";
// write "4.3wow"
Console.WriteLine(da);

I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give it 5 stars if you find it useful.

http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=2854&lngWId=10

Regards,
Jon Davis
 
D

Daniel O'Connell [C# MVP]

I tend to disagree with the prevailing opinon here. There is nothing wrong
with a Variant, per se. There are certainly times when a single type can
take on multiple views.

Even in the current atmosphere, when you are dealing with situations where
object models cannot be directly imported, for example xpath queries, how
often do you find yourself calling the particular overload for that value?
Wouldn't it be easier, at times, if you could pass a value that can be
considered any of them, depending on what the caller will eventually want?

This class, in and of itself is not a problem, bad usage of it certaily
would be.

Also, ironically, a Variant classes biggest use would probably be in a
runtime for underlying script systems.

The only problem I have with this is that, IMHO, the type properties should
be available. Explicit conversions are nice, but shouldn't be the only
avenue to any given functionality, IMHO.

Hi guys!

Just wanted to let you all know that I created a Variant structure, inspired
by the old VB6 days.

// Here is an example of use:
// start with a string of "1"
Variant da = new Variant("1");
// add an integer of 2, becomes 3
da += 2;
// add a float of 1.3, becomes 4.3
da += 1.3F;
// add a string, becomes "4.3wow"
da += "wow";
// write "4.3wow"
Console.WriteLine(da);

I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give it
5 stars if you find it useful.

http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=2854&lngWId=10

Regards,
Jon Davis
 
J

Jon Davis

It was a proof of concept to show that Microsoft wasn't in the least bit
simply too incompetent to reproduce the past, but that they made a willfull
choice not to provide something that actually was sometimes handy.

Jon



Just when I got my programming act together dropping VB 6's kindness to
advance my skills to C#'s preciseness, you're trying to do what to me?
Nooooooooo!!! I've come too far for a Variant type. It's like going to the
pub after an A.A. meeting with your A.A. mates. Jon don't look back you may
turn to salt, you've already displayed alot of skill in what you've
constructed, ironically you don't need a Variant type. Just a friendly
opinion.

Regards,
SpotNet
Hi guys!

Just wanted to let you all know that I created a Variant structure,
inspired by the old VB6 days.

// Here is an example of use:
// start with a string of "1"
Variant da = new Variant("1");
// add an integer of 2, becomes 3
da += 2;
// add a float of 1.3, becomes 4.3
da += 1.3F;
// add a string, becomes "4.3wow"
da += "wow";
// write "4.3wow"
Console.WriteLine(da);

I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give
it 5 stars if you find it useful.


http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=2854&lngWId=10

Regards,
Jon Davis
 
D

Drebin

I think what the problem here, is in philosophy. This is like gunmakers
doing away with safetys!! A gun without a safety isn't fundamentally *more*
dangerous, it's only when that gun is in a humans hands, does it pose a
bigger risk.

The variant *allows* people to do bad things in code, and for most that
would use it - they use it as a shortcut for a being a lazy coder.

So although in principle, there is nothing wrong with a variant - in the
hands of a skilled/competent developer, it's ironic that this is exactly the
kind of person who WON'T be using it.
 
J

Jon Davis

Tell that to the guys who invented it in the early VB days. What you call
"lazy", I might sometimes call productive.

Jon
 
D

Drebin

No, don't misunderstand - I mean lazy, because if you don't take the
time/effort to type a variable correctly, you are opening the door for an
assumption, and assumptions are what "software bugs" are. Assumptions are
bad, clarity is good!!

Productivity is only valuable if you don't have to pay an unreasonable price
for it. If you are productive, but your code is confusing, unmanageable or
based on undocumented assumptions - that's bad, even for the smallest of
programs. Mainly because we all know, even the smallest of apps have a habit
of turning into "enterprise applications"!!

This is clearly a philosophical difference, not a technical one - so this is
my side of it.. for whatever it's worth..
 
J

Jay B. Harlow [MVP - Outlook]

Jon,
Its interesting all the comments of the "evils" of the Variant. Which I am
not here to dispute! (As with OO you don't normally need a Variant).

What's interesting is that SQL Server 2000 added a Variant type as a
Database Type see sql_variant:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_setu-sus_4stw.asp

Just a thought
Jay


Hi guys!

Just wanted to let you all know that I created a Variant structure, inspired
by the old VB6 days.

// Here is an example of use:
// start with a string of "1"
Variant da = new Variant("1");
// add an integer of 2, becomes 3
da += 2;
// add a float of 1.3, becomes 4.3
da += 1.3F;
// add a string, becomes "4.3wow"
da += "wow";
// write "4.3wow"
Console.WriteLine(da);

I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give it
5 stars if you find it useful.

http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=2854&lngWId=10

Regards,
Jon Davis
 
P

Peter N Roth

a good exercise in typology! OTOH, my rating for use in actual projects: :blush:P

version 5 should be in C# 2.0 using generics, eh
--
Grace + Peace,
Peter N Roth
Engineering Objects International
http://engineeringobjects.com


Hi guys!

Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days.

// Here is an example of use:
// start with a string of "1"
Variant da = new Variant("1");
// add an integer of 2, becomes 3
da += 2;
// add a float of 1.3, becomes 4.3
da += 1.3F;
// add a string, becomes "4.3wow"
da += "wow";
// write "4.3wow"
Console.WriteLine(da);

I might actually use this puppy. :)

Anyway, here it is, source code and all, take a look and be sure to give it 5 stars if you find it useful.

http://www.planet-source-code.com/vb/scripts/showcode.asp?txtCodeId=2854&lngWId=10

Regards,
Jon Davis
 
J

Jon Davis

Its interesting all the comments of the "evils" of the Variant. Which I am
not here to dispute! (As with OO you don't normally need a Variant).

I'm not disputing it, either. The documentation is very detailed that the
Variant is considered dangerous. I did it because I "miss" the old beast,
and I wanted another little pet project for frills. I got inspired to do
this while refreshing myself on the stack vs. heap / classes vs. structs
while studying for MCSD certification.

But I do see some good use for it if I'm constantly jumping back and forth
between intrinsic types, and since I wrote the thing I will always know at
the back of my mind EXACTLY what's going to happen from my actions.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top