Advertisement
Java_Volume1 Miscellaneous #98744

SMALLEST CODE FOR FINDING WHETHER PROGRAM IS RUN FROM VB IDE OR COMPILED EXE

This function will return whether your program is running in Visual Basic Or it is running from the compiled EXE. This Function tries to print in the immediate window using the Debug.print method, which is available only in VB IDE and will be removed while compiling the code to EXE (or dll or ocx). The value being print using Debug.print method the raises a division by zero error and the error handler set the InIDE function to TRUE. I saw another code in Planet source code doing the same thing using a static variable and also calling the same function recursively. but this code is smaller than that.

AI

Shrnutí AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Zdrojový kód
original-source
<P>'// This function will return whether your program is running in Visual Basic Or it is running from the compiled EXE. This Function tries to print in the immediate window using the Debug.print method, which is available only in VB IDE and will be removed while compiling the code to EXE (or dll or ocx). The value being print using Debug.print method the raises a division by zero error and the error handler set the InIDE function to TRUE. </P>
<P>'// I saw another code in Planet source code doing the same thing using a static variable and also calling the same function recursively. but this code is smaller than that. </P><BR>
Private Function InIDE() As Boolean <BR>
  On Error GoTo Xit<BR>
  '//this line will execute only in VB IDE <BR>
  '//generate a division by zero error<BR>
  Debug.Print 1 / 0 <BR>
  Exit Function<BR>
Xit:<BR>
  InIDE = True<BR>
End Function<BR>
<BR>
<u>Follow-up for the comments posted regarding this posting </u>
<p>There are 2 suggestions that are posted as smaller codes than this one. <br>
True, they are lesser lines than this code, but they are less efficient (takes more time) when compiled to exe. This is because code in this article becomes virtually zero since debug.print line is eliminated and the only remaining line is 'Exit Function'. Both the other codes has some line to process. For comparing these 3 methods, I have created a test project. Download it from the files of this article.</p>
<p><u>Conclusions <u/><BR> 
<B>1. App.Log method is fastest in the VB IDE <BR>
2. Code used in this article is fastest in compiled EXE </B><BR>
It is better to have the Exe run faster. 
</p>
Původní komentáře (3)
Obnoveno z Wayback Machine