Trying to understand constructors

D

darrel

I posted a question below and GroupReader suggested I look into constructors
as the solution to my problem.

So, that's what I'm doing, but I'm a little hung up on how to pass data back
to my page.

What I'm doing is trying to set up a class that can read a cookie and pass
the data back to the particular page. I looks like I need something like
this:

Public Class UserSecuritySettings
public sub ReadCookie()
....
su_strUser = Server.HtmlEncode(Request.Cookies("CMSUser")("su_strUser"))
su_strDistrict =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_strDistrict"))
....
end sub
End Class

Then, on my page, I'd do:

dim securitySettings as new UserSecuritySettings
scuritySettings.ReadCookie()

The problem is that I have no idea how to access the variables in the class.
Since a constructor has to be a sub, I see no way to pass back a value.

-Darrel
 
D

David Browne

darrel said:
I posted a question below and GroupReader suggested I look into
constructors as the solution to my problem.

So, that's what I'm doing, but I'm a little hung up on how to pass data
back to my page.

What I'm doing is trying to set up a class that can read a cookie and pass
the data back to the particular page. I looks like I need something like
this:

Public Class UserSecuritySettings
public sub ReadCookie()
...
su_strUser =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_strUser"))
su_strDistrict =
Server.HtmlEncode(Request.Cookies("CMSUser")("su_strDistrict"))
...
end sub
End Class

Then, on my page, I'd do:

dim securitySettings as new UserSecuritySettings
scuritySettings.ReadCookie()

The problem is that I have no idea how to access the variables in the
class. Since a constructor has to be a sub, I see no way to pass back a
value.


You need to declare a Function, not a Sub to return data to the caller.

Public Class UserSecuritySettings
public Function ReadCookie(CookieName as string) as string
return Server.HtmlEncode(Request.Cookies("CMSUser")(CookieName))
end sub
End Class


Then

dim user as string = scuritySettings.ReadCookie("su_strUser")
dim district as string = scuritySettings.ReadCookie("su_strDistrict")


David
 
J

Just Me

I think your getting a little confused here. Firstly a class with no shared
members needs to be instantiated in order to access its member functions and
subs.

You class could look something along the lines of, if you dont want to
instantiate

setting =
UserSecuritySettings.getUserCookieSettings("CMSUser","su_strUser")


Public Class UserSecuritySettings

public shared function getUserCookieSettings( CookieName as String,
cookieProperty as String ) as String

return =
Server.HtmlEncode(Request.Cookies(CookieName)(cookieProperty )

end function

End Class
 
D

darrel

You need to declare a Function, not a Sub to return data to the caller.
Public Class UserSecuritySettings
public Function ReadCookie(CookieName as string) as string
return Server.HtmlEncode(Request.Cookies("CMSUser")(CookieName))
end sub
End Class

Then

dim user as string = scuritySettings.ReadCookie("su_strUser")
dim district as string = scuritySettings.ReadCookie("su_strDistrict")

The problem with that is that it 'request' is not declared. I assume I need
to fully qualify it?

-Darrel
 

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

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top