Log in

View Full Version : [SLEEPER:] IF statement, difference between IF NOT ...False Vs IF TRUE



sunnyimran
10-02-2019, 01:23 AM
Hi,

I want to clarify VBA IF statement. What is the difference between them:

if x=true
' do something at t
end if
if NOT x=false then
' do something at true
end if

Both statements will check same conditions. What is the difference among them.

To be more specific I am working on recordset object adodb and trying to find the difference between these and can't figure out

If Not objMyRecordset.EOF=True
' do something when objMyRecordset.EOF is not true (Implicitly means False
End if
objMyRecordset.EOF=False Then
I'd do something when objMyRecordset.EOF returns False (implicitly means not Then
End if

Both If's are checking same condition here too. But on numerous articles on internet I found the test condition with "If Not objMyRecordset.EOF=True Then". There must be some real reason behind this. can someone explain?

regards

Bob Phillips
10-02-2019, 01:37 AM
As you say, the net effect of both is the same.

For what it is worth, in my view, it is just a question of clarity, stating the condition that you the developer are really interested in, or the true value. So in the case of the recordset you want to know that there is another record to process, so I would use If Not EOF. In another case, say I have a loop checking a cell on each row and I just want to know when I hit a blank line, I would use If cellvalue = vbNullString.

BTW, the True and False are superfluous, you can just use


if x Then
' do something at true
end if
if NOT x Then
' do something at true
end if