Solved

operator question

Posted on 2004-04-08
5
230 Views
Last Modified: 2010-04-15
here is the code:

if ((sFileExtension != ".doc") || (sFileExtension != ".txt"))
{

}

im looking to see if uploaded file is either .doc OR .txt


the above doesnt work. how come?

0
Comment
Question by:tmueller18
  • 4
5 Comments
 
LVL 5

Accepted Solution

by:
millsoft earned 250 total points
ID: 10784768
Hi tmueller18,

Your boolean operators are wrong.

if ((sFileExtension == ".doc") || (sFileExtension == ".txt"))
{
    // extension is .DOC or .TXT
}
else
{
    // it is not
}

Cheers!
Brad
0
 
LVL 5

Expert Comment

by:millsoft
ID: 10784784
!= is "NOT EQUALS"
== is "EQUALS"

You were checking to see if the extension is "NOT .DOC or NOT .TXT".  One of those conditions will ALWAYS be true.
0
 
LVL 5

Expert Comment

by:millsoft
ID: 10784791
>One of those conditions will ALWAYS be true.

because it cannot be both at the same time.
0
 

Author Comment

by:tmueller18
ID: 10784795
thanks!
0
 
LVL 5

Expert Comment

by:millsoft
ID: 10784813
happy to help
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question