|
It doesn't matter that you are in a class, the error says you can't use = to compare Points.
Taking a quick look at the library for the Point type I see you can use the equals method:
Dim a As New Point(0, 10)<br />
Dim b As New Point(1, 10)<br />
Dim c As New Point(0, 10)<br />
If a.Equals(b) Then Debug.WriteLine(" a = b") Else Debug.WriteLine(" a not = b")<br />
If a.Equals(c) Then Debug.WriteLine(" a = b") Else Debug.WriteLine(" a not = b")
|
|
|
|
|
There is a critical distinction you need to make:
1) Do you want to know if the two objects are really the same? In other words, are you passing in a second reference to a single instance of the object?
2) Do you want to know if the state of two different object instances are identical. In other words, you have two separate object instances, but their property values, i.e their state, is identical.
In the first case there is a comparison operator - "Is". Example
boolTest = m_Object1 Is m_Object2
If this returns true, you have a single object instance that is being referenced by two pointers - m_Object1 and m_Object2.
In the second case, the simplest approach is to write your own validator function in the class that performs a memberwise comparison of two objects, such as
Private Function IsObjectStateIdentical(ByRef MyPoint1 As POINT, ByRef MyPoint2 As POINT) As Boolean
Dim fIsIdentical As Boolean
With MyPoint1
fIsIdentical = (.X = MyOvbject2.X)
fIsIdentical = fIsIdentical And (.Y = MyObject2.Y)
End With
Return fIsIdentical
End Function
|
|
|
|
|
Hi all,
Can any one please tell me how can i add a bacground music with user control (user can control , volume, mute etc) by using VS, VB, ASP.net web application.
Regards
Jennifer Wadhani
jenniferaahmed@yahoo.com
|
|
|
|
|
VB can't play music in a web application. ASP.NET is a server-side only technology that generates HTML for browsers. If you want music in your web page, you'll have to do research on HTML and Web methods of doing that.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Just curious.
From my recent reading ("Coding Techniques for Microsoft Visual Basic.Net" - Table 4-1), I noticed that a Boolean variable took 4 Bytes of storage and a Byte variable only took 1 Byte.
It's clear why a Byte equals a Byte, but why on earth does a Boolean (who's only values can be either a 1 or 0) require 4 Bytes?
Was this a typo?
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
A boolean in the .NET Framework is not just a single bit, but is a structure with a couple fields and a bunch of methods. Internally, the boolean value is stored at an Int32, or 32-bit value, I think(!).
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The system memory bus is 4 bytes (32 bits). The minimum packet of information along this bus then is 4 bytes. The common language runtime decides the actual size of the boolean at runtime. Typically it will use 4 bytes as this is the most efficient. If memory is at a premium, then it can reduce the size on the fly. On 64 bit architecture it will use 8 bytes.
|
|
|
|
|
Thanks to all. My goal is to learn the right way to design tight classes. Soooo on today's 32 bit system, using less than 4 Bytes is inefficient.
This is beginning to make sense -- I also read using a 'int16' or 'short integer' (2 Bytes) is less efficient than using an 'int32' or 'integer' (4 Bytes).
I was using the 'Byte' declaration for integer variables that would never see a value higher than 255. I understand this to be slower than just using the 'integer' declaration. Right?
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
watagal wrote:
I was using the 'Byte' declaration for integer variables that would never see a value higher than 255. I understand this to be slower than just using the 'integer' declaration. Right?
Not necessarily. Depends on what math your doing and what the result is going to end up in.
But, you also don't ahve to be THAT tight with it. The size of the variable isn't really a concern because of the VAST memories of today's systems. What makes a "tight" class is the use of proper OOP techniques, data types, logic, class organization and relationships to other classes. At least IMHO.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Greetings,
My hope is that someone can help a newbie trying to learn this OOP on her own.
My base class is POINT2 and the derived class is POINT3 and I'm trying to overide the subroutine called add.
As the code is written - I get the error sub "add" cannot be declared 'Overrides' because it does not overrides a sub in a base class and it recommends to me to remove the keyword Overrides.
Once I remove the keyword Overrides, I get the error message, sub 'add' shadows an overridable method in the base class 'POINT2'. To override the base method, this method must be declared 'Overrides'.
Now I'm not pointing the finger at Microsoft, I'm sure it is something I did or didn't do.
Help me stop chasing my tail.
Karen
Nooobie to OOP and VB.Net 2005 (beta)
' 2D POINT ===========================================================<br />
Public Class POINT2<br />
Friend _X As Decimal = Nothing<br />
Friend _Y As Decimal = Nothing<br />
<br />
Public Sub New(ByVal x As Decimal, ByVal y As Decimal)<br />
mybase.new()<br />
Me._X = x<br />
Me._Y = y<br />
End Sub ' Constructor<br />
<br />
Property X()<br />
Get<br />
Return (_X)<br />
End Get<br />
Set(ByVal value)<br />
_X = value<br />
End Set<br />
End Property ' Get/Set X<br />
<br />
Property Y()<br />
Get<br />
Return (_Y)<br />
End Get<br />
Set(ByVal value)<br />
_Y = value<br />
End Set<br />
End Property ' Get/Set Y<br />
<br />
Public Overridable Sub add(ByRef p1 As POINT2)<br />
Me._X += p1.X<br />
Me._Y += p1.Y<br />
End Sub<br />
<br />
End Class ' 2D POINT Class<br />
<br />
<br />
' 3D POINT ===========================================================<br />
Public Class POINT3<br />
Inherits POINT2<br />
<br />
Friend _Z As Decimal = Nothing<br />
<br />
Public Sub New(ByVal x As Decimal, ByVal y As Decimal, ByVal z As Decimal)<br />
MyBase.New(x, y)<br />
Me._X = x<br />
Me._Y = y<br />
Me._Z = z<br />
End Sub ' Constructor<br />
<br />
Property Z()<br />
Get<br />
Return (_Z)<br />
End Get<br />
Set(ByVal value)<br />
_Z = value<br />
End Set<br />
End Property ' Get/Set Z<br />
<br />
Public Overrides Sub add(ByRef p1 As POINT3)<br />
Me._X += p1.X<br />
Me._Y += p1.Y<br />
Me._Z += p1.Z<br />
End Sub<br />
End Class ' 3D Point
Thanks,
Karen
Nooobie to OOP and VB.Net 2005 (beta)
|
|
|
|
|
In your implementation, you're adding functionality to a base class, POINT2, not overriding it. The base class supports every associated with POINT2, including it's Add method. Your Add method takes a parameter of POINT2 pass ByRef. In your POINT3 class, your Add method is taking a parameter of POINT3 ByRef. This is a different method from the base class.
So what you're really doing is adding new support to the Add method in POINT2, not replacing it. This is called Overloading. You have multiple methods with the same name that take different parameters. Calling the Add method with a POINT2 parameter will call the POINT2 class' version. Calling the Add method with a POINT3 parameter will call the POINT3 subclass' Add method.
A few things need to be changed in your code. We'll start with POINT2:
' 2D POINT ===========================================================
Public Class POINT2
'Friend _X As Decimal = Nothing ' Remove the "= Nothing"'s. Decimals are value types that
'Friend _Y As Decimal = Nothing ' can't be set to Nothing. Also, you might want to change
' these to Doubles instead. Decimal types are 128-bit numbers
' and a rather slow to work with.
Friend _X As Double
Friend _Y As Double
Public Sub New(ByVal x As Double, ByVal y As Double)
'mybase.new() ' Since this class isn't inheriting from anything (well, not really true!),
' you're calling the New of System.Object, which doesn't
' do anything. Remove this line.
'Me._X = x ' You should be setting your initial values using your
'Me._Y = y ' Property statements. Your Properties can validate the data
' and return Exceptions if not valid.
Me.X = x
Me.Y = y
End Sub ' Constructor
Public Property X() As Double ' It doesn't hurt to be specific about what your coding.
Get ' Making assumptions and not specifying exactly what you
Return Me._X ' want Public/Private can lead to hard to find problems.
End Get
Set(ByVal value)
' You might want to do some checking of your values to see if they
' are valid before setting the value of this class instance.
Me._X = value
End Set
End Property ' Get/Set X
Public Property Y() As Double
Get
Return Me._Y
End Get
Set(ByVal value)
' You might want to do some checking of your values to see if they
' are valid before setting the value of this class instance.
Me._Y = value
End Set
End Property ' Get/Set Y
Public Sub add(ByRef p1 As POINT2) ' Remove the Overridable modifier. You won't need it
Me.X += p1.X ' since your not actually replacing the functionality
Me.Y += p1.Y ' of POINT2, just adding another version of 'Add" to it.
End Sub
End Class ' 2D POINT Class
Now on to POINT3:
' 3D POINT ===========================================================
Public Class POINT3
Inherits POINT2
Friend _Z As Double
Public Sub New(ByVal x As Decimal, ByVal y As Decimal, ByVal z As Decimal)
'MyBase.New(x, y) ' This line isn't required because you're setting all
' three values in this constructor. Anything you do in
' in the POINT2 constructor would just be overwritten
' by what you have in this one.
Me.X = x ' Again, go through the Properties!
Me.Y = y
Me.Z = z
End Sub ' Constructor
Public Property Z() As Double
Get
Return Me._Z
End Get
Set(ByVal value)
Me._Z = value
End Set
End Property ' Get/Set Z
Public Overloads Sub add(ByRef p1 As POINT3) 'Use Overloads here because you adding another
Me.X += p1.X ' version of 'Add' to the base class that takes a
Me.Y += p1.Y ' different parameter from what the base class version does.
Me.Z += p1.Z ' Also, do your math using the Property versions of the
' fields. You can check the values of the results of the
' math much easier this way.
End Sub
End Class ' 3D Point
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks so much for your quick response. Last week, I read the same thing in 2 different books - you made it much more clearer and practical.
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
Dave Kreskowiak wrote:
Public Sub New(ByVal x As Decimal, ByVal y As Decimal, ByVal z As Decimal)
'MyBase.New(x, y) ' This line isn't required because you're setting all
' three values in this constructor. Anything you do in
' in the POINT2 constructor would just be overwritten
' by what you have in this one.
Me.X = x ' Again, go through the Properties!
Me.Y = y
Me.Z = z
End Sub ' Constructor
Dave,
As soon as I comment out the 'Mybase.New()' statement in POINT3 class, VS2005 complains that it should be there.
This is where my code stands (w/o VS complaints):
Public Sub New(ByVal x As Double, ByVal y As Double, ByVal z As Double)
MyBase.New(x, y)
Me.Z = z
End Sub ' Constructor
Is this ok?
Thanks,
Karen
Nooobie to OOP and VB.Net 2005
|
|
|
|
|
There's something you haven't shown in the POINT2.New constructor. This message shouldn't come up with the code that I've seen and what I posted. The code that I posted came straight out of VB.NET 2005 and it compiled nicely.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Can you correct this conflict in two methods with similar names but different parameters.
<code>Public Type MyPoint
x As Double
y As Double
End Type
Public Type MyLine
Head As MyPoint
Tail As MyPoint
End Type
Public Sub DrawLine(aLine As MyLine, Canves As Form)
Canves.Line (aLine.Head.x, aLine.Head.y)-(aLine.Tail.x, aLine.Tail.y)
End Sub
Public Sub DrawLine(aLine As MyLine, Canves As PictureBox)
Canves.Line (aLine.Head.x, aLine.Head.y)-(aLine.Tail.x, aLine.Tail.y)
End Sub
</code>
Shoaib Nawaz
|
|
|
|
|
What conflict? What's the errot you're getting?
I see other things wrong that have nothing to do with Overloading, Shadowing, or Overriding.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi
i have a datagrid on the form..i want that on the button click selected values from the data grid shud be picked up and shud be displayed in the textbox(on the button click)
i know this will be done thru properties...
but i am not able to do so...
please help me out....
please........
ashima
|
|
|
|
|
hi laks here,
iam a beginner to programming field ,i have some doubts
if possible clarify my doubts
1.whether we can convert transfer the records of Ms-excel to Ms-access ,if yes then how we can write a simple application.
2.I want to secure my project.so when ever we install our setup on clients system ,we have to generate one secret code so ,after giving that code the project should be opened
(This should happen when client logs for first time),then we should enter one unique id into the table such that he/she should not install the project on other system
thanks
|
|
|
|
|
Hi,
how can I find Text with specific BackColor in my RTB and replace it with another BackColor? I do not know the Text, Startposition, Length and number of the text pieces with the specific BackColor.
Thanks
Lupus
|
|
|
|
|
I'm new to the VB.NET world so any help will be appreciated. I'm building a Windows app and I have a form with tabs. On the first tab, I'm building a search capability. I have a couple of text boxes and a data grid. Everything seems to work OK, however in my datagrid, one of the columns displays a social security number. My problem is I cant figure out how to format the SSN column to display with dashes. Right now it displays as '#########' and I need it to display "###-##-####'
Thank you in advance for any help.
|
|
|
|
|
LMJ
I'm also a newbie, but have come across this in VS2005. Use the 'Masked Textbox' and specify a mask or 000-00-0000.
If this control is not a part of your version of VS, you can convert the SS number to a string (tostring) and parse it using 'substring'
Dim sParse as String<br />
Dim sSS as String = ""<br />
sParse = iSSnumber.tostring<br />
sSS = sParse.substring(0,3) + "-"<br />
sSS += sParse.substring(3,2) + "-"<br />
sSS += sParse.substring(5,4)
Hope this is right,
Karen
*** Nooobie to OOP and VB.Net 2005
|
|
|
|
|
Take a look at this[^] article here on CP. The code is in C#, but if you look close enough, you'll see that it is easily convertible to VB.NET.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I've edited the normal.dot file to add certain styles to documents created in Word 2003. These styles would only worked in new documents and not old ones. I created a macro and attached it to a toolbar button, which will add these styles to any documnet whether they are newly created documents or not. Yet my dilemma, is having the styles in this newly created normal.dot file activate no matter who's logged in to the system. I was worndering if there's a Currentuser or username variable that would accomplish this task for me. Any help would be greatly appreciated.
Thank you,
The VB Newbie
|
|
|
|
|
I want to do the following.
I have a tab control with 3 tab pages. When I click on the say tab 1, then a procedure automatically starts.
If I put the procedure in say, TabPage2_Click, then I have to physically click on the tab. What I am aiming for is that when I click the tabPage of the Tab Control, the procedure automatically runs.
I have been trying various ways using TabControl1.TabPages(1) but with no success. I know this must be a simply process and I am missing something out.
|
|
|
|
|
Have you tried combining all the tabpage handlers into one event handler?
See the "Handles" clause at the end of your TabPage_Click event handler. You can add a comma then the next object and event that this code will handle. When any of the classes in the Handles list fire's it's Click event, this handler will be called.
Public Sub TabPage_Click(...,...) Handles TabPage1.Click, TabPage2.Click, TabPage3.Click
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|