Solved

class definitions

Posted on 2006-11-08
14
223 Views
Last Modified: 2010-04-23
Can someone tell me what is wrong with this and how it is defined. I need to identify those areas that are incorrect and indicate what I need to do to fix it.  It has to do something with basic class definitions, please help...

Public Class _MyClass
    Private MyName As String
    Private MyAddress As String
    Public MyCity As String

    Private Property GetName()
        Get
            Return MyName
        End Get
        Set(ByVal Value)
            Value = MyName
        End Set
    End Property

    Public Property MyAddress()
        Get
            Return MyAddress
        End Get
        Set(ByVal Value)
            MyAddress = Value
        End Set
    End Property

    Public ReadOnly Property GetCity()
        Get
            Return GetCity
        End Get
    End Property

    Public Function CheckZipCode() As Boolean
        If IsNumeric(MyZipCode) = False Then
            Return False
        Else
            Return True
        End If
    End Function

    Private Sub CapitalizeNames()
        MyName = MyName.ToUpper
    End Sub
End Class


0
Comment
Question by:fahVB
  • 5
  • 5
  • 2
  • +1
14 Comments
 
LVL 10

Assisted Solution

by:Kinger247
Kinger247 earned 25 total points
ID: 17900379
1. MyZipCode is not declared
2. CheckZipCode should be read only.
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17900412
In fact theres a whole lot wrong with it (disregard number 2 previously).
whats this for ?
0
 
LVL 29

Assisted Solution

by:Nightman
Nightman earned 25 total points
ID: 17900414
MyName and MyAddress are already defined, so you can't create a property get or set for them with the same name.
MyZipCode is not declared.


Public Class _MyClass
  Private _MyName As String
  Private _MyAddress As String
  Private _MyZipCode As String
  Public MyCity As String

  Private Property GetName()
    Get
      Return _MyName
    End Get
    Set(ByVal Value)
      Value = _MyName
    End Set
  End Property

  Public Property MyAddress()
    Get
      Return _MyAddress
    End Get
    Set(ByVal Value)
      _MyAddress = Value
    End Set
  End Property

  Public ReadOnly Property GetCity()
    Get
      Return GetCity
    End Get
  End Property

  Public Function CheckZipCode() As Boolean
    If IsNumeric(_MyZipCode) = False Then
      Return False
    Else
      Return True
    End If
  End Function

  Private Sub CapitalizeNames()
    _MyName = _MyName.ToUpper
  End Sub
End Class
0
 
LVL 13

Accepted Solution

by:
newyuppie earned 200 total points
ID: 17900441
homework?
besides kinger's suggestions:
1) Public Class _MyClass is not a CLS compliant name for a Class. you should remove the underscore (_)
2) in the SET part of the properties, you should identify the data type for the value passed to it.

for example in your code says:
Public Property MyAddress()
        Get
            Return MyAddress
        End Get
        Set(ByVal Value)
            MyAddress = Value
        End Set
    End Property

on the Set part, it should be
Set(ByVal Value as String)
            MyAddress = Value
        End Set

same for every other property.
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17900459
3) you should have Imports Microsoft.VisualBasic if you are going to use the IsNumeric function (on the CheckZipCode function)
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17900474
4)
on
Public ReadOnly Property GetCity()
        Get
            Return GetCity
        End Get
    End Property

it should read
Public ReadOnly Property GetCity()
        Get
            Return MyCity
        End Get
    End Property

because you cant return a property.
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17900490
This looks like an exam question to me ???????????????????????????????
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 13

Expert Comment

by:newyuppie
ID: 17900493
5) MyName = MyName.ToUpper
lacks the ending ()
0
 

Author Comment

by:fahVB
ID: 17900547
wow too many suggestions. It is an exam question though. How do I allocate points now? So many guru's....

0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17900602
I think you should give us 500 each ;)
and if you pass your exam, a beer.
0
 
LVL 29

Expert Comment

by:Nightman
ID: 17900633
10% to Kinger247
10% to Nightman
80% to newyuppie

IMHO - Kinger and I both shot from the hip - newyuppie gave some really good feedback.
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 17900662
But then I twigged what this was for !
0
 

Author Comment

by:fahVB
ID: 17900669
Thanks for the suggestions guys.
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17901197
thanks to you, and thanks nightman for your opinion, but anyway i think you two also had very good points there. cheers
NY
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now