[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

paren or not paren

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
buyer
Asked:
buyer
  • 4
  • 3
  • 3
  • +2
1 Solution
 
riduceCommented:
here is you're answer
y + x * 8 = 80
y + (x * 8) = 52

0
 
riduceCommented:
here is you're answer
y + x * 8 = 80
y + (x * 8) = 52

0
 
riduceCommented:
here is you're answer
y + x * 8 = 80
y + (x * 8) = 52

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
riduceCommented:
oops sorry for the tripple message
0
 
BarryTiceCommented:
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
 
buyerAuthor Commented:
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
 
DrDelphiCommented:
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
 
buyerAuthor Commented:
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
 
DrDelphiCommented:
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
 
DrDelphiCommented:
also, in this particular case there is no real difference.... but for giggles try this:

x=5

debug.print (x=0)


0
 
gcs001Commented:
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
 
buyerAuthor Commented:
Thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now