Trying to understand constructors

  • Thread starter Thread starter darrel
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top