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:
Option Explicit Public TESTING As Boolean #Const TESTING = True 'Set true or false as required Sub TestingCheck() 'Dummy procedure which is never called. #If TESTING Then Will not compile if TESTING is true 'The above line appears red in the VB6 code editor. 'That's expected because we are forcing a compile error. Don't edit it! #End If End Sub Public Sub Main() 'Set a public variable so we can check it from 'anywhere in the program. (The compiler constant 'with the same name applies ONLY in the module 'in which it is declared. #If TESTING Then TESTING = True #End If 'Example of use >>>>>>>>>>>>>>>>>>> 'Dim DataFromSpacecraft As String 'If TESTING Then ' ' 'Supply dummy data for testing the application ' DataFromSpacecraft = "Hello earth!" ' 'Else ' ' 'Get real data ' DataFromSpacecraft = GetDataFromSpacecraft() ' 'End If 'Example of use >>>>>>>>>>>>>>>>>>> End Sub




Reply With Quote