• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

class definitions

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
fahVB
Asked:
fahVB
  • 5
  • 5
  • 2
  • +1
3 Solutions
 
Kinger247Commented:
1. MyZipCode is not declared
2. CheckZipCode should be read only.
0
 
Kinger247Commented:
In fact theres a whole lot wrong with it (disregard number 2 previously).
whats this for ?
0
 
NightmanCTOCommented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
newyuppieCommented:
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
 
newyuppieCommented:
3) you should have Imports Microsoft.VisualBasic if you are going to use the IsNumeric function (on the CheckZipCode function)
0
 
newyuppieCommented:
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
 
Kinger247Commented:
This looks like an exam question to me ???????????????????????????????
0
 
newyuppieCommented:
5) MyName = MyName.ToUpper
lacks the ending ()
0
 
fahVBAuthor Commented:
wow too many suggestions. It is an exam question though. How do I allocate points now? So many guru's....

0
 
Kinger247Commented:
I think you should give us 500 each ;)
and if you pass your exam, a beer.
0
 
NightmanCTOCommented:
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
 
Kinger247Commented:
But then I twigged what this was for !
0
 
fahVBAuthor Commented:
Thanks for the suggestions guys.
0
 
newyuppieCommented:
thanks to you, and thanks nightman for your opinion, but anyway i think you two also had very good points there. cheers
NY
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now