Solved

paren or not paren

Posted on 2000-03-30
12
212 Views
Last Modified: 2010-05-02
Can anyone tell me the difference between:
If (x = 0) Then

and

If x = 0 Then

someone told me that there was a difference. If there is, then when would you use one over the other?
0
Comment
Question by:buyer
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 1

Expert Comment

by:riduce
ID: 2670756
here is you're answer
y + x * 8 = 80
y + (x * 8) = 52

0
 
LVL 1

Expert Comment

by:riduce
ID: 2670760
here is you're answer
y + x * 8 = 80
y + (x * 8) = 52

0
 
LVL 1

Expert Comment

by:riduce
ID: 2670768
here is you're answer
y + x * 8 = 80
y + (x * 8) = 52

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 1

Expert Comment

by:riduce
ID: 2670776
oops sorry for the tripple message
0
 
LVL 7

Expert Comment

by:BarryTice
ID: 2670783
The only difference I'm aware of is ease of reading.

There could be less certainty with something like the following:

If X = 0 And Y = 1 Then

and

If (X = 0) And (Y = 1) Then

Without the parenthesis, VB could interpret as

If X = (0 And Y)

and get results you aren't expecting. (I don't honestly know how VB responds in this case. I always use parenthesis in these kinds of cases to avoid ambiguity. But, then again, I'm one of those bastards who always comments my code, too.)

With the simple expression in your example, though, there shouldn't be a functional difference, I don't think.

-- b.r.t.
0
 

Author Comment

by:buyer
ID: 2670792
Yeah, I know about that. That doesnt answer the question for comparison though. Im using x = 0 and (x = 0) in an if then else statement.
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2670803
There are two reasons for this.

1. if (X=0)=Boolean
 
For example:
   List1.enabled=(x=0)

2. if you take 5+2+7-3+10=?
 
   a.(5+2)+(7-3)+10=21
   b. 5+(2+7)-(3+10)=1
 
The grouping is critical.

Good luck!!
       
0
 

Author Comment

by:buyer
ID: 2670821
Again DrDelphi - you are explaining addition. Yeah, I know about this. I am not adding, subtracting, etc anything. I am comparing.
If (x = 0) Then
....
and

If x = 0 Then
....
What is the difference here?
0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 50 total points
ID: 2670831
x=0 is a mathematical expression

(x=0) is treated as a codition to either be met or not, hence a boolean. I thought I made that clear last time.

0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2670841
also, in this particular case there is no real difference.... but for giggles try this:

x=5

debug.print (x=0)


0
 
LVL 4

Expert Comment

by:gcs001
ID: 2670871
Funny enough debug.print x = 0 also displays False, so it seems that both x = 0 and (x = 0) result in a Boolean value depending of course on the context it's used in.
0
 

Author Comment

by:buyer
ID: 2670882
Thanks
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

803 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