Problem using Execute to dynamically create variables

Discussion in 'ASP General' started by Colin Mc Mahon, May 6, 2005.

  1. 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
    Colin Mc Mahon, May 6, 2005
    #1
    1. Advertising

  2. 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
    Colin Mc Mahon, May 6, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    9
    Views:
    935
  2. Savas Ates
    Replies:
    1
    Views:
    276
    Patrice
    Aug 17, 2004
  3. Phil Grimpo

    Session Variables Cleared afer Server.Execute

    Phil Grimpo, Jan 27, 2005, in forum: ASP General
    Replies:
    5
    Views:
    515
    Phil Grimpo
    Jan 28, 2005
  4. Adam Akhtar
    Replies:
    3
    Views:
    135
    Robert Klemme
    Nov 16, 2008
  5. iporter
    Replies:
    11
    Views:
    467
    Thomas 'PointedEars' Lahn
    Jan 20, 2008
Loading...

Share This Page