How can I make this into a class??

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

I would like to make this code into a class:

Private Sub btnAllCap_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnAllCap.Click
txtOutput.Text = txtInput.Text.ToUpper

End Sub

Private Sub btnalllower_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnalllower.Click
txtOutput.Text = txtInput.Text.ToLower
End Sub

Private Sub btnReverse_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnReverse.Click
Dim string1 As String = txtInput.Text
txtOutput.Text = StrReverse(string1)
End Sub

I know that I could create a class and just use:
txtoutput.text = mystringclass(reverse) <-- for example....how do I
setup a class though I have no experiance with classes.
 
Ron,

Most probably it is already in a class. A windowform is as well a class.
VB.Net has an inbuild construction which a windowsform instanced in an
object as soon as it is used.

That is the reason that you have to use me. to point to a variable in those
objects.

This sample you give is real not good to put it in an seperate class or you
should want to make your program unreadable for others. (Obfuscate while
writting).

Cor
 
Ron said:
I would like to make this code into a class:

What are you aiming for?

1) A "helper" class that you can [re-]use in the code under buttons?
2) A complete UserControl, complete with textbox and buttons that does
all of this (and more)?

From your last comment, I'll assume the former, which gets you ...

Import VB=Microsoft.VisualBasic

Public Class SuperString

Public Shared Function Reserve( _
ByVal sText as String _
) as String

Return VB.StrReverse( sText )
End Function

End Class

....then...

Private Sub btnReverse_Click( _
ByVal sender As System.Object _
, ByVal e As System.EventArgs _
) Handles btnReverse.Click

txtInput.Text = SuperString.Reverse( txtInput.Text)

End Sub

Note: there's no "New SuperString" anywhere because the Reverse method
is declared as "Shared".

HTH,
Phill W.
 
Back
Top