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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Dynamic Classes 1

Status
Not open for further replies.

Mugs321

Programmer
Jan 31, 2007
49
CA
Hey all,

I'm trying to create a dynamic class to handle user permissions on my site. Right now, if I add a new permission field to the db, I also have to create the GET/SET properties in the class itself.

I'm looking to have the class created dynamically based on the fields in a specified table. This way, adding a new permission is a one-step process.

As a first step, I decided to forgo the GET/SET methods and simply create PUBLIC variables.

My variables are being created properly, but since all code has to fall into a sub/fn I can't create my dims dynamically (ie. PUBLIC strHello, strHello1).

Any thoughts? I can show the code if you think it'll help.

Thx,
Dave
 
What language are you using? Looks like C# or vb.net from what you're describing but I can't tell which.
 
What if your class a property named .TableFields that returned an object of type Scripting.Dictionary?

Your class initialization logic could be something like this:
Code:
Class Permissions
  Public TableFields

  private sub Class_Initialize() 
    Dim CN, RS, oFLD

    Set CN = Server.CreateObject("ADODB.Connection")
    CN.Open Application("MyConnectionString")
    Set RS = CN.Execute("SELECT * FROM TheTable WHERE 1=2")

    Set TableFields = CreateObject("Scripting.Dictionary")

    For Each oFld in RS.Fields
      TableFields.Add oFld.Name, ""
    Next
    
    Set oFld = Nothing
    Set RS = Nothing
    CN.Close
    Set CN = Nothing
  end sub 

  private sub Class_Terminate() 
    Set TableFields = Nothing
  end sub  
End Class
 
I am using VBScript...

Sheco:
Your solution works great. Not only that, I've been complaining for a while now about the fact that ASP didn't have associative arrays... guess I was wrong.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top