Apr 5th, 2007, 11:40 AM
#1
Thread Starter
Admodistrator
[2005] Creating own class troubles
Ive been working in Java a ton lately, seems my mind is slipping here..
vb Code:
Public Class menu
Dim mFont As Font
Dim mMenu As String
Public ReadOnly Property getFont() As Font
Get
Return mFont
End Get
End Property
Public WriteOnly Property setFont(ByVal fontName As String) As String
Set(ByVal value As String)
mFont = New Font(fontName, 12, FontStyle.Regular)
End Set
End Property
Public ReadOnly Property getMenu() As String
Get
Return mMenu
End Get
End Property
Public WriteOnly Property setMenu(ByVal menuText As String) As String
Set(ByVal value As String)
mMenu = menuText
End Set
End Property
End Class
In my program I try to set the menuText:
Attached Images
Last edited by |2eM!x; Apr 5th, 2007 at 11:52 AM .
Apr 5th, 2007, 11:47 AM
#2
Re: [2005] Creating own class troubles
EDIT: I posted before thinking
Last edited by bmahler; Apr 5th, 2007 at 12:03 PM .
Apr 5th, 2007, 11:49 AM
#3
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
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
Apr 5th, 2007, 11:52 AM
#4
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:
Public Class menu
Dim mFont As Font
Dim mMenu As String
Public Property Font() As Font
Get
Return mFont
End Get
Set(ByVal value As Font)
mFont = value
End Set
End Property
Public Property Menu() As String
Get
Return mMenu
End Get
Set(ByVal value As String)
mMenu = value
End Set
End Property
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:
Dim rMenu As New menu
rMenu.Menu = "A"
rMenu.Font = New Font("Arial", 12)
Apr 5th, 2007, 11:57 AM
#5
Thread Starter
Admodistrator
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
Apr 5th, 2007, 12:06 PM
#6
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:
Public WriteOnly Property setMenu() As String
Set(ByVal value As String)
mMenu = value
End Set
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
Apr 5th, 2007, 12:22 PM
#7
Thread Starter
Admodistrator
Re: [2005] Creating own class troubles
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:
Public WriteOnly Property setMenu() As String
Set(ByVal value As String)
mMenu = value
End Set
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
Forum Rules
Click Here to Expand Forum to Full Width