Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using classes in VBScript 1

Status
Not open for further replies.

wbodger

Programmer
Apr 23, 2007
769
US
OK, I am new to classes and I am trying to implement a standard query that we will use on many pages that will get standard user info. I will always have a staffid to pass in and I have the sql, I am just not sure of the syntax. So, here is my first crack at it

Code:
Class UserInfoClass
    Private m_userinfo

    Public Sub Class_Initialize()
        Set m_userinfo = Server.CreateObject("Scripting.Dictionary")
    End Sub

    Public Property Get UserInfo()
        Set UserInfo = m_userinfo
    End Property

    Public Property Set UserInfo(value)
        set m_userinfo = value
    End Property
End Class

function GetUserInfo(staffID)
  Dim conn, sqltext
  Dim userinfo : Set userinfo = Server.CreateObject("Scripting.Dictionary")
  Set conn=Server.CreateObject("ADODB.Recordset")
      sqltext = "SELECT s.SiteID, SiteName, s.SiteURL, st.FirstName, st.LastName, st.Email " &_
		"FROM NewCompass.dbo.tblSite s " &_
			"join NewCompass.dbo.tblStaffProtocol sp on s.SiteID=sp.SiteID " &_
			"join NewCompass.dbo.tblStaff st on st.StaffID=sp.StaffID "&_
		"WHERE st.StaffID='"& session("sessionUserID")&"' " &_
		"and ProtocolID=0 and ProjectID=3"
      conn.Open sqltext, strNewCompass

      userinfo.add "siteid",conn("siteid")
      userinfo.add "SiteName",conn("SiteName")
      userinfo.add "SiteURL",conn("SiteURL")
      userinfo.add "FirstName",conn("FirstName")
      userinfo.add "LastName",conn("LastName")
      userinfo.add "Email",conn("Email")

    Set GetUserInfo = userinfo

      conn.Close
      set conn=nothing
end function

And then I was calling it by

Code:
Dim oUserInfoClass : Set oUserInfoClass = New UserInfoClass
Set oUserInfoClass.UserInfo = GetUserInfo(session("sessionuserid"))

dim siteid : siteid = ouserinfoclass.item("siteid")

response.write siteid

I know that I am missing pieces here, but not sure how to get here. Is my class setup correctly? If so, then how do I pull out specific data pieces in my pages? If not, can you help me with the class piece first?

Thanks!

wb
 
Yes it is set up correctly but I would have called oUserInfoClass either oUserInfo or userInfoObj or objUserInfo. Since it is not a class, I'd leave the Class out. The MS naming convention would be to call the class ClsUserInfo and the object objUserInfo. To get siteid from what you've written
Code:
fn = oUserInfoClass.UserInfo.item("siteid")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top