I'd like to know what is the exact code for dynamic variable from link and have it set via conditions of If and If else.
let say i have link of default.asp?variable=value&string=number
how can i get this into my page with coding it in conditional term. (not sure if my code is correct)
<%
DIM value = something
If blah-blah then
[asp code here]
else if blah-blah then
[another asp code here]
end if
%>
i have to match a dynamic value on If and Else If, something like that.
thanks in advance...
I'm going to assume your question is about ASP classic and that you're going to handle:
default.asp?cmd=add&x=5&y=4
default.asp?cmd=mult&x=5&y=4
And, respectively, you want the outputs to be
Answer is 9
Answer is 20
The ASP for that would be something like:
<html>
<head>
<title>simple asp</title>
</head>
<body>
<%
Dim cmd, x, y
cmd = Request.QueryString("cmd")
x = CDbl(Request.QueryString("x"))
y = CDbl(Request.QueryString("y"))
Select Case cmd
Case "add"
Response.Write("Answer is " & (x + y))
Case "mult"
Response.Write("Answer is " & (x * y))
Case Else
Response.Write("Please supply a valid cmd")
End Select
%>
</body>
</html>
get idea from this line of codes
<%
Set udrmcatgry=TheDB.Execute("SELECT * FROM rmcatgry ORDER BY sl asc")
Do while Not udrmcatgry.eof=true
myqsl=udrmcatgry("sl")
TheDB.Execute "Update `rmcatgry` set catnme`='"&request.form(""+myqsl+"")&"' where sl='"&myqsl&"' "
udrmcatgry.MoveNext
Loop
%>
Related
Hi i don't have RedDot CMS and i want to know is it possible to use <!IoRangeList> inside <!IoRangePreExecute> also use ASP Classic to get sum of the elements inside for loop.
Or is the other way to do it
Here is my code
<!IoRangePreExecute>
<%
Dim a(5), b, c
%>
<% d = 0 %>
<!IoRangeList>
' user range list as loop to get value from reddot
a(<% d = d + 1 %>) = <%value%>
<!/IoRangeList>
<% For Each b in a
c = c + Cint(b)
Next
Response.Write(c)
%>
<!/IoRangePreExecute>
Im wondering is the correct way to do it
It would be easier to use the built in foreach loop tag, but yes you can do this that way(although the code in the rangelist isn't complete)
It is possible, but I would not recommend it. PreExecute is very inefficient, avoid if you can.
Prior to my recent departure from OpenText, I generally used iorangelist to output client-side code - perhaps as javascript data - and then used JS/JQuery to build a dynamic UI from this.
For your specific question, I would simply output the List loop as a client-side javascript:
<script>
var a = 0;
<%iorangelist%>
a += <%value%>; //I'd check for numeric here.
<%/iorangelist%>
console.log(a);
</script>
I'm new to classic asp and I'm trying to figure out this simple if else statement.
For some reason it's just recognizing person 2 and not even trying person 1?
Any idea on how to fix? Thanks
This is my code:
<%
Dim GetPath
GetPath = request.ServerVariables("URL") & query_string
Dim page
page = "/products/dowlex/index.htm"
if GetPath = page then
varrecipient = "email1#email.com"
Response.Write("*Path = " & GetPath)
Response.Write("Person 1")
else
varrecipient = "email2#email.com"
Response.Write("*Path = " & GetPath)
Response.Write("Person 2")
end if
varFormName = "Contact"
varRHBusinessUnit = "businessname"
varLanguage = "ENGLISH"
varCourtesyResponse = "Y"
varRedirect = "#noredir?formRun=true"
varSubject = "Ask an Expert Form"
%>
I would compare the two strings based on the same case...
if UCase(GetPath) = UCase(page) then
And of course, if query_string ever has a value, then the 1st case will never be true.
The formatting of your statement is fine. If... Then... Else... End if.
I would do a Response.Write("GetPath") to see if you are getting back, what you think you should be.
I have a couple thoughts.
1) Can you use Response.Write to display what's in "GetPath" before the if statement? That might help you see what's going wrong!
2) Try changing the variable names. The editor is making "GetPath" blue, as though it's a reserved word. That might be messing things up.
I'm sorry guys, I messed up a small code and thats why it wasn't working.
I forgot to complete the full path of the site. Thanks for all your help and suggestions!
*Path = /plasticpipes/eu/products/dowlex/index.htm
*Page = /products/dowlex/index.htm
I am pretty new to ASP, I know VBScript reasonably well though. What I am trying to do is create a website with 2 frames. In the top frame, it asks for a year (from a selection box) and a week number (from a selection box). It should then display the dates relating to the selection and a button to process the request. When the button is clicked the bottom form then processes a SQL query based on the selection in the top frame and displays the info.
Now, my problem is when it comes to understanding ASP. With ASP, all the code is processed then the output is sent to the browser. How do you update variables or even pass them to other frames when the code has already processed?
I just need some pointers on the way forward to accomplishing the above.
Thanks
First off, don't use frames: they're annoying, ugly, and outmoded.
You can do something like this in asp, but it's going to require a round trip (or two) to the server.
The basic outline of the page (let's call it thispage.asp) would be something like
<html><head>[head stuff]
<%
dim yr, wk, i
yr = request.form("Year")
wk = request.form("Week")
'- if you use form method='get', then use request.querystring("Year")
if not isnumeric(yr) then
yr = Year(date) 'or whatever else you want to use as a default
else
yr = CInt(yr)
end if
'similar validation for wk
%>
</head>
<body>
<form method="post" action="thispage.asp">
<select name="Year" size="1">
<%
for i = Year(Date) - 2 to Year(Date) + 2
response.write "<option value='" & i & "'"
if i = yr then response.write " selected"
response.write ">" & i & "</option>"
next
%>
</select> [similar code for week or date or whatever]
<input type="submit">
</form>
<%
If yr <> "" and wk <> "" Then
'- look up stuff in database and output the desired data
'- (this part will be much longer than this)
Else
Response.Write "<p>Please make your selections above.</p>"
End If
%>
</body></html>
If you need to output form fields that are dependent on the user's initial year & week selections, then you're going to need more than one trip to the server, but it's still the same idea: set up the variables you're going to need, see if they have values, write out the form, and then if all the necessary variables have all the necessary values, then you can do your output stuff.
This code was working up until today now I keep getting the buffer exceeded error. I'm positive there is a much better way to do this but I have no idea how.
What I'm trying to do is display any entry from the current date to two weeks out. Users can enter any date within that two week period and the table will fill the spaces in between or after with a default "GREEN" span. I had it working until today. I haven't touched it in three weeks and I have no idea what happened. I'm a lowly graphic designer who's bosses don't know the difference between html/css and asp/sql driven applications. Please help before I go insane...
<div class="cond_holder">
<div class="dir_name">PEDS CARDIOLOGY</div>
<%
Dim this_day_peds_cardio
this_day_peds_cardio = Date
Dim Conditions_peds_cardio
Dim Conditions_peds_cardio_cmd
Dim Conditions_peds_cardio_numRows
Set Conditions_peds_cardio_cmd = Server.CreateObject ("ADODB.Command")
Conditions_peds_cardio_cmd.ActiveConnection = MM_webdbs_STRING
Conditions_peds_cardio_cmd.CommandText = "SELECT * FROM dbo.ryg_conditions WHERE aoc='1' AND Day >= DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0) ORDER BY aoc ASC, Day ASC"
Conditions_peds_cardio_cmd.Prepared = true
Set Conditions_peds_cardio = Conditions_peds_cardio_cmd.Execute
Conditions_peds_cardio_numRows = 0
Dim Repeat_peds_cardio__numRows
Dim Repeat_peds_cardio__index
Repeat_peds_cardio__numRows = 14
Repeat_peds_cardio__index = 0
Conditions_peds_cardio_numRows = Conditions_peds_cardio_numRows + Repeat_peds_cardio__numRows
While ((Repeat_peds_cardio__numRows <> 0) AND (NOT Conditions_peds_cardio.EOF))
If DateDiff("d", (Conditions_peds_cardio.Fields.Item("Day").Value), this_day_peds_cardio)=0 Then
%>
<span class="daily_condition <%=(Conditions_peds_cardio.Fields.Item("ryg").Value)%>">
<span style="display: none;"><%=(Conditions_peds_cardio.Fields.Item("aoc").Value)%></span>
<%=(Conditions_peds_cardio.Fields.Item("ryg").Value)%>
<span class="reason"><%=(Conditions_peds_cardio.Fields.Item("reasoning").Value)%></span>
</span><!-- /.daily_condtion -->
<%
this_day_peds_cardio = DateAdd("d", 1, this_day_peds_cardio)
Else
While DateDiff("d", (Conditions_peds_cardio.Fields.Item("Day").Value), this_day_peds_cardio)<>0
%>
<span class="daily_condition GREEN">GREEN</span><!-- SPACER -->
<%
this_day_peds_cardio = DateAdd("d", 1, this_day_peds_cardio)
Wend
%>
<span class="daily_condition <%=(Conditions_peds_cardio.Fields.Item("ryg").Value)%>">
<span style="display: none;"><%=(Conditions_peds_cardio.Fields.Item("aoc").Value)%></span>
<%=(Conditions_peds_cardio.Fields.Item("ryg").Value)%>
<span class="reason"><%=(Conditions_peds_cardio.Fields.Item("reasoning").Value)%></span>
</span><!-- /.daily_condtion -->
<%
this_day_peds_cardio = DateAdd("d", 1, this_day_peds_cardio)
End if
Repeat_peds_cardio__index=Repeat_peds_cardio__index+1
Repeat_peds_cardio__numRows=Repeat_peds_cardio__numRows-1
Conditions_peds_cardio.MoveNext()
Wend
While loop_ctr_peds_cardio < 14
%>
<span class="daily_condition GREEN">GREEN</span><!-- FILLER -->
<%
loop_ctr_peds_cardio = loop_ctr_peds_cardio +1
Wend
%>
</div><!-- /#cond_holder -->
When I read your source code, I came up with two thinks:
You use too many script tags (<% %>), even to seperate vbscript code. This overusing makes it hard to read and understand your code. I had to paste your source code into Notepad++ to tidy up and reading your code.
You didn't use a recordset for the first while query. If you want loop through a result of a Selectquery use the recordset object. It is more convinence to handle and prevents some general errors. Does the using of a recordset eleminate your error?
To your problem:
Do you use an IIS6.0 or higher? If so then following ideas could help (I got it from a german! site of Microsoft, posted in stackoverflow.com (see here). The idears are:
Using Response.Flush()
Turn the Response.Buffer off on the page, or on the entire site.
Response.Buffer = False at the top of the page before any ASP code.
Increase the size of the buffer (see the link on 'see here' position).
Decrase the size of your response.
The reason your response buffer is overflowing is because you have more data to show now. The quickest way to get it sorted should be to issue a Response.Flush every couple of rows or so (depending on how big the response buffer is) inside your while loop. Turning off the response buffer will almost always result in the page taking longer to render, especially if you have lots of context switches like you do.
For example, how can I run me.test below?
myvar = 'test'
me.myvar
ASP looks for the method "myvar" and doesn't find it. In PHP I could simply say $me->$myvar but ASP's syntax doesn't distinguish between variables and methods. Suggestions?
Closely related to this, is there a method_exists function in ASP Classic?
Thanks in advance!
EDIT: I'm writing a validation class and would like to call a list of methods via a pipe delimited string.
So for example, to validate a name field, I'd call:
validate("required|min_length(3)|max_length(100)|alphanumeric")
I like the idea of having a single line that shows all the ways a given field is being validated. And each pipe delimited section of the string is the name of a method.
If you have suggestions for a better setup, I'm all ears!
You can achieve this in VBScript by using the GetRef function:-
Function Test(val)
Test = val & " has been tested"
End Function
Dim myvar : myvar = "Test"
Dim x : Set x = GetRef(myvar)
Response.Write x("Thing")
Will send "Thing has been tested" to the client.
So here is your validate requirement using GetRef:-
validate("Hello World", "min_length(3)|max_length(10)|alphanumeric")
Function required(val)
required = val <> Empty
End Function
Function min_length(val, params)
min_length = Len(val) >= CInt(params(0))
End Function
Function max_length(val, params)
max_length = Len(val) <= CInt(params(0))
End Function
Function alphanumeric(val)
Dim rgx : Set rgx = New RegExp
rgx.Pattern = "^[A-Za-z0-9]+$"
alphanumeric = rgx.Test(val)
End Function
Function validate(val, criterion)
Dim arrCriterion : arrCriterion = Split(criterion, "|")
Dim criteria
validate = True
For Each criteria in arrCriterion
Dim paramListPos : paramListPos = InStr(criteria, "(")
If paramListPos = 0 Then
validate = GetRef(criteria)(val)
Else
Dim paramList
paramList = Split(Mid(criteria, paramListPos + 1, Len(criteria) - paramListPos - 1), ",")
criteria = Left(criteria, paramListPos - 1)
validate = GetRef(criteria)(val, paramList)
End If
If Not validate Then Exit For
Next
End Function
Having provided this I have to say though that if you are familiar with PHP then JScript would be a better choice on the server. In Javascript you can call a method like this:-
function test(val) { return val + " has been tested"; )
var myvar = "test"
Response.Write(this[myvar]("Thing"))
If you are talking about VBScript, it doesn't have that kind of functionality. (at least not to my knowledge) I might attempt it like this :
Select myvar
case "test":
test
case "anotherSub":
anotherSub
else
defaultSub
end select
It's been a while since I wrote VBScript (thank god), so I'm not sure how good my syntax is.
EDIT-Another strategy
Personally, I would do the above, for security reasons. But if you absolutely do not like it, then you may want to try using different languages on your page. I have in the past used both Javascript AND VBScript on my Classic ASP pages (both server side), and was able to call functions declared in the other language from my current language. This came in especially handy when I wanted to do something with Regular Expressions, but was in VBScript.
You can try something like
<script language="vbscript" runat="server">
MyJavascriptEval myvar
</script>
<script language="javascript" runat="server">
function MyJavascriptEval( myExpression)
{
eval(myExpression);
}
/* OR
function MyJavascriptEval( myExpression)
{
var f = new Function(myExpression);
f();
}
*/
</script>
I didn't test this in a classic ASP page, but I think it's close enough that it will work with minor tweaks.
Use the "Execute" statement in ASP/VBScript.
Execute "Response.Write ""hello world"""
PHP's ability to dynamically call or create functions are hacks that lead to poor programming practices. You need to explain what you're trying to accomplish (not how) and learn the correct way to code.
Just because you can do something, doesn't make it right or a good idea.
ASP does not support late binding in this manner. What are you trying to do, in a larger sense? Explain that, and someone can show you how to accomplish it in asp.
Additionally, you might consider "objectifying" the validation functionality. Making classes is possible (though not widely used) in VB Script.
<%
Class User
' declare private class variable
Private m_userName
' declare the property
Public Property Get UserName
UserName = m_userName
End Property
Public Property Let UserName (strUserName)
m_userName = strUserName
End Property
' declare and define the method
Sub DisplayUserName
Response.Write UserName
End Sub
End Class
%>