How do I rename or delete a tag?
Problem using Execute to dynamically create variables
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > ASP web-programming > Problem using Execute to dynamically create variables 6 May 2005 06:57:54

  Recent blog posts: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

Problem using Execute to dynamically create variables

Colin Mc Mahon 6 May 2005 06:57:54
 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.ServerVaria­bles("HTTPS")
if LCase(protocol) = "on" Then protocol = "https://" else protocol =
"http://"
i_URL = protocol & Request.ServerVaria­bles("HTTP_HOST") &
Request.ServerVaria­bles("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_Item­Count)
' 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&ite­m2=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


Add comment
Colin Mc Mahon 6 May 2005 06:57:54 permanent link ]
 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


Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > ASP web-programming > Problem using Execute to dynamically create variables 6 May 2005 06:57:54

see also:
user postgres
Is there anyway to create a functional…
size of indexes and tables (more than…
пройди тесты:
see also:
My brother taught me this prayer
The song my brother taught me
can some1 please help me in...

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .