1 Attachment(s)
[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:
Re: [2005] Creating own class troubles
EDIT: I posted before thinking
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
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)
1 Attachment(s)
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
Quote:
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:
http://vbforums.com/attachment.php?a...1&d=1175792158
I will try to figure it out, thanks for the replies.:duck:
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
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:
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 :wave: Thanks.
edit*
And now that I read back we had it on the second post. Anyways thanks.