• 0

[VB6] Exit Application


Question

Hi,

I have written a VB6 application, and want to exit it if a certain condition happens. All my code gets called from the Form_load event and the form it self is never shown. I tryed using "unload me" or "unload form1" but that didnt work.

So what command would I use in VB6 to close the application?

thx in advance!

Link to comment
https://www.neowin.net/forum/topic/338146-vb6-exit-application/
Share on other sites

10 answers to this question

Recommended Posts

  • 0

Actually a Form Unload or "End" command during the Load event can cause problems and/or simply not work so...

declare a module level variable

Private mbUnload as Boolean

Sub Form_Load

If Conditions_Met Then

mbUnload = True

End if

End Sub

Sub Form_Activate

If mbUnload = True Then

Unload Me

End If

End Sub

  • 0

sweet, it worked when I put the unload me in the Form_Load. Why doesnt it work when I put it in a different sub though?

I was reading something about End before, but it sounded kinda negative and that it shouldnt be used... ?

I actually solved my problem too by using a module instead of a form and by using the exit sub command in the last sub that gets called.

still thx guys:yes:!

  • 0

<sigh> I just know I am going to regret posting this but...

"End" is the proper way to completely stop an application becuase, often, application are more than just Forms, and often do not include Forms at all. Simply doing an Unload on all Forms will not nessasarily destroy all objects (classes, references, etc).

Although Unload is not bad, it is not complete.

(please take this message as it was intended, to inform, not inflame)

Sincerely,

James Rose

New York City

  • 0
  jameswjrose said:
Simply doing an Unload on all Forms will not nessasarily destroy all objects (classes, references, etc).

586138573[/snapback]

Err, why would you regret posting it? I'm just curious--to the best of my understanding, if you unload all the forms, won't the application be closed anyway by the system? I understand that a VB app is often more than just forms. But, according to MSDN, in the documentation for the End statement:

  Quote
For normal termination of a Visual Basic program, you should unload all forms. Your program closes as soon as there are no other programs holding references to objects created from your public class modules and no code executing.

The other resources (classes, references, file handles, etc) should be reclaimed by the OS once your application terminates, right?

  • 0

See, that's the thing, the Garbage collector in VB6 runs when a function/procedure ends (as opposed to .Net which runs at rather random intervals, or you can call it specifically, but this is another issue)

Say you had an app with one Form and one Class. Say the class is created when you load the form. The class SHOULD be destroyed when you unload the form. However this is not always the case. The End command makes sure ALL references are destroyed. The reason for this importance is that if your app is started again, is is possible (however unlikely) that the previous values from the original class will still be in memory.

In fact, we had a VERY similar situation about class destruction in our app just this month. (I have NO idea how the values were not being cleared but....)

End will guarentee that all memory will be cleared.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • HWiNFO 8.28 by Razvan Serea HWiNFO (Hardware Information) is a professional hardware information and diagnostic tool supporting latest components, industry technologies and standards. It's targeted to recognize and extract the most possible amount of information about computer's hardware which makes it suitable for users searching for driver updates, computer manufactures, system integrators and technical exteperts too. Retrieved information is presented in a logical and easily understandable form and can be exported into various types of reports. System health monitoring and basic benchmarking available too. HWiNFO32 & HWiNFO64 v8.28 changelog: Extended number of temperatures monitored (for CPUs with up-to 256 cores). Added OSD independent window without title bar. Added workaround for thermal throttling stuck sticky on Arrow Lake-H. Removed taskbar entry for OSD window. Improved support of next-generation AMD server and workstation platforms. Improved I3C bus synchronization on Intel Sapphire Rapids and later CPUs. Fixed sensor monitoring on some ASRock B850 series mainboards. Added support of ITE IT8698E. Enhanced sensor monitoring on GIGABYTE Q870M D3H. Enhanced support of Intel Wildcat Lake. Added monitoring of NVIDIA PCI Express Error Counters. Added AMD Radeon AI Pro R9700. Improved support of Intel Granite Rapids. Download: HWiNFO 8.28 | 17.8 MB (Free for Non-Commercial use) Download: HWiNFO Portable View: HWiNFO Website | HWiNFO Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Helpwire doesn't support sound transfer.
    • Here's your first look at Raycast for Windows, now in beta by David Uzondu Last September, we reported that Raycast, the popular macOS command bar and launcher tool, was set to make its way to Windows in 2025. Since its launch in 2020, Raycast has quickly become the go-to app that people recommend for new Mac users due to its speed, UI, features, and plethora of extensions. People have been begging for a Windows build, and even a Linux one, for a long time. Now, the company has published a YouTube video showcasing the beta on a Microsoft Surface and explaining how you can get your hands on it today. It's all opened by pressing the default hotkey (Alt + Space). This gives you a central command bar to launch apps, run commands, and search for files. You get a lot of the core features right now, like a calculator that handles natural language queries, a full clipboard history manager, and tools for creating text snippets and quicklinks. For example, typing .pdf instantly filters for just PDF documents, and using a forward slash lets you navigate through folder paths directly. Once you find a file, pressing Ctrl + K opens a contextual action menu with options like "Show in File Explorer" or "Copy File." The included calculator is also a powerhouse, handling everything from basic math to natural language queries, like "time in Barcelona" or "days until August 12." The full clipboard history manager is a massive upgrade over the Windows default. It keeps a running log of everything you copy to your clipboard, including blocks of text, links, images, and files. You can open the clipboard history and search through every item you've copied. It also comes with a powerful filtering system. By pressing Ctrl + P, you can filter your history to show only text, images, links, or even just colors. Its Quick AI feature is also included and will be free for everyone during the beta period. That means you can ask it questions and get answers without needing a Pro subscription for now. Quick AI is built on a set of AI models, like GPT-4o mini, which maintains conversational context, allowing for natural follow-up questions, and you can browse your entire chat history. There's also an "AI search" feature, which is listed as coming soon. The most surprising part is the support for third-party extensions right out of the gate. Raycast built its reputation on an extensive library of integrations that connect it to services like Slack, YouTube, and GitHub. While some of these extensions are written for specific macOS features and are not compatible, many of the extensions are written in JavaScript, which means a huge number of them already work from day one on Windows. Image: @alvaniss1g on X As you can guess, the beta is not feature-complete. A lot of the heavy-hitting Pro features are still on the roadmap and are promised to be coming soon. This includes Cloud Sync to keep your settings consistent across machines, as well as the much-loved Raycast Notes feature. If you are a Pro user on Mac looking to switch, you may want to wait a little longer for full parity. Snippet expansion and calendar integration are also on the to-do list for future updates. Getting into the beta is a bit of a process. Access is being managed through a gradual rollout, with priority given to users who signed up for the waitlist announced last year. If you are on the list, you can expect to receive an email soon. And if you don't like the waitlist, your best bet is to find a friend who already has an invite code, as each invited user gets a few extra codes to share. Sorry, Linux users, but there is no word on your build at the moment, and we're not holding our breath.
    • We M$ and our 801 loved partner$ are having a data party !
    • Wise Disk Cleaner 11.2.4 by Razvan Serea Wise Disk Cleaner is a free disk utility designed to help you keep your disk clean by deleting any unnecessary files. Usually, these unnecessary, or junk files appear as a result of program's incomplete uninstalls, or Temporary Internet Files. It is best if these files are wiped out from time to time, since they may, at some point, use a considerable amount of space on your drives. Wise Disk Cleaner, with its intuitive and easy to use interface, helps you quickly wipe out all the junk files. Using the program is indeed easy. It also works fast when both scanning for files and deleting files. The new Wise Disk Cleaner has more advantages: improved performance, better interface and scans/cleans more thoroughly. Wise Disk Cleaner Free provides lifetime free update service and Unlimited Free technical support. The first Slimming System software Wise Disk Cleaner is the first system slimming tool, which will help you to remove Windows useless files that you don't need, such as Korean IME, Windows Sample music, videos, pictures, Installers and Uninstallers of Updates Patches etc. Wise Disk Cleaner 11.2.4 Build 844 changelog: Improved cleaning rules for WPS Office and Mozilla Firefox. Added cleaning support for Jetbrains Pycharm, Jetbrains WebStorm, Jitsi, Visual Studio Code, jv16 PowerTools, Kakao Talk, Kingo Root, Launchy, Layers of Fear, LBRY, League of Legends, Leapfrog Connect, and Leawo Prof Media. Fixed minor bugs from the previous version. Download: Wise Disk Cleaner 11.2.4 | 6.9 MB (Freeware) Download: Portable Wise Disk Cleaner 11.2.4 | 7.3 MB View: Wise Disk Cleaner Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Popular Contributors

    1. 1
      +primortal
      537
    2. 2
      ATLien_0
      205
    3. 3
      +FloatingFatMan
      167
    4. 4
      Michael Scrip
      151
    5. 5
      Som
      127
  • Tell a friend

    Love Neowin? Tell a friend!