Reference to a non-shared member requires an object reference

I added sample code below and an image.  I have a DLL that i created which encrypts / decrypts a string.  When I add    Encrypts( some text ) I receive "Reference to a non-shared member requires an object reference" error.  Without the encrypt I do not recevie the error.

Any idea how to resolve?
Protected Sub btnLogin_Click(ByVal sender As Object, 
      ByVal e As EventArgs) Handles btnLogin.Click

   Dim _connStr As String = ConfigurationManager.ConnectionStrings("DBASE").ToString()

    Dim _login As New BOL.Login
    Dim ds As New DataSet
    If Page.IsValid Then

        Try
            _login.ConnectionString = _connStr
            _login.UserId = txtUserName.Text
            _login.Password = Encrypt
                              (txtPassword.Text.ToString())
        Catch

        End Try

Open in new window

Error.jpg
LVL 2
CipherISAsked:
Who is Participating?
 
käµfm³d 👽Commented:
What is the name of the class where you defined Encrypt and Decrypt?
0
 
käµfm³d 👽Commented:
You didn't post the code that defines your Encrypt and Decrypt methods (for obvious reasons, I'm sure), but it sounds like you didn't declare these methods as Shared, so they are instance methods--which means you need to create an instance of the class which houses these methods. Call the methods against the instance rather than as standalone functions.
0
 
CipherISAuthor Commented:
How do I do that?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
CipherISAuthor Commented:
I added an image of the class - minus private info
Crypto.jpg
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
So, as stated by kaufmed, you need to create an instance of your "aes" class:

    aes crypto = new aes();
    ...
    _login.Password = crypto.Encrypt(txtPassword.Text.ToString()) // <-- here we are using our instance "crypto"
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
By default, when you create a method in a class, you need an object to call it.

The way your class is built, you would need to to the following in order to call the method:
aes obj;
ojb.Encrypt("text")

Open in new window

In order to be able to call a method directly without having to declare a variable, as you do in your Click event, you need to declare the method as static (shared):
public static string Encrypt (string Data)

Open in new window

0
 
CipherISAuthor Commented:
fixed my problem
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.