example using boolean

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I understand how boolean variables work. However, I am looking for a simple code that use boolean to understand it better or to see how it is used really. I created the code below but to me that does not make a lot of sense, I have seen this example on the net.

Code:
Sub myboolean()
    Dim result As Boolean
    Dim x As Integer
    x = InputBox("enter number")
    result = x > 50
    MsgBox result
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
(x > 50) is a condition. It's either TRUE or FALSE. So your line that says:

Code:
result = x > 50

is essentially a shortcut way of saying this:

Code:
If x > 50 Then
    result = TRUE
Else
    result = FALSE
EndIf

Or perhaps another way to look at it:


Code:
If x > 50 Then
   ..do something..
Endif

If TRUE Then
    ..do something..
Endif

Both of those If's will do the same thing (if x >50), so therefore the x > 50 and TRUE are equivalent. Does this make any more sense?
 
Upvote 0

Forum statistics

Threads
1,223,957
Messages
6,175,622
Members
452,661
Latest member
Nonhle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top