Solved

operator question

Posted on 2004-04-08
5
228 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now