How can I make this into a class??

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.
 
C

Cor Ligthert [MVP]

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
 
P

Phill W.

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.
 

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