Consulting

Results 1 to 2 of 2

Thread: IF statement, difference between IF NOT ...False Vs IF TRUE

  1. #1

    IF statement, difference between IF NOT ...False Vs IF TRUE

    Hi,

    I want to clarify VBA IF statement. What is the difference between them:
    if x=true then
    'do something at true
    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 Then
    ' do something when objMyRecordset.EOF is not true (Implicitly means False)
    End if

    If objMyRecordset.EOF=False Then
    ' do something when objMyRecordset.EOF returns False (implicitly means not True)
    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master xld's Avatar
    Joined
    Apr 2005
    Posts
    25,091
    Location
    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
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •