Possible to reference a property of a class by the class itself like VB6?

Hey there,

I was wondering if it was possible to reference a property or method by the class itself. That property would depend on the data type of the passed value.

I am thinking of something similar to what you can do with VB6. I have never really played around with VB6 for at least 5 or 6 years. I have more recently (in the past 4 years) read about this in a VB.NET (it compared .net to the classic VB6) book. BUT I seem to remember that VB6 and/or VBA allowed you to assign a textfield’s text by referencing the class itself?? So it would saving you from typing this:

textfield1.text = "your text"

And you could refer to the text property with:

textfield1 = "your text"

Can I use something like operator overloading to achieve this or is this just not recommended code practice these days?

Thanks

That was one of my main annoyances with VB6. Be explicit and the next guy to read your code will have a better idea what is going on.

The idea is, I have a class that would give you the same behaviour as a data type like an integer, double or string apart from it sets a boolean variable internally to state that the value has been changed.

Thanks

I do not think it makes the code confusing.

Thanks

Look at Operator_Convert.

[quote=141979:@Oliver Scott-Brown]I do not think it makes the code confusing.

Thanks[/quote]
You have never seen what I refer to as “Mike code”. It is a scary thing to behold.

To me this is a bit different than what you were describing in the OP and makes sense. I’ve never done that but I tend to error on the verbose side in code.

[quote=141987:@Bob Coleman]You have never seen what I refer to as “Mike code”. It is a scary thing to behold.

To me this is a bit different than what you were describing in the OP and makes sense. I’ve never done that but I tend to error on the verbose side in code.[/quote]
Sorry for my explanation.

Thanks

You have nothing to apologize for you were using it as an example and I misinterpreted.

Okay. No worries.

You won’t be able to make this work
The name of the control is basically reserved and so trying to make a new method of your own that takes on the same name will not be possible

[quote=142023:@Norman Palardy]You won’t be able to make this work
The name of the control is basically reserved and so trying to make a new method of your own that takes on the same name will not be possible[/quote]
Okay, thanks. I was not planning on using this like I was showing in the example so that will not be a problem.

The closest you can get is to use a string Computed Property called TextArea1_ and use set and get to access TextArea1.Text.

That said, unless you plan on writing 2000 lines of code around TextArea1.Text, it probably is safer to keep the traditional notation.

[quote=142030:@Michel Bujardet]The closest you can get is to use a string Computed Property called TextArea1_ and use set and get to access TextArea1.Text.

That said, unless you plan on writing 2000 lines of code around TextArea1.Text, it probably is safer to keep the traditional notation.[/quote]
I know this. I could decide for myself how I wanted to distinguish the original from this. As I said, it is just an example and I do not plan to do this.

Thanks