VB line of code inquiry, filed = (variable = 0)

66 Views Asked by At

I am working with our CRM program and coding some stuff into the system. I kind of get the basics, but I am not fully familiar with it so I am stuck trying to understand what this line means and what it actually does. Any help is truly appreciated.

Code looks something like this:

txtField.ReadOnly = (intOption = 0)
SetControlColor(txtField)

I know what intOption is, and I know what the outcome of the code is doing, but I don't understand what this line truly does...

1

There are 1 best solutions below

0
On

Tear it apart. Read it from right to left. This part of the line:

(intOption = 0)

is comparing whether intOption equals 0. This will return True or False. That True or False value will then be assigned to txtField.ReadOnly, which is a Boolean type.

It is equivalent to this code:

If intOption = 0 Then
    txtField.ReadOnly = True
Else
    txtField.ReadOnly = False
End If

As you can see, it is easier to write all that code into one line.