|
![Go to Parent](https://www.codeproject.com/App_Themes/CodeProject/Img/arrow-up24.png) 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![D'Oh! | :doh:](https://www.codeproject.com/script/Forums/Images/smiley_doh.gif)
|
|
|
|
|
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
|
|
|
|
|
hi
i am a bigginner to this vb.net.i have a problem in inserting data programiticaly(without using wizard or server explorer)from vb.net application to sql data table.whatever i am inserting through vb.net is not updating in the table. i have searched from 2 months for this.please anybody help for this?please give sample code for this, (another question is i am using combo box in the application how to insert that?)
thanking you.
|
|
|
|
|
You posted this very question an hour ago? Don't repost, it's very rude and it won't get your question answered any faster.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Could somebody tells me the way to create string/array math using visual basic? Thank You!
|
|
|
|
|
What do you mean by a "string/array math"? This doesn't make any sense at all, so we couldn't even begin to tell you anything useful.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
If you want to know about array of strings
Dim ArrayOfString(0 to 3) as String
Redim Preserver ArrayOfString(5)
ArrayOfString(0)="Put "
ArrayOfString(2)="What "
ArrayOfString(3)="You "
ArrayOfString(4)="to "
ArrayOfString(5)="Save."
Shoaib Nawaz
|
|
|
|
|
hi
i am a bigginner to this vb.net.i have a problem in inserting data programiticaly(without using wizard or server explorer)from vb.net application to sql data table.whatever i am inserting through vb.net is not updating in the table. i have searched from 2 months for this.please anybody help for this?please give sample code for this, (another question is i am using combo box in the application how to insert that?)
thanking you.
shyli
|
|
|
|
|
Without seeing your SQL update code, it's impossible to tell you what your doing wrong.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Imports System.Data.SqlClient
Imports System.Data.DataTable
Imports System.Data.DataRow
Public Class Form1
Inherits System.Windows.Forms.Form
Dim flag As Integer
Dim custid As String
Dim dr As DataRow
Dim dt As DataTable
Dim DS As New DataSet
Dim Conn As SqlConnection = New SqlConnection
Dim CMD As SqlCommand = New SqlCommand
Dim DA As SqlDataAdapter = New SqlDataAdapter
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Conn As SqlConnection = New SqlConnection("workstation Id=SHAily;packet size=4096;integrated security=SSPI; data source=SHAILY; PERSIST SECURITY INFO=FALSE;INITIAL CATALOG=customer")
Dim CMD As SqlCommand = New SqlCommand("select * from tablename ", Conn)
CMD.Connection = Conn
DA.SelectCommand = CMD
DA.Fill(DS, "details")
Textbox1.DataBindings.Add("Text", DS.Tables("tablename"), "CUSTID")
Combobox1.DataSource = DS.Tables("tablename ")
Combobox1.DisplayMember = " tablename "
Combobox1.ValueMember = "NAME"
Textbox2.DataBindings.Add("Text", DS.Tables("tablename “), "ADDRESS")
Textbox3.DataBindings.Add("Text", DS.Tables("tablename "), "PHONE")
Combobox2.DataSource = Ds.Tables("tablename ")
Combobox2.DisplayMember = " tablename "
Combobox2.ValueMember = "POBOX"
End Sub
Private Sub BTNADD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BNADD.Click
dt = DS.Tables("tablename ")
Textbox1.Text = ""
Combobox1.Text = ""
Textbox2.Text = ""
Textbox3.Text = ""
Combobox2.Text = ""
flag = 1
Dim ctr, len As Integer
Dim custidval As String
len = (dt.Rows.Count - 1)
dr = dt.Rows(len)
custid = dr("CUSTID")
custidval = Mid(custid, 2, 3)
ctr = CInt(custidval)
If ctr >= 1 And ctr < 9 Then
ctr = ctr + 1
Textbox1.Text = "C00" & ctr
ElseIf ctr >= 9 And ctr < 99 Then
ctr = ctr + 1
Textbox1.Text = "C0" & ctr
ElseIf ctr >= 99 Then
ctr = ctr + 1
Textbox1.Text = "C" & ctr
End If
Textbox1.Enabled = True
End Sub
Private Sub BtnSAVE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNSAVE.Click
If flag = 1 Then
da.Fill(DS, " tablename ")
'Dim dt7 As New DataTable
'dt7 = DS7.Tables("tablename ")
'dr = dt7.NewRow()
'Dim i As Integer
'dr(0) = custid
'dr(1) = Combobox1.Text
' dr(2) = Textbox2.Text
'dr(3) = Textbox3.Text
'dr(4) = Combobox2.Text
' dt7.Rows.Add(dr)
Dim str As String
Dim Conn1 As SqlConnection = New SqlConnection("workstation Id=SHAILY;packet size=4096;integrated security=SSPI; data source=SHAILY; PERSIST SECURITY INFO=FALSE;INITIAL CATALOG=customer")
'CMD.Connection = Conn
str = "INSERT INTO DETAILS '(CUSTID,NAME,ADDRESS,PHONE,POBOX)'+'VALUES(CUSTID,@NAMEBOX,@TBADDRESS,@TBPHONE,@POBOX)'"
Dim CMD1 As New SqlCommand(str, Conn1)
CMD1.Parameters.Add("TEXT", SqlDbType.Char, 8, "custid")
'par.SourceColumn = "custid"
'par.SourceVersion = DataRowVersion.Original
CMD1.Parameters.Add("TEXT", SqlDbType.VarChar, 50, "name")
CMD1.Parameters.Add("TEXT", SqlDbType.VarChar, 90, "address")
CMD1.Parameters.Add("TEXT", SqlDbType.Char, 10, "phone")
CMD1.Parameters.Add("TEXT", SqlDbType.Char, 10, "pobox")
Conn1.Open()
DA.InsertCommand = CMD1
ElseIf flag = 2 Then
DA.Fill(DS, " tablename ")
dt = DS2.Tables("tablename ")
dr = dt.Rows(0)
custid = TEXTBOX1.Text
dr = dt.Rows.Find(custid)
dr.BeginEdit()
dr(0) = custid
dr(1) = COMBOBOX1.Text
dr(2) =TEXTBOX2.Text
dr(3) = TEXTBOX3.Text
dr(4) = COMBOBOX2.Text
dr.EndEdit()
Dim DA As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM tablename", Conn)
DA.UpdateCommand = New SqlCommand("UPDATE tablename SET Name = @Name " & _
"WHERE CUSTID = @CUSTID", Conn)
DA.UpdateCommand.Parameters.Add("@Name", SqlDbType.NVarChar, 15, "Name")
Dim workParm As SqlParameter = DA.UpdateCommand.Parameters.Add("@CUSTID", SqlDbType.Int)
workParm.SourceColumn = "CUSTID"
workParm.SourceVersion = DataRowVersion.Original
Dim DS As DataSet = New DataSet
DS.Fill(DS, "tablename")
Dim cRow As DataRow = DS.Tables("tablename").Rows(0)
cRow("Name") = "New name"
End If
flag = 0
DA.Update(DS, "tablename")
DA.fill(DS,”tablename”)
MsgBox("data saved---")
End Sub
|
|
|
|
|
Hi All,
I need to show all the menu items in the form into treeview
but i am not able to get the menu name its only giving the
menu text. any methods are available to get the name of the
menuitem object.
reply me yaar!!
V.Gopi.
Easy Design Systems
Coimbatore
India
|
|
|
|
|
Are you sure there's no name property (I don't remember it by heart)?
Anyway, an easy way is give the tag property the same value of the name and recall that one.
|
|
|
|
|