ASP security code if else doesn't work - security

We have an old project we decide to implement a security code to our resume form I put that code bottom and my question is why if else statement doesn't work even code and form input was equal.
if (Session("random_code")<>request.form("input_code")) then
Response.Write "wrong code"
else
Response.Write "true"
end if
result is always wrong code I mean only first statement works.

Wild guess. Try by adding a Cstr() around both session() and request.form()
This makes sure you are comparing string subtypes.

Related

Excel Nested IF statements returning False

I am constructing a nested IF statement, and I believe I am missing an ELSE but I cannot figure out where. I have the following statement:
=
IF(AND(B2="4",E2="R37",X2="Y"), "Non-Competing",
IF(AND(B2="4",E2="R37",X2="N"), "Competing",
IF(AND(B2="4",E2<>"R37",RIGHT(Z2,2)="00"), "Non-Competing",
IF(AND(B2="4",E2<>"R37",RIGHT(Z2,2)<>"00"), "Competing",
IF(B2<>"4","-")))))
I thought the last bit would cover the rest, but I am receiving a FALSE when I was hoping to get a result. For example, when B2=4, E2=R37, and X2=Y, I am expecting "Non-Competing" but am receiving FALSE. I also tried a combination with OR:
IF(OR(AND(B41="4",E41="R37",X41="Y"),
AND(B41="4",E41<>"R37",RIGHT(Z41,2)="00")), "Non-Competing",
IF(OR(AND(B41="4",E41="R37",X41="N"), AND(B41="4",E41<>"R37",RIGHT(Z41,2)
<>"00")), "Competing",
IF(B41<>"4","-")))
...which gives me the same result.
Any assistance would be greatly appreciated!
The missing else is in IF(B2<>"4","-"). You need IF(B2<>"4","-",<whatever last-ditch-answer>) If you are reaching False, then B2 is 4, but none of the other full conditions were met.
Without seeing your data, I can't know for sure, but I'm guessing that you may have intended that entire statement to behave as an else. If that is case, I would replace IF(B2<>"4","-") directly with "-".

return value from select case

How can I get the value from the expression in my Select Case statement?
When we write select case statements, we are told that good practice is to have a case else at the end. I understand the purpose of this to be if we don't think of all possible cases, there is a way to inform us instead of just moving on. Usually I just use debug.assert in that case, which works great for personal debugging and is sometimes sufficient for some end users after delivery.
That doesn't work well when I am writing to the VBE, as breaking is not supported anytime after the VBE has been called. I realize that I could probably unload the VBE object and then debug.assert, but that kind of defeats the purpose of pausing my code, if the case has to do with what I am reading/writing to the VBE.
To my mind, the easiest solution would be to msgbox TheUnexpectedResultFromMyExpression, but I have no idea how to call that. The second easiest solution appears to be to have full and complete prescience of what my users may or may not do, as well as when and how they may do it. I have been working on that too, so if you don't know how to return the value, then maybe you have some tips on omniscience.
I know that I, in the vase majority of cases, could simply copy the expression itself to a msgbox ... inside case else, but I happen to be working with a case of a decision tree based upon the return to setting an object, and I am not interested in doing that twice. Another option might be to just myVariable=<expression> and select case myVariable instead of select case <expression>, and then always debug.print myVariable before every select case, but my log is already so busy, doing that in a larger project would mean I have to buy another monitor, and I am struggling with groceries right now.
Asking here seems easier. Thanks.
EDIT:
For those that seemed to have a hard time understanding what I am trying to ask, I boiled the code down as simply as I could. Obviously the below isn't super useful, but you get the idea.
Select Case Forms("Form1").Module.CreateEventProc("Click", Forms("Form1").Controls("label0").Name)
Case 1
Debug.Print "line1"
Case 2
Debug.Print "line2"
Case Else
Debug.Print Forms("Form1").Module.CreateEventProc("Click", Forms("Form1").Controls("label0").Name)
End Select
When my Case Else statement runs, it may print the value of the expression (the workaround I mentioned) in the immediate window, and I know I could do the same with a msgbox or variant or whatever, but it runs the code again. And yes, as I mentioned above already, I could (in this case) just assign the value to a long and then run the Select Case on the long, but that option doesn't solve the problem in my application. And lest this become a conversation where we debate the merits of using VBE objects, or tries to get me to ask a different question of why I get unexpected values (I am not, I am trying to plan for clean debugging during runtime), or someone asking me why I can't just make the code simpler and easier to use instead of tens of thousands of lines of code that write another thousand+ lines of code, it is because I have a client. And they pay for what they want.
So, back to original question, all I want is to know how to return the value from the select case expression. If you are a superhero, and can get code to pause after the VBE is called, then by all means answer that question instead or in addition to.
The answer is: you can't.
Sorry, no source, except multiple descriptions of Select Case, e.g. MSDN, which would mention it, if this functionality existed.
It is a rather unusual question, that's one reason for the confusion in the comments. You are looking for a "meta" variable or method, like ##IDENTITY in T-SQL. But this doesn't exist for the VBA Select Case.
And the reason why it isn't needed: you have complete control over the testexpression in the Select part. The usual way, and I actually consider this good programming practice, is to always assign any sort of complex expression or method call (like CreateEventProc) to a variable, and then use this variable for Select Case.
So
LineNr = Forms("Form1").Module.CreateEventProc("Click", Forms("Form1").Controls("label0").Name)
Select Case LineNr
Case <expected values>
' do something useful
Case Else
Debug.Print "Whoa, unexpected LineNr: " & LineNr
End Select
is really the and the only solution.
I just wrote this maybe itll help?
Private Sub mystuff()
Dim stuff As String
Select Case stuff
Case Is = "Mine"
stuff = "yours "
Case Is = "Not yours"
stuff = "his "
Case Else
stuff = "Hers"
End Select
debug.print "stuff"; stuff
End Sub

Evaluate method to get result for notes web view

I am using evaluate function in lotusscript to get a value of certain expression.
The formula is working fine when kept in the column of a view, but as soon as it is passed in evaluate, it is throwing error as "Error in evaluate macro", might be I am using wrong suntax.
Set Eval= Evaluate({#Text(#If(#Member(#Subset(txtRejectedApprovers;-1);txtApprover1:txtApprover2:txtApprover3:txtApprover4)-#Member(#Name([CN];txtApprovedApprovers[n]);txtApprover1:txtApprover2:txtApprover3:txtApprover4)>0;"1";"0")))},foundDoc)
txtApprover1 and other fields are coming from foundDoc document.
First thing. You shouldn't use such complex evaluate statement because if there are errors or unexpected results its very difficult to find the reason.
I think your error is one bracket to much at the end of your statement. Here is the code which doesn't return the error:
Set Eval= Evaluate({#Text(#If(#Member(#Subset(txtRejectedApprovers;-1);txtApprover1:txtApprover2:txtApprover3:txtApprover4)-#Member(#Name([CN];txtApprovedApprovers[n]);txtApprover1:txtApprover2:txtApprover3:txtApprover4)>0;"1";"0"))},foundDoc)

VBA Excel - Macscript causing problems on windows when using IIF

I'm creating a macro that opens a file that everyone has on their computer and in order to do so must know the person's username / work ID.
To get the person's work ID I've tried using the following:
sso = IIf(InStr(Application.OperatingSystem, "Windows") = 1, Environ("UserName"), _
'MacScript("(user name as string)"))
Running this on windows returns an error because of the Macscript (I think) and I'd assume the same would happen vice versa, even though the error part of the IIF is never actually accessed I'm guessing seeing as the whole line is executed this is why there is a problem, thus On Error Resume Next would not really help here.
I know this can be easily overcome by just using an if and else statement but I just want to know if I'm right / why this problem occurs and if there are any other more sophisticated ways of achieving what I want.
Thanks
The IIF function evaluates both the true and false parts, or rather it attempts to do so. There is no short-circuit. Your assumption about why it's failing (and also that you can't use an OERN) is correct. You may take a look at conditional compilation logic, if certain parts of your code will not compile on Windows (or Mac, respectively).
http://msdn.microsoft.com/en-us/library/aa240847(v=vs.60).aspx

modx - getPage - [[+pageNav]] Placeholder always has a value

I try to hide the getPage [[+pageNav]] Placeholder if there is no pagination. But I can't do the following.
[[!+pageNav:notempty=`<ul class="overview__pagination">[[!+pageNav]]</ul>`]]
Does someone know how I can hide the element with an apropriate output filter? (without own extra snippet). I also tried the following and some other (not likely to work variations).
[[!+pageNav:isnot=``:then=`<ul class="overview__pagination">[[!+pageNav]]</ul>`]]`
Are you calling that code in a chunk that is cached?
Otherwise i've experienced this aswell and it seems custom placeholders sometimes behave that way, it's probably due to the fact that they actually have some unprocessed value during the IF computation but when it's actually output you see nothing. Or that the value is somehow "null" instead of "" while modx output filter might do a strict comparison.
If you're not calling it in a cached chunk or part of code, i suggest first trying with another getPage placeholder such as pageCount or total.
Like:
[[!+pageCount:gt=`1`:then=`<ul class="overview__pagination">[[!+page.nav]]</ul>`]]
If that still doesn't work, a last resort in the form of a simple snippet will always solve it, like:
[[!outputPagination? &total=`[[+total]]` &limit=`XX` &output=`<ul class="overview__pagination">[[!+page.nav]]</ul>`]]
In snippet:
if ($total > $limit) {
return $output;
}
Shouldn't it be...
[[!+page.nav:notempty=`<ul class="overview__pagination">[[!+page.nav]]</ul>`]]
Well, there is a much more easier way to do it than in the first answer. It's like TheMistaC says, even if my answer is a lot easier:
[[!+page.nav:notempty=`
[[!+page.nav]]
`]]
I use it to display a list of articles with getResources, so I know this works fine.

Resources