Classic VB - Why does my program give me errors running as an Exe but not in the IDE?
Does your program work fine in the IDE (where you write the code), and then fail when you compile it into an Exe file? If so, one of the items below will hopefully provide you with the solution.
Are you running code which relies on a previous piece of code, or intensive loops?
A compiled program runs faster than code in the IDE, so it is possible that code which needs to finish its work (such as copying a file) before the next line of code starts (such as opening the same file) doesn't quite get a chance to complete when your program is compiled, even though it seems to be alright in the IDE.
In situations like this it can be useful to let the operating system (Windows) catch-up with what it was supposed to be doing. There is a statement in VB which lets this happen, this statement is DoEvents; eg:
VB Code:
... Code to copy the file ...
FileCopied = True
DoEvents
'Load the file here
Open sFileName For Input as #myFileNo
...
You may also find DoEvents useful inside intensive loops, as it allows the user to press keys (or the mouse) and your program can respond to them. You will also find that your forms are re-drawn at this time, which often fails to happen if your program is busy.
Are you loading files?
If you are loading files, how are you specifying where to load them from? If you have only specified the name of the file (and not the folder it is in) then it must be in the same folder as the application is being run from (which is likely to be the same place as the application itself).
If you have specified a particular folder, be aware that this might not exist on other computers, so this could cause errors when installed on another computer. A good solution to this is to store files in the same folder as the application, and specify where to load them from by using code like in this thread.
Are you running the Exe file on another computer?
If so, did you just copy the Exe file, or did you install it properly? If you just copied it, see here for more information.