operator overloding in VB
-
Is it possible to use operator overloading in visual basic. I just try to do it on vb6.0 using + operator(i.e to plus with numeric number and concatenate with string number). But this does not work properly. Any idea? ---------------------CODE--------------------- Private Sub cmdDo_Click() Dim ty If ((VarType(Me.txtInput.Text) = vbString) And (VarType(Me.txtOutput.Text) = vbString)) Then ty = Me.txtInput.Text & "--" & Me.txtOutput.Text MsgBox ty ElseIf ((VarType(Me.txtInput.Text) = vbInteger) And ((VarType(Me.txtOutput.Text) = vbInteger))) Then ty = (Me.txtInput.Text) + Me.txtOutput.Text MsgBox ty Else MsgBox "Unknow Format or mismatch data" End If End Sub ------------------------END CODE------------------- Regards, himadrish himadrish@yahoo.com:-O Himadrish Laha
-
Is it possible to use operator overloading in visual basic. I just try to do it on vb6.0 using + operator(i.e to plus with numeric number and concatenate with string number). But this does not work properly. Any idea? ---------------------CODE--------------------- Private Sub cmdDo_Click() Dim ty If ((VarType(Me.txtInput.Text) = vbString) And (VarType(Me.txtOutput.Text) = vbString)) Then ty = Me.txtInput.Text & "--" & Me.txtOutput.Text MsgBox ty ElseIf ((VarType(Me.txtInput.Text) = vbInteger) And ((VarType(Me.txtOutput.Text) = vbInteger))) Then ty = (Me.txtInput.Text) + Me.txtOutput.Text MsgBox ty Else MsgBox "Unknow Format or mismatch data" End If End Sub ------------------------END CODE------------------- Regards, himadrish himadrish@yahoo.com:-O Himadrish Laha
First, VB6 doesn't do true OOP and does not support operator overloading at all. Second, the code you wrote is making an incorrect assumption about the VarType function. VarType will return the Type of the Variable, not its contents.
Private Sub cmdDo_Click()
Dim ty
If ((VarType(Me.txtInput.Text) = vbString) And (VarType(Me.txtOutput.Text) = vbString)) Then
ty = Me.txtInput.Text & "--" & Me.txtOutput.Text
MsgBox ty
ElseIf ((VarType(Me.txtInput.Text) = vbInteger) And ((VarType(Me.txtOutput.Text) = vbInteger))) Then
ty = (Me.txtInput.Text) + Me.txtOutput.Text
MsgBox ty
Else
MsgBox "Unknow Format or mismatch data"
End If
End SubThe VarType statements of all your Text properties will ALWAYS return vbString. If you hit F2, select the TextBox control in the left pane and then the Text property in the right pane, and look at property details at the bottom of the window, you'll see that it says
Property Text As String
Member of VB.TextBox
Returns/sets the text contained in the control.On top of that, both the '&' and '+' operators, when used with strings (.Text properties) will always append one string to another. In your code, you essentially did the same thing twice. Both 'ty=' statements will append one string to another. RageInTheMachine9532
-
First, VB6 doesn't do true OOP and does not support operator overloading at all. Second, the code you wrote is making an incorrect assumption about the VarType function. VarType will return the Type of the Variable, not its contents.
Private Sub cmdDo_Click()
Dim ty
If ((VarType(Me.txtInput.Text) = vbString) And (VarType(Me.txtOutput.Text) = vbString)) Then
ty = Me.txtInput.Text & "--" & Me.txtOutput.Text
MsgBox ty
ElseIf ((VarType(Me.txtInput.Text) = vbInteger) And ((VarType(Me.txtOutput.Text) = vbInteger))) Then
ty = (Me.txtInput.Text) + Me.txtOutput.Text
MsgBox ty
Else
MsgBox "Unknow Format or mismatch data"
End If
End SubThe VarType statements of all your Text properties will ALWAYS return vbString. If you hit F2, select the TextBox control in the left pane and then the Text property in the right pane, and look at property details at the bottom of the window, you'll see that it says
Property Text As String
Member of VB.TextBox
Returns/sets the text contained in the control.On top of that, both the '&' and '+' operators, when used with strings (.Text properties) will always append one string to another. In your code, you essentially did the same thing twice. Both 'ty=' statements will append one string to another. RageInTheMachine9532
Okay, if VB6 does not support true OOP; then, what about VB.Net? Does VB.Net support OOP. Well, I'm not familiar with the language BASIC. I am using+learning C++ and java all the time. And I am now exploring the VC++.Net, so I wonder what's the difference between VC++.Net and VB.Net, since they are both windows programming. Do I need to understand BASIC to use VB.net?
-
Okay, if VB6 does not support true OOP; then, what about VB.Net? Does VB.Net support OOP. Well, I'm not familiar with the language BASIC. I am using+learning C++ and java all the time. And I am now exploring the VC++.Net, so I wonder what's the difference between VC++.Net and VB.Net, since they are both windows programming. Do I need to understand BASIC to use VB.net?
VB.Net supports almost all OOP specifications. The only thing it can't do is operator overloading. In order to use VB.NET, you better have at least a minimal understanding of at least one flavor of the BASIC language. C++ and Java are closely related and more flexible than BASIC or VB.Net as far as OOP goes. But, you get that flexibility at the expense of complexity. The difference between VC++.Net and VB.Net? Apples and Oranges...The two languages are just that, two completely different languages. Which one you use is NOT dictated by what you want to do, but more HOW you want to do it. For instance, if your code design requires operator overloading, you'll have to use either C++ or C#. BASIC/VB doesn't support it. But that doesn't mean that VB is useless. Like I said, your DESIGN is what dictates which languages you can use. There are ways around operator overloading if your classes are designed properly. Your classes can be designed with Add, Subtract, or Whatever operator functions you choose, designing these as overloaded functions to handle different operand cases. RageInTheMachine9532
-
VB.Net supports almost all OOP specifications. The only thing it can't do is operator overloading. In order to use VB.NET, you better have at least a minimal understanding of at least one flavor of the BASIC language. C++ and Java are closely related and more flexible than BASIC or VB.Net as far as OOP goes. But, you get that flexibility at the expense of complexity. The difference between VC++.Net and VB.Net? Apples and Oranges...The two languages are just that, two completely different languages. Which one you use is NOT dictated by what you want to do, but more HOW you want to do it. For instance, if your code design requires operator overloading, you'll have to use either C++ or C#. BASIC/VB doesn't support it. But that doesn't mean that VB is useless. Like I said, your DESIGN is what dictates which languages you can use. There are ways around operator overloading if your classes are designed properly. Your classes can be designed with Add, Subtract, or Whatever operator functions you choose, designing these as overloaded functions to handle different operand cases. RageInTheMachine9532
-
RageInTheMachine9532 wrote: Which one you use is NOT dictated by what you want to do I'm sorry but I disagree. If I want to write a hardware driver, I'm sure not going to use VB, nor am i going to use C++ to write a simple business app.
Support Bone
OK. That's a special purpose example. But for the great majority of apps, the design is the dictator. You project requirements are laid out and you come up with a modular design framework. Various parts of the framework are then designed and coded. The designs you come up with are going to be based on the techniques and languages you are familiar with. Sure, some languages are better suited for certain tasks than others. You COULD write a simple business app in C++ but, your right, it is simpler in VB. Could you write a data fitting algorithm in either language? Sure! Again, it comes down to what your familiar with in languages and techniques. Anyway, the person who posted the original question doesn't sound like he is going to be writing device drivers anytime soon. He still needs to learn the differences in languages, what their capabilities and limitations are and how to get around them when appropriate. Just my humble opinion... But in the end, it's a combination of factors that determine the language(s) used for various parts of or for an entire project. RageInTheMachine9532
-
VB.Net supports almost all OOP specifications. The only thing it can't do is operator overloading. In order to use VB.NET, you better have at least a minimal understanding of at least one flavor of the BASIC language. C++ and Java are closely related and more flexible than BASIC or VB.Net as far as OOP goes. But, you get that flexibility at the expense of complexity. The difference between VC++.Net and VB.Net? Apples and Oranges...The two languages are just that, two completely different languages. Which one you use is NOT dictated by what you want to do, but more HOW you want to do it. For instance, if your code design requires operator overloading, you'll have to use either C++ or C#. BASIC/VB doesn't support it. But that doesn't mean that VB is useless. Like I said, your DESIGN is what dictates which languages you can use. There are ways around operator overloading if your classes are designed properly. Your classes can be designed with Add, Subtract, or Whatever operator functions you choose, designing these as overloaded functions to handle different operand cases. RageInTheMachine9532
VB program is not as fast as C++ and our operating system like windows and linux are written in C and C++. When writing device driver or component. It is always better of using C++. For business application and RAD which program speed is not crucial. It is okay to use VB. Sonork 100.41263:Anthony_Yio
-
VB program is not as fast as C++ and our operating system like windows and linux are written in C and C++. When writing device driver or component. It is always better of using C++. For business application and RAD which program speed is not crucial. It is okay to use VB. Sonork 100.41263:Anthony_Yio
With .NET, the argument is no longer true since managed code is managed code - all .NET languages compile to IL and use the CLR - the only differences are any language-specific differences, which if the application is CLS compliant are not supposed to be used anyways.