• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1074
  • Last Modified:

ASP IF statement to check TWO conditions

How to use an if statement two check to conditions

Like:

IF "a" = "a" AND "b" = "b" then
do some thing
else
do some thing else
end if

this syntax must not be correct because I can't get it to work.
0
quest_capital
Asked:
quest_capital
2 Solutions
 
HilaireCommented:
Maybe a rpoble mwith operator precedence / imlpicit conversions

Try to enclose both condition between parens

IF ("a" = "a") AND ("b" = "b") then
do some thing
else
do some thing else
end if

0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Nope, that's correct.  What are you trying to get it to evaluate and what's happening?
0
 
sciber_dudeCommented:
you have to check the conditions against variables. like this..

Dim a, b
' Initializing the variables.

a = "a"
b = "b"

IF a = "a" AND b = "b" then
      do some thing
else
      do some thing else
end if
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ColosseoCommented:
Hi

The syntax you are using appears correct to me... perhaps one of the clauses in your actual code is returning false?

It could possibly be a case mismatch, you could try using the ucase or lcase function around all the strings to make sure they are the same

IF lcase("a") = lcase("a") AND lcase("b") = lcase("b") then

Cheers

Scott

0
 
masirofCommented:
Keep in mind datatypes.. numeric, string... etc..
0
 
quest_capitalAuthor Commented:
I thing I know the problem?

Lets say:
filen = name2
sp_id = 2

I am pulling a record set
sqltext = "SELECT * FROM speech_files WHERE  filen = '"& filen &"'"
set rst = cnn.Execute(sqltext)

Let say this is coming out of the rst:

sp_id  filen
  1      name1
  1      name2
  2      name2

and I have an if stament

if filen = rsta("filen") AND sp_id = rsta("speech_id") then
sqltext1 = "UPDATE speech_files SET url = '" & url & "',ext = '" & ext & "',sizef = '" & sizf & "' WHERE filen = '"& filen &"'"
set rst1 = cnn.Execute(sqltext1)
else
sqltext = "INSERT INTO speech_files (speech_id,filen,url,ext,sizef) VALUES ('"& sp_id & "','" & filen & "','" & url & "','" & ext & "','" & sizf & "')"
set rst = cnn.Execute(sqltext)
end if

the rst is only pulling this record:
1  name2

and not

2  name2

So how can I say

select filen = name2 with sp_id = 1 as long as it is so where in the record set
0
 
justinbilligCommented:
"you have to check the conditions against variables. like this.. "

no you don't you can compare to strings to each other
0
 
sciber_dudeCommented:
@ justinbillig -
I agree with what you say. But look at the author's code. you USUALLY check the conditions against variables.
Are you ok with that statement?

@ quest_capital -

I guess u are getting only one record as you are not looping the RS.

Are you?

:) SD
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
please close your older questions:

1 09/01/2004 500 xmldom to parse an xml page  Open Active Server Pages (ASP)
2 09/02/2004 125 Want update to the new ASP page.  Open Active Server Pages (ASP)
3 09/07/2004 500 Automatically download xml page every ho...  Open XML
4 09/16/2004 250 Lock a page in use  Open Active Server Pages (ASP)
5 11/05/2004 250 Combined to form validation scripts  Open JavaScript
6 11/09/2004 250 ASP IF statement to check TWO conditions  Open Active Server Pages (ASP)
7 08/03/2004 250 UPDATE a field with all the records of a...  Open Microsoft Access
0
 
quest_capitalAuthor Commented:
I getting the first record where filen = '"&filen&"'

and not the record where I want filen = '"&filen&"' AND sp_id = rsta("speech_id")
0
 
sciber_dudeCommented:
do until rsta.EOF
    if filen = rsta("filen") AND sp_id = rsta("speech_id") then
        sqltext1 = "UPDATE speech_files SET url = '" & url & "',ext = '" & ext & "',sizef = '" & sizf & "' WHERE filen = '"& filen &"'"
        set rst1 = cnn.Execute(sqltext1)
    else
        sqltext = "INSERT INTO speech_files (speech_id,filen,url,ext,sizef) VALUES ('"& sp_id & "','" & filen & "','" & url & "','" & ext & "','" & sizf & "')"
        set rst = cnn.Execute(sqltext)
    end if
rsta.movenext
loop
0
 
quest_capitalAuthor Commented:
The_Big_Daddy
Do I close those questions even if I didn't get the right answer?
I don't want to give anyone answers that have not been answer correctly.

But If you want me to close them out I will.
0
 
quest_capitalAuthor Commented:
sciber_dude
I think that you are on to somthing but the only thing is that when it loop through the rsta if the condition is false it will insert the record the multiple times.
0
 
quest_capitalAuthor Commented:
sciber_dude
can you end a loop after the ELSE statement?
0
 
sciber_dudeCommented:
quest_capital -
If you have questions that are open and u havent received any good answers, please post a comment at Community Support at http://www.experts-exchange.com/Community_Support/ and request them to close the question. Make sure you mention which question(s) to close

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

filen = "name2"
sp_id = 2


sqltext = "SELECT * FROM speech_files WHERE  filen = '"& filen &"'"
set rsta = cnn.Execute(sqltext)                ' <<< updated rst to rsta

do until rsta.EOF
     if sp_id = rsta("speech_id") then        ' <<< read comment below.
          sqltext1 = "UPDATE speech_files SET url = '" & url & "',ext = '" & ext & "',sizef = '" & sizf & "' " &_
               "WHERE filen = '"& filen &"'"
          set rst1 = cnn.Execute(sqltext1)
     else
          sqltext2 = "INSERT INTO speech_files (speech_id,filen,url,ext,sizef) " &_
               "VALUES ('"& sp_id & "','" & filen & "','" & url & "','" & ext & "','" & sizf & "')"
          set rst2 = cnn.Execute(sqltext2)
     end if
rsta.movenext
loop

Comment: Since your sqltext is already checking for this condition [WHERE  filen = '"& filen &"'"], you dont need double checking here.

>> If the condition is false it will insert the record the multiple times
It depends on what you want to do. There wont be too many records coz you are restricting the initial no. of records u are picking up coz of the WHERE statement in the sqltext
0
 
sciber_dudeCommented:
This is the way you think in terms of using loop and an if statement. you can nest them within each other.

do ...
    If .. then
    {else ...}
    end if
  Increment
loop

This is also correct [you dont need to have an else]:
do ...
    If .. then
    end if
  Increment
loop

This is also correct:
If .. then
    do ...
       Increment
    loop
{else
    do ...
       Increment
    loop
}
end if


This is wrong:<<<<<<<<<<<<<<<
do ...
    If .. then
  Increment
loop
    {else ...}
    end if

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now