|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How would I make this into a class ? simple program HELP.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 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 Show quoteHide quote "Jason" <none@none.invalid> wrote in message news:etoY2RIGGHA.3100@tk2msftngp13.phx.gbl... >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 > > 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. "Jay Taplin" <jtap***@integraware.com> wrote in message news:1_Uxf.2448$6L1.188@trnddc02...Show quoteHide quote > 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 > > "Jason" <none@none.invalid> wrote in message > news:etoY2RIGGHA.3100@tk2msftngp13.phx.gbl... >>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 >> >> > > 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. "Mark Lincoln" <mlinc***@earthlink.net> wrote in message 'enum' is from C -- classically : -news:1137349795.579153.172890@g47g2000cwa.googlegroups.com... > 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 color { red, green, blue }
Images inline with blog contents - HOW??
Referencing "Forms" objects from a module some advice The old Structure/Class Argument Migrating From ListBox to ListView: Only One Problem Command.Close vs Command.Dispose IO locked error Referencing Datagrid Information Problem on MSHFlexGrid Regarding a dot net application program |
|||||||||||||||||||||||