Solved

class definitions

Posted on 2006-11-08
14
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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
 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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 …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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