example using boolean

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,640
Office Version
  1. 365
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
 

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
10,624
(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?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,734
Messages
5,597,807
Members
414,177
Latest member
RezaAkhund

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
Top