I'm creating an application which uses request.querystring to transfer variables between pages. However at the moment I am setting variable names in the URL dynamically in accordance with an array and I want to retrieve these values on another page using (essentially) the same array. So I came up with what I thought would be the simple solution:
For Each x In AnswerIDs
response.write(x)
ctest = Request.Querystring(x)
response.write(ctest)
Next
However this doesn't seem to work as it looks like you can't use Request.Querystring() with a variable as it's parameter. Has anyone got any idea how I could do this?
This is the query string:
QuizMark.asp?11=1&12=1
In this case AnswerIDs consists of "11" & "12" so in my loop I want it to write "1" & "1".
You can loop through the querystring like this:
For Each Item in Request.QueryString
Response.Write Item & ": " & Request.QueryString(Item) & "<br/>"
Next
Item contains the name of the querystring parameter, with Request.Querystring(Item) you retrieve the value of the parameter.
Your method will work with a simple modification:
For Each x In AnswerIDs
response.write(x)
ctest = Request.Querystring(CStr(x))
response.write(ctest)
Next
If your array might have Null elements, then replace the Cstr(x) with x & "".
If, on the other hand, you can make sure that every element of AnswerIDs has a value (i.e. is neither Empty nor Null), then you can omit the string conversion. In other words, the problem isn't with calling Request.Querystring with a variable, but with calling Request.Querystring with an Empty or a Null.
Related
I have a table of records that has two logical flags, holdn and holdl. I want to loop through this table with 3 different criteria.
Either flag is TRUE - We want to see everything that is on hold
Flag holdl is TRUE - We only want see items that are on hold for this one reason
Flag holdn is TRUE - We only want to see items that are on hold for this other reason.
I cannot figure out how to dynamically change the for each loop based on this. What I have tried so far is to set the value of a variable based on these conditions and then use the content of the variable as one of the where parameters. This does not work as Progress complains that there is a data mismatch. The variable is a string, the flags are logical, so that does make sense. See sample code below. This is a snippet of the actual code with the the table name changed. The which-hold, order-from, etc variables are defined and set in a different module which calls this one.
DEFINE VARIABLE which-hold# AS CHARACTER FORMAT "x(30)" NO-UNDO.
CASE which-hold:
WHEN "B" THEN which-hold# = "(widget.holdn or widget.holdl)".
WHEN "L" THEN which-hold# = "widget.holdl".
WHEN "N" THEN which-hold# = "widget.holdn".
END CASE.
for each widget where which-hold# and
widget.order-no >= order-from and widget.order-no <= order-thru and
widget.line-no >= line-from and widget.line-no <= line-thru and
widget.joint-no >= joint-from and widget.joint-no <= joint-thru
no-lock:
A bunch of code to make a nice report with the retrieved records...
end.
Self taught Progress programmer here, who has inherited a huge, poorly documented application. Please be gentle.
If you would prefer not to deal with handles a semi-dynamic approach is also possible:
define variable i as integer no-undo.
define query q for customer.
do while true:
update i.
case i:
when 0 then quit.
when 1 then open query q for each customer no-lock where custNum >= 1000.
when 2 then open query q for each customer no-lock where state = "nh".
otherwise open query q for each customer no-lock where name begins "u".
end.
do while true with frame a:
get next q.
if not available customer then leave.
display custNum name state with frame a 10 down.
down with frame a.
end.
close query q.
end.
What you want is actually a dynamic query. I'll get to it at the end, but first I'd like to explain why you won't be able to try and substitute the field name in the which-hold# variable: because the query is evaluated at compile time. And this is what it reads (supposing which-hold# has a value of widget.holdn
FOR EACH widget where "widget-holdn" (...)
And that does not evaluate to TRUE or FALSE. So what, you ask? Well, that is the key here. Every condition needs to evaluate to true or false, so you'd be more in luck if you try
for each widget where (if widget-hold# = 'widget.holdn' then widget.holdn = true else TRUE) (...)
Again, notice the condition will exist if widget-hold# has the value I want, otherwise it doesn't filter on this at all.
So you can just code the way I showed (for each of the conditions you have) and it should work fine.
BUT let me suggest a dynamic query instead.
You need to have:
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
CREATE QUERY hQuery.
hQuery:SET-BUFFERS(BUFFER widget:HANDLE).
hQuery:QUERY-PREPARE('<THIS IS THE CORE>').
hQuery:QUERY-OPEN().
DO WHILE hQuery:GET-NEXT():
A bunch of code to make a nice report with the retrieved records...
END.
So in the core you have a string that corresponds to your for each the way you want it to look. So it should be for example (store this in a variable, or assemble it inside the query prepare, it doesn't matter):
'FOR EACH widget NO-LOCK WHERE ' +
(if which-hold = 'B' then 'widget.holdn = true and widget.holdl = true'
else if which-hold = 'L' then 'widget-holdl = true'
else /* N */ 'widget-holdn = true').
Remember I said your query is evaluated at compile time? Well, just so you know, dynamic queries on the other end are evaluated at run time, so be prepared for errors to pop up only when you run. Another thing I should mention is dynamic queries are slower than static ones, so please evaluate and choose your poison :)
This should be what you need. Please let me know if it's helpful or any questions remain.
I was trying to combine two separate date/time fields into one text box through an expression in SSRS.
My expression is:
=Format(Fields!EarlyShiftStart.Value,"hh:mm tt") & "-" & Format(Fields!LateShiftEnd.Value,"hh:mm tt")
And it looks to be correct in the report:
But I am getting a warning when I preview the report:
Warning 1 [rsRuntimeErrorInExpression] The Value expression for the
textrun ‘Textbox49.Paragraphs[0].TextRuns[0]’ contains an error: Input
string was not in a correct format
Not sure why this warning occurs, as it looks to be correct. Thoughts?
I am not sure about it but there is seems to be the wrong input string getting from the database. My best guess is that there are 2 reasons in your case this was happening
1) Some where in your data might present the null value.
If you want to avoid the warning I will suggest to you that use the expression as,
=Format(IIF(IsNothing(Fields!EarlyShiftStart.Value),"00:00",Fields!EarlyShiftStart.Value),"hh:mm tt") & "-" & Format(IIF(IsNothing(Fields!LateShiftEnd.Value),"00:00",Fields!LateShiftEnd.Value),"hh:mm tt")
This will filter out the incoming NULL values.
2) You are concatenating the two values with - so that could be the reason as you are formatting both your values as Time and then concatenating with string value. So try to change your expression as,
=CStr(Format(Fields!EarlyShiftStart.Value,"hh:mm tt")) & "-" & CStr(Format(Fields!LateShiftEnd.Value,"hh:mm tt"))
This will force convert your time values to the string and then con-cat them.
I would also suggest you to look at your incoming values if all values are in the correct format. So you can make changes in your expression accordingly.
I have 16 items named q1,q2,q3,...,q16 and txt_q1,txt_q2,...,txt_q16
And I need to check each one, so I have a for and inside I have the If like this:
For Cnt AS Integer = 1 To 16 Step 1
If("q"&cnt = "") Then
"txt_q"&cnt.Style.Add("color","blue")
....
..
End If
End For
The idea is check al items with a For to avoid the 16 Ifs, but I have a syntax error.
What can I do?
the txt_q1,txt_q2... are IDs for asp:labels, and I have a radiobuttonList, so I get the radiobutton text and I set q1, q2, q3... to the corresponding radiobuttonlist. So I want to check if there is a radiobuttonlist that is not checked, if not I change the color to blue to the asp:label. So I want to avoid making 16 ifs for each radiobuttonlist and make it with a For, because the only thing that change in the variables is the number is the same "q" and the same "txt_q" so I want to add the number to "q" or "txt_q" to make it one variable called q1 or txt_q1 that already exist and that way acces to the txt_q1.Style.Add() and change the color of that label.
Thank You
Just for your understanding:
When you write "txt_q"&cnt, you are creating a new string literal which holds e.g. "txt_q1", "txt_q2", etc. This resembles the name of the variables, but is really something completely different. The name of the variable is just for you to write in code. The value of the variable is a reference to the control object. What you need is to obtain the reference to the controls. This can be done on several ways, one is to use the FindControl() method.
For Cnt AS Integer = 1 To 16 Step 1
Dim c = FindControl("q" & cnt) 'pass in the ID here, you will get a reference
'you can use c to access the properties e.g. c.Style
End For
Again, just to clarify
c.Style 'c is a variable holding a reference to the control
"c".Style ' "c" is a simple string
I'm currently working on a project that was written in classic asp. I've used this language some before but I'm rusty with it.
In that code I see the following function call:
Result = SwapOEMPart(sItem)
When I look at SwapOEMPart I see this:
function SwapOEMPart(oemPart)
// Do a bunch of stuff
oemPart = objRS("CCIPartNo") <-- this is the result of the stuff
end function
What does that do? Does it fill Result with the value of oemPart? Does it change the value of sItem (similar to a pass by reference)? Or perhaps it is something entirely different.
I'm familiar with returning data from asp functions by setting the function name equal to the value you want to return, but in this instance they are changing the value of the parameter they pass in and then just ending the function.
Based on the code you have provided, I'm going to assume objRS is an adodb.recordset, if that is the case, CCIPartNo is a column in the recorset, all your code is doing is writing the value of that column into the eomPart variable - eomPart isnt referenced as byref in the function declaration but this is assumed as default if you're in vbscript (not .net) so **it's almost as if the value of the column is being passed back into eomPart & because eomPart is a REFERENCE to the sItem value in your example, the actual value of sItem would change.
http://msdn.microsoft.com/en-us/library/ee478101%28VS.84%29.aspx
I have many constant variables for example:
Const Total_US_Price = "100"
However, in my code, I am pulling a string "Total_US_Price". I want to replace my string with the value of the Const variable.
How do I do that? How do I change "Total_US_Price" to return "100" (both being strings)?
It sounds like you want to use the eval() function...
http://www.devguru.com/technologies/vbscript/QuickRef/eval.html
EDIT: I hope you're not pulling these strings from the client side (query string, POSTed form values, or cookies) or else you are opening yourself up for a world of hurt. Someone could inject whatever strings they wanted and it will get executed on your web server.
Not sure what you exactly mean with 'pulling a string' but please don't abuse eval. Use a lookup table for lookup values.
set x = createobject("scripting.dictionary")
x("total_us_price") = 100
price = x("total_us_price")
You would use the "CInt " function.
VBScript CInt Function explained and usage.
I don't think this can be done other than by executing code dynamically, using either Eval() to get the value directly, or Execute() to get it by side-effect.
Specifically:
MyVarName = "Total_US_Price"
Value100 = Eval(MyVarName)
' Or...
Exectute("Value100 = " + MyVarName)
The Eval is more practical, but less flexible...