How would I make this into a class ? simple program HELP.

J

Jason

I want to have two buttons on the form, one called smile and one frown.
When smile is pressed my LableSmile.text would display a smile

and using the windings font and JKL this is possible.

I can do this in a sub routine...simply by

btnSmile
lableSmile.text = "J"
end sub

and etc for frown.

How would I make this into a class for example a class called Face.

can someone build a class so I can see how its done?
thanks
 
J

Jay Taplin

Here you go! On your form, create a text box named TextBox1 and a Command
Button named Button1. Set the font for the text box to WingDings. Add this
code to the form:


Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim face As clsFace = New clsFace

face.MouthType = enuMouthType.Smile
TextBox1.Text = face.ToString

face = Nothing
End Sub
End Class

Create a class named clsFace. Add the following code:

Public Enum enuMouthType
Frown = 1
Smile = 2
End Enum
Public Class clsFace
Private mintMouthType As enuMouthType

Public Overrides Function ToString() As String
Select Case mintMouthType
Case enuMouthType.Frown
Return "L"
Case enuMouthType.Smile
Return "J"
Case Else
Return "K"
End Select
End Function

Public Property MouthType() As enuMouthType
Get
MouthType = mintMouthType
End Get
Set(ByVal value As enuMouthType)
mintMouthType = value
End Set
End Property
End Class


If you need any help understanding the code, just respond back and I'll
attempt to clarify.

Take care.

Jay Taplin
 
J

Jason

Jay,
thank you for your help. I still was unable to get it to work..

I need to look over the code though because I do not quite understand it.
 
M

Mark Lincoln

Jay,

I'm just getting started with OOP and VB.NET; all of my recent
programming experience is in VBA. I'm trying to come to grips with
classes and such, and OOP programming in general. I've done a fair
amount of reading, but I still haven't gotten to the point where I can
think in OOP/.NET terms. So I've been looking for examples.

I've been able to work through your code and feel as though I
understand what's going on. I do have a couple of questions, though:

1. It looks to me from your code that Enums are the .NET way of
declaring constants. Am I correct? What are the advantages to using
Enums as opposed to how I've used CONST in VBA? (Does VB.NET have
CONST? I haven't looked yet....)

2. Is the "mint" in "mintMouthType" a way of saying that MouthType is a
member of clsFace and is an integer? (I kept thinking "minty fresh
mouth" when I looked at it. Sorry.) :)

3. Do you know of someplace on the Web I can go to find more examples
like this? That is, examples that translate top-down style programming
to VB.NET without overwhelming OOP beginners like me?

Thanks for helping turn on the lights.
 
H

Homer J Simpson

1. It looks to me from your code that Enums are the .NET way of
declaring constants. Am I correct? What are the advantages to using
Enums as opposed to how I've used CONST in VBA? (Does VB.NET have
CONST? I haven't looked yet....)

'enum' is from C -- classically : -

enum color
{
red,
green,
blue
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top