Problem using Execute to dynamically create variables

C

Colin Mc Mahon

Hi,

I am trying to re-write an old url management class I use, and am having
problems using the Execute method to create vars. I think i'm missing
something simple, as I have used this method several times to perform this
kind of action, maybe it just needs some fresh eyes :) The code i'm using is
as follows:
Class cURL
' *--- [ Private variable
declarations ] --------------------------------------------------*
Private i_ItemCount
Private i_URL, i_QSURL, arFieldNames

' *--- [ Initialisation/termination
routines ] ----------------------------------------------*
Private Sub Class_Initialize()
arFieldNames = Array()
End Sub
Private Sub Class_Terminate()
' Clean up objects and data
End Sub

' *--- [ Class
properties ] -------------------------------------------------------------*
Public Property Get cnt
cnt = i_ItemCount
End Property
Property Get URL
URL = i_URL
End Property
Property Get QSURL
QSURL = i_QSURL
End Property

' *--- [ Class
Methods ] ---------------------------------------------------------------*
Public Sub Load
Dim protocol, sQuery, i, x
Dim nStart, url, url_element, vItem
protocol = "" & Request.ServerVariables("HTTPS")
if LCase(protocol) = "on" Then protocol = "https://" else protocol =
"http://"
i_URL = protocol & Request.ServerVariables("HTTP_HOST") &
Request.ServerVariables("SCRIPT_NAME")
' get QueryString if there is one
sQuery = Request.QueryString()
if sQuery <> "" Then sQuery = "?" & sQuery Else sQuery = ""
i_QSURL = i_URL & sQuery
i_ItemCount = Request.QueryString.Count
If i_ItemCount = 0 Then Exit Sub
' At this point we know we have some q string data
ReDim arFieldNames(i_ItemCount)
' build the internal map of name-value pairs from the url.
url = Request.QueryString()
url_element = split(url, "&")
'if the url has no parameters
if IsNull(url_element(0)) Or url_element(0) = "" Then Exit Sub
'if the url has parameters
for i = 0 to UBound(url_element)
vItem = split(url_element(i), "=")
arFieldNames(i) = vItem(0)
Execute("qs_" & arFieldNames(i) & "=" & vItem(1)) ' PROBLEM LINE
Next
End Sub

Public default Function Items(str_item)
Dim intOrdinal, i, strTest
If i_ItemCount = 0 Then Items = "" : Exit Function
strTest = "qs_" & str_item
If Len(Eval(strTest)) = 0 Then
Items = "" ' Always returns this!
Else
Items = Eval(strTest)
End If
End Function
End Class

On the calling page:
<% Dim g_URL : Set g_URL = New cURL : g_URL.Load %>
<a href="<%= g_URL.URL & "?item1=astring&item2=lop"%>">Test QueryString</a>
<br>
<br>
<br>
URL: <%= g_URL.URL %>
<br>
Full URL: <%= g_URL.QSURL %>
<br>
Item Count: <%= g_URL.cnt %>
<br>
Request item: <%= g_URL("item1") %>

Thanks for your time,
Colin
 
C

Colin Mc Mahon

Hi, sorry vbscript fatigue setting in! I found the problem, the line that
reads:
Execute("qs_" & arFieldNames(i) & "=" & vItem(1)) ' PROBLEM LINE

Should have read:
Execute("qs_" & arFieldNames(i) & " = """ & vItem(1) & """")
because the qs is a string.

Thanks anyway,
Colin
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top