Results 1 to 4 of 4

Thread: Prevent compilation

Threaded View

  1. #1

    Thread Starter
    Fanatic Member BrianHawley's Avatar
    Join Date
    Aug 2001
    Location
    Saudi Arabia
    Posts
    796

    Prevent compilation

    Why would you want to do this?

    I had to write and test some code to hook up to a piece of external equipment.

    To test the code when the equipment was not there, I set a variable TESTING which generated fake replies from the equipment so that the rest of the program could be tested.

    The problem? What if some idiot (i.e. me) forgot to reset the TESTING variable, compiled the program and sent it to the customer. Disaster!

    This code prevents compilation when TESTING is true.

    Another approach would have been to see if we were in the IDE and generate fake data when we were, but that would not have worked here as we sometimes needed to debug in the IDE with the equipment present.


    VB Code:
    1. Option Explicit
    2. Public TESTING As Boolean
    3. #Const TESTING = True 'Set true or false as required
    4.  
    5. Sub TestingCheck()
    6.  
    7.   'Dummy procedure which is never called.
    8.  
    9.   #If TESTING Then
    10.     Will not compile if TESTING is true
    11.     'The above line appears red in the VB6 code editor.
    12.     'That's expected because we are forcing a compile error. Don't edit it!
    13.   #End If
    14. End Sub
    15.  
    16. Public Sub Main()
    17.  
    18.   'Set a public variable so we can check it from
    19.   'anywhere in the program. (The compiler constant
    20.   'with the same name applies ONLY in the module
    21.   'in which it is declared.
    22.   #If TESTING Then
    23.     TESTING = True
    24.   #End If
    25.  
    26.   'Example of use >>>>>>>>>>>>>>>>>>>
    27.   'Dim DataFromSpacecraft As String
    28.   'If TESTING Then
    29.   '
    30.   '  'Supply dummy data for testing the application
    31.   '  DataFromSpacecraft = "Hello earth!"
    32.   '  
    33.   'Else
    34.   '
    35.   '  'Get real data
    36.   '  DataFromSpacecraft = GetDataFromSpacecraft()
    37.   '  
    38.   'End If
    39.   'Example of use >>>>>>>>>>>>>>>>>>>
    40.  
    41.  
    42. End Sub
    Last edited by BrianHawley; Aug 26th, 2005 at 03:35 AM. Reason: Added explanation
    Brian
    (Fighting with the RightToLeft bugs in VS 2005)

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