Results 1 to 4 of 4

Thread: [RESOLVED] How to use IF NOT

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    91

    Resolved [RESOLVED] How to use IF NOT

    Can anyone tell how to use the If Not so I don't have to use an exit sub to get out of the procedure

    This works but I want to remove the exit sub
    VB Code:
    1. Public Sub FillLabels()
    2.     If Not (objrec.BOF = True) Or (objrec.EOF = True) Then
    3.         Exit Sub
    4.     End If
    5.     txtJobDescription = objrec.Fields("Job_Description").Value & " "
    6.     txtSubTotal.Text = Format$(objrec.Fields("Sub_Total").Value & " ", "Currency")
    7.     lblAddVAT = Format$(objrec.Fields("VAT").Value & " ", "Currency")
    8.     lblNewTotal = Format$(objrec.Fields("Total").Value & " ", "Currency")
    9. End Sub
    here is the code for the navigation
    VB Code:
    1. Public Sub Forward()
    2.     'If the recordset is not at the end of file....
    3.     If objrec.EOF = False Then
    4.         '....Move to the next record
    5.         objrec.MoveNext
    6.             'Call the Select_Case procedure to refill the labels with the next record
    7.             Select_Case
    8.         If objrec.EOF Then
    9.             'This will prevent the user from moving to
    10.             'the EOF Marker if he or she is on the last
    11.             'record.
    12.             objrec.MoveLast
    13.         End If
    14.     Else
    15.         If objrec.BOF Then
    16.             Exit Sub
    17.         Else
    18.             objrec.MoveNext
    19.         End If
    20.     End If
    21. End Sub

    I have a forward and back navigation buttons on my toolbar and use it to move forward and back records. I have tried using IF NOT around the booleans but When it reaches the last record it will crash saying 'Either BOF or EOF is True.......'
    I want to be able to remove the Exit Sub becuase I have been told it's lazy programming to exit a sub routine

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How to use IF NOT

    Pure logic... simply reverse the process

    VB Code:
    1. Public Sub FillLabels()
    2.     If (objrec.BOF = True) Or (objrec.EOF = True) Then
    3.         txtJobDescription = objrec.Fields("Job_Description").Value & " "
    4.         txtSubTotal.Text = Format$(objrec.Fields("Sub_Total").Value & " ", "Currency")
    5.         lblAddVAT = Format$(objrec.Fields("VAT").Value & " ", "Currency")
    6.         lblNewTotal = Format$(objrec.Fields("Total").Value & " ", "Currency")
    7.     End If
    8. End Sub

    VB Code:
    1. Public Sub Forward()
    2.     'If the recordset is not at the end of file....
    3.     If objrec.EOF = False Then
    4.         '....Move to the next record
    5.         objrec.MoveNext
    6.             'Call the Select_Case procedure to refill the labels with the next record
    7.             Select_Case
    8.         If objrec.EOF Then
    9.             'This will prevent the user from moving to
    10.             'the EOF Marker if he or she is on the last
    11.             'record.
    12.             objrec.MoveLast
    13.         End If
    14.     Else
    15.         If Not objrec.BOF Then
    16.             objrec.MoveNext
    17.         End If
    18.     End If
    19. End Sub

    In the second one, you are exiting the sub anyway when the If's finish. So you don't need Exit Sub.

  3. #3
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: How to use IF NOT

    you can use the not like this

    VB Code:
    1. Public Sub FillLabels()
    2.     If Not (objrec.BOF = True Or objrec.EOF = True) Then
    3.         txtJobDescription = objrec.Fields("Job_Description").Value & " "
    4.         txtSubTotal.Text = Format$(objrec.Fields("Sub_Total").Value & " ", "Currency")
    5.         lblAddVAT = Format$(objrec.Fields("VAT").Value & " ", "Currency")
    6.         lblNewTotal = Format$(objrec.Fields("Total").Value & " ", "Currency")
    7.     End If
    8. End Sub

    grouping the conditions is more important
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    91

    Re: How to use IF NOT

    Many thanks to both of you for helping me out woth this problem.

    The problem is now fixed

Posting Permissions

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



Click Here to Expand Forum to Full Width