Results 1 to 7 of 7

Thread: [2005] Creating own class troubles

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    [2005] Creating own class troubles

    Ive been working in Java a ton lately, seems my mind is slipping here..

    vb Code:
    1. Public Class menu
    2.     Dim mFont As Font
    3.     Dim mMenu As String
    4.     Public ReadOnly Property getFont() As Font
    5.         Get
    6.             Return mFont
    7.         End Get
    8.     End Property
    9.  
    10.     Public WriteOnly Property setFont(ByVal fontName As String) As String
    11.         Set(ByVal value As String)
    12.             mFont = New Font(fontName, 12, FontStyle.Regular)
    13.         End Set
    14.     End Property
    15.  
    16.     Public ReadOnly Property getMenu() As String
    17.         Get
    18.             Return mMenu
    19.         End Get
    20.     End Property
    21.  
    22.     Public WriteOnly Property setMenu(ByVal menuText As String) As String
    23.         Set(ByVal value As String)
    24.             mMenu = menuText
    25.         End Set
    26.     End Property
    27. End Class

    In my program I try to set the menuText:

    vb Code:
    1. rMenu.setMenu = "A"
    Attached Images Attached Images  
    Last edited by |2eM!x; Apr 5th, 2007 at 11:52 AM.

  2. #2
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Creating own class troubles

    EDIT: I posted before thinking
    Last edited by bmahler; Apr 5th, 2007 at 12:03 PM.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  3. #3
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: [2005] Creating own class troubles

    Properties work a little different in .NET than the getters and setters in Java. In .NET, the one property declaration defines both the Get and the Set.
    Code:
    Public Property Menu() As String
        Get            
            Return mMenu        
        End Get
        Set(ByVal value As String)            
            mMenu = value
        End Set
    End Property
    then it would be
    Code:
    rMenu.Menu = "A"
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Creating own class troubles

    also, why have 2 properties for each one? you can just use a silgel property to accomplish both
    vb Code:
    1. Public Class menu
    2.  
    3.     Dim mFont As Font
    4.     Dim mMenu As String
    5.  
    6.     Public Property Font() As Font
    7.         Get
    8.             Return mFont
    9.         End Get
    10.         Set(ByVal value As Font)
    11.             mFont = value
    12.         End Set
    13.     End Property
    14.  
    15.     Public Property Menu() As String
    16.         Get
    17.             Return mMenu
    18.         End Get
    19.         Set(ByVal value As String)
    20.             mMenu = value
    21.         End Set
    22.     End Property
    23.  
    24. End Class

    You are right about the setFont... I responded before thinking

    an example of using this method i have is like so
    vb Code:
    1. Dim rMenu As New menu
    2.         rMenu.Menu = "A"
    3.         rMenu.Font = New Font("Arial", 12)
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  5. #5

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: [2005] Creating own class troubles

    Okay thanks for the responses so quick!

    The reason I had two separate properties is a few reasons --
    1.I wanted to have a string representing the font name coming in, but upon calling the getFont I wanted to return a font.
    2.To keep with standards and neatness of code

    You don't want to have = because you are passsing a parameter it should be
    rMenu.setMenu("A")
    Doing this gives me the following error that I also tried to fix unsuccessfully:


    I will try to figure it out, thanks for the replies.
    Attached Images Attached Images  

  6. #6
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: [2005] Creating own class troubles

    Ya, I posted that while my brain was still starting up. Sorry bout that, you were setting it properly.

    You need to remove the (byval MenuText As String) From that property

    Should be

    vb Code:
    1. Public WriteOnly Property setMenu() As String
    2.         Set(ByVal value As String)
    3.             mMenu = value
    4.         End Set
    5.     End Property

    When you are setting the value, the Set function of the property is called and the value is passed to this function.

    so,...
    mMenu.setMenu = "A"

    will call the set function and pass the string "A" as the value
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

  7. #7

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: [2005] Creating own class troubles

    Quote Originally Posted by bmahler
    Ya, I posted that while my brain was still starting up. Sorry bout that, you were setting it properly.

    You need to remove the (byval MenuText As String) From that property

    Should be

    vb Code:
    1. Public WriteOnly Property setMenu() As String
    2.         Set(ByVal value As String)
    3.             mMenu = value
    4.         End Set
    5.     End Property

    When you are setting the value, the Set function of the property is called and the value is passed to this function.

    so,...
    mMenu.setMenu = "A"

    will call the set function and pass the string "A" as the value
    Nail on the head Thanks.

    edit*
    And now that I read back we had it on the second post. Anyways thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width