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

Dynamic Varilables

Status
Not open for further replies.

FateFirst

Programmer
Apr 15, 2002
212
GB
Hi there.

Basically I want to be able to dynamically create variables. The variables will take their name from the column names in a table and then the information from the relevant field is the data that goes into each variable.

If anyone could supply an answer/idea, that would be very much appreciated.

Many thanks!
 
[tt]If it's a form your are using\submitting:
[ol][li]When you enter data into your database create Session Varialbes holding whatever information you want from the form[/li] [li]Display the Session variable as you please[/li][/ol]

If I undertood the question correctly, this would be my idea.
[/tt]

"The reward of one duty done is the power to fulfill another"
J R C L [jester] W N


 
What you are talking about almost sounds more like a recodset than a variable. In cases were you create a recordset the variable is essentialy the field name of the table, and the values are stored under that field name.

I would really need to know what you are trying to do to explain it better. But I would avoid using the session objects if you are going to hold alot of data, becuase these are objects that will take up more memory on the server than what is really needed, and are hard to get rid of when you are done with the variable.
 
[tt]When you say "Basically I want to be able to dynamically create variables."[/tt]

I saying to create the variables before they get to the page so you can carry them across pages and place them where you want to. I don't know how you would create variables after you write them


"The reward of one duty done is the power to fulfill another"
J R C L [jester] W N


 
Sounds more like the Scripting.Dictionary.
Dim dctD
Set DctD = CreateObject("Scripting.Dictionary")
dctD.Textcompare = 1 ' Case Insensitive key names

dctd(whatever) = whateverdata
.........
dim aryColKeys
dim aryColData
aryColKeys = dctd.Keys ' array of keys
aryColData = dctd.Items ' array of data
Session("aryColKeys") = arycolkeys
Session("aryColData") = arycoldata
......
arycolkeys = Session("aryColKeys") ' Restore keys
arycoldata = Session("aryColData") ' Restore data
For I = 0 To Ubound(aryKeys)
dctd(aryKeys(i)) = dctd(aryData(i))
Next Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
My apologies for not explaining this better, I will give an example:

Lets say 1 table contains 5 fields:

table_id
table_main_1
table_main_2
table_main_3
table_main_4

Do the usual methods to get the data then assign the data to the variables:

table_id = objRecordSet("table_id")
table_main_1 = objRecordSet("table_main_1")
table_main_2 = objRecordSet("table_main_2")
table_main_3 = objRecordSet("table_main_3")
table_main_4 = objRecordSet("table_main_4")

Now instead of having to do the above assigning bit manually, I just want to be able to change the SQL statement and it will dynamically build the above using the field names as the names of the variables and the field content as the data assigned to each variable. Is this possible, and if so which is the best way around this.

Just as a note I dont really want to use sessions though, as it is quite resource intensive.

Thanks people, great replies so far...its just my lame explaining that didnt help :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top