Declaring variables

  • Thread starter Thread starter HHickey
  • Start date Start date
H

HHickey

We are developing our user security for our vb.net web product and trying to
design a page that would list the different pages in a drop down/list or
something similar allowing a supervisor to select pages that their employee
would have access to. Taking it one step further - we would then like to
list all of the objects on this page or atleast have access to them to give
access further down the scale (Save / Delete / Change access on a page). To
do this - I am thinking that I would have to declare a variable of type that
was selected by the user - and this is where I have stopped. I know in
declaring a variable I have to specify a type:
Dim frmTemp as WebProject.WebPage1

Is there a way for me to declare a variable of type which the user selected
from a drop down.
Dim frmTemp as <Dropdown.SelectItem.Name>

I know that I could declare a variable of type WebPage and then ctype() it.
But then again I would have to declare a type. I know that I do not have
macro substitution as I do in Visual FoxPro. My only other thought of how
to get around this is a case statement and code each one appropriately.

??
Thanks
Heather Hickey
 
We are developing our user security for our vb.net web product and trying to
design a page that would list the different pages in a drop down/list or
something similar allowing a supervisor to select pages that their employee
would have access to. Taking it one step further - we would then like to
list all of the objects on this page or atleast have access to them to give
access further down the scale (Save / Delete / Change access on a page). To
do this - I am thinking that I would have to declare a variable of type that
was selected by the user - and this is where I have stopped. I know in
declaring a variable I have to specify a type:
Dim frmTemp as WebProject.WebPage1

Is there a way for me to declare a variable of type which the user selected
from a drop down.
Dim frmTemp as <Dropdown.SelectItem.Name>

I know that I could declare a variable of type WebPage and then ctype() it.
But then again I would have to declare a type. I know that I do not have
macro substitution as I do in Visual FoxPro. My only other thought of how
to get around this is a case statement and code each one appropriately.

??
Thanks
Heather Hickey

I'll outline an approach. First, a generic way to do something like this,
and then a more "customized" way to matches your needs more closely.

A declaration requires a specific type so you can't realy "dim" something
like what you're asking.
What you *can* do is create a "Object" variable.

Dim UserVar as Object

Then you can do

UserVar = Activator.CreateInstance([TypeName])

note that this means late binding, but you can overcome this issue like
this:
Define a variable for each type that is possible to instatiate by the user:

Dim UserVar as object
Dim o1 as Class1
Dim O2 as Class2
....

After you create the instance of the object and put it into UserVar (as
above) check what is the type of the created object using
UserVar.GetType(). use a select case statement to set that UserVar to the
approprate "Dim"ed variable of the type that corresponds to that type and
voila - no late binding issue.


I'm not sure you need to overcome the latebinding issue. The solution I've
outlined here is too generic for you.

--solution 2
For your purposes (finding all objects on the form) you can just decalre
UserVar as a WebForm object (which automatically encapsulates what you need
to get all the controls from it.

You then create an instance of the required page type and put it into the
UserVar and interate over all the controls no matter what type of page it
is.
 
Back
Top