none
Struggling with IF statement

    Question

  • I can't get an IF statement to evaluate and process.  -stumped.

    Started with this:

    <%if 8 > (rs("[now list]")) { %>
    <p>This is a Sheriff Sale. Validate all information yourself.</p>
    <% } else { %>
    <p>This is not a Sheriff Sale. </p<
    <% } %> 

    this does not work.

    Regarding [now list] I tried all sorts of different configurations utilizing the rs in the statement, various bracketing using all I could think of with () and {}; as well as rs, and rs! and =rs! and so forth. 

    I don't understand how the statement can be evaluated all the way to the "then", the initial {, and then stop. I've already used an hour this morning "experimenting" 

    I'm wondering if this might work instead?  (cleaning out some <% info?)

    <%if 8 > (rs("[now list]")) { 
    <p>This is a Sheriff Sale. Validate all information yourself.</p>
    } else { 
    <p>This is not a Sheriff Sale. </p<
    } %> 

    this returned this error on the page:
    Microsoft VBScript compilation error '800a0408'
    Invalid character
    /res/details01f.asp, line 127

    if 8 > (rs("[now list]")) {
    ---------------------

    with the ^ pointing underneath the { on line one.  No success getting past the first {

    I am stumped.  The field "now list" is retrieved from an Access table using an SQL statement.  In that statement, it is shown as [now list] with brackets and space between words. [now list] has a default value of 1, so it is never 0 or blank. 

    This process is being "injected" into a webpage; a page created in FrontPage2000 and saved as an .ASP page. The page functioned as intended before putting this "IF snippet" into it. With the snippet, it shuts the page down with the error code. 

    All I want to do is compare [now list] as < or > a given number, in this case 8; and based upon whoever is <>, If [now list ] >8 then return 1 sentence or if [now list] <8  return a different sentence.  That's it. 

    What am I doing wrong here?  A new set of eyeballs on this would be greatly appreciated. 

    Friday, March 17, 2017 2:29 PM

Answers

  • Thanks very much Kathy!  I appreciate your help.  Here is what ended up working in my specific case:

    <% if (rs.Fields("now list")>5) then %>
    <p>This is the true response.</p>
    <% else %>
    <p>This is the false response. </p>
    <% end if %>

    I had to compare a field from an Access 2000 table that was retrieved in an SQL query. I know using 2 word names is bad idea, but I did and it was a very long time ago. It was extracted in the SQL statement as [now list] ; complete with the brackets which also added unnecessary complexity and consternation for me.  With your help, and the help of another forum outside of Microsoft, I was able to achieve the result I needed.  Thank you very, and I mean VERY much!  Have a great weekend - I know I will.   :-)

    Friday, March 17, 2017 10:15 PM

All replies

  • Well, the first thing you're doing wrong is trying to use ASP in EW. EW doesn't grok ASP, doesn't provide Intellisense for it, and the built-in server does not parse nor execute it. To test SAP code, you will have to either install/activate IIS locally and configure it for ASP support, or test it on your remote server, if it is configured for ASP support.

    After you get yourself a properly configured test bed, then you can start working on issues with your code's logic.

    cheers,
    scott


    Please remember to "Mark as Answer" the responses that resolved your issue. It is common courtesy to recognize those who have helped you, and it also makes it easier for visitors to find the resolution later.

    Friday, March 17, 2017 6:39 PM
  • Actually, the best I thought I could do was say "EW" because it was a replacement for the product I am using which is FrontPage2000; which is not an option here. 

    As such, the rest of your answer might apply to someone somewhere, but certainly not to my situation.  All I want to do is evaluate a dang IF statement.

    How dang hard can this be?  It sure as heck SHOULDN'T be hard, considering I've been using them since 1987 when spreadsheets were in their infancy. 

    IF test some sort of condition

    if true do this

    if false do this

    end

    Thanks for looking.

    Friday, March 17, 2017 6:54 PM
  • Classic ASP syntax is not an EW question. If you have questions about it, you should try an ASP forum, which are pretty hard to find now since ASP is mostly used only in legacy applications, or an ASP reference book or online document.

    Now, since I happen to have a classic ASP site in hand (which I will shortly be converting to MVC), I can tell you that the ASP syntax I see is:

    <%

    if CONDITION then DO SOMETHING else DO SOMETHING ELSE

    end if

    %>

    No curly brackets anywhere.

    In particular, if what you want to do is conditionally display html, that would be either done with Response.Write or just put the markup outside the <% %>:  E.g.:

    <% if CONDITION then %>

    <p>Your html here </p>

    <% else %>

    <p>Your other choice here <p>

    <% end if %>

    Give that a try.


    Kathleen Wilber
    BrightWillow - Asp.Net Applications



    • Edited by KathyW2 Friday, March 17, 2017 7:18 PM
    Friday, March 17, 2017 7:05 PM
  • Actually, the best I thought I could do was say "EW" because it was a replacement for the product I am using which is FrontPage2000; which is not an option here.

    In other words, you duplicitously came to an EW forum, where ASP is not supported (and ordinarily not discussed), and asked an off-topic question without revealing that you were not using the tool to which the forum is dedicated, rather than taking the minimal time to simply google and find an ASP forum, right?

    Lovely.

    FWIW, your spreadsheet experience has precisely zip point doodoo to do with VBScript, as is evidenced by your ignorance of the proper syntax. In programming contexts, syntax matters. In VBScript, the proper syntax is If...Then...Else...End If. Notice anything missing from your conditional statement?

    You are fortunate that Kathy still has some old ASP projects lying around, and took the time to point out to you your syntax errors. For your own benefit, please consider reviewing ASP questions at a source like the free https://www.w3schools.com/asp/asp_introduction.asp, which provides a complete ASP course, along with an excellent reference for individual elements of ASP such as conditional statements.

    cheers,
    scott


    Please remember to "Mark as Answer" the responses that resolved your issue. It is common courtesy to recognize those who have helped you, and it also makes it easier for visitors to find the resolution later.

    • Edited by paladyn Friday, March 17, 2017 9:38 PM
    Friday, March 17, 2017 9:35 PM
  • Thanks very much Kathy!  I appreciate your help.  Here is what ended up working in my specific case:

    <% if (rs.Fields("now list")>5) then %>
    <p>This is the true response.</p>
    <% else %>
    <p>This is the false response. </p>
    <% end if %>

    I had to compare a field from an Access 2000 table that was retrieved in an SQL query. I know using 2 word names is bad idea, but I did and it was a very long time ago. It was extracted in the SQL statement as [now list] ; complete with the brackets which also added unnecessary complexity and consternation for me.  With your help, and the help of another forum outside of Microsoft, I was able to achieve the result I needed.  Thank you very, and I mean VERY much!  Have a great weekend - I know I will.   :-)

    Friday, March 17, 2017 10:15 PM
  • You are welcome. Now, it would be helpful for future visitors to the forum if you marked the correct post as the answer: the one or ones that helped you.

    Kathleen Wilber
    BrightWillow - Asp.Net Applications

    Friday, March 17, 2017 10:25 PM
  • By the way, the "old Asp project" I have is in fact a current website (TahitiLegends.com) written several years ago by someone who does not want to support it going forward.  I'm now supporting changes to its sister site (Tahiti.com) which was written in MVC by the same original coder, and will be converting the classic ASP one to MVC.  This particular job manages to skip completely over asp.net web forms ... which is the technology I've done most of my work in.

    Kathleen Wilber
    BrightWillow - Asp.Net Applications

    Saturday, March 18, 2017 8:02 AM