Solved

class definitions

Posted on 2006-11-08
14
225 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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