INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Using classes in VBScript

Using classes in VBScript

(OP)
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

RE: Using classes in VBScript

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")

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close