Need Help Building My First Class

Posted on 2009-02-21
Medium Priority
Last Modified: 2012-05-06
I'm building my first class for my website project.  The Class will need to define my User entity as well as contain some subroutines for SelectUser, UpdateUser, DeleteUser etc etc.  I have no problem with the subroutines.  For some reason I can't for the life of me figure out where and how i define my "User".  Can someone show me an example of how to architect this class.   Let's just assume that  a  User will have the following properties


And then how i would instantiate an instance of a User object on one of my pages.  Or basically, how i'm going to "tie it together" into one of my pages.  For instance, my login page.
Question by:davidcahan
  • 2
  • 2
LVL 11

Accepted Solution

mildurait earned 2000 total points
ID: 23702920
Here's some basics for you (see code below stored as .vb file in your App_Code folder).
    dim oU as new MyProject.User

To tie it together, you would hold UserID, Email, LoggedIn status in Session variables.
Namespace MyProject
   Public Class User
          Public FirstName as string
          Public LastName as string
          Public Email as string
          Public IsActive as boolean
          Public Function GetUserIDByEmail(ByValue E as string) as long
               dim UID as long     
              .... your script to query db and return userid
              return UID
          End Function
          Public Function CheckPassword(ByVal UID as long,PWD as string) as boolean
              dim PwdCorrect as boolean = false
             .... your script to test password
              return PwdCorrect
          End Function
          Public Sub InitialiseUser()
             FirstName = nothing
             LastName = nothing
             Email = Nothing
             Address = nothing
             Active = nothign
          End Sub
          Public Function GetUser(ByVal UID as long) as long
             ... your script to read user properties from db
             Return UID 
         end function
          Public Function SetUser(ByVal UID as long) as long
             ... your script to update database user properties 
             Return UID 
         end function
    End Class
End Namesapce

Open in new window


Author Comment

ID: 23702959
very nice....could you show me an example of what it would look like if i were returning a whole user record.  for instance.  if i had a sub called

Public function getUser(byVal UserID as Integer) as User

     DO I DIM A USER IN HERE?  dim u as New User()

    return u
End Function
LVL 11

Assisted Solution

mildurait earned 2000 total points
ID: 23702988
This is where you would read the values from your database into your object properties.
My example below assumes that i have built a connectivity class to setup and close adodb.recordset objects.

Dim oC as new MyProject.Connectivity
dim rs as adodb.recordset = oC.odbs("SELECT * FROM tblUser WHERE iUserID=" & UserID)
With rs
  If .eof = false then
           FirstName = .fields("sUserFirstName").value
           LastName = .fields("sUserLastName").value
           Email = .fields("sUserEmail").value
           Address = .fields("sUserAddress").value
           IsActive = .fields("bUserActive").value
       Call Initialise()
  end if
End with
oC = nothing

Open in new window


Author Comment

ID: 23788575
thanks for the help.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question