• 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

    • Stardock Start11 v2.5.3.1 by Razvan Serea Stardock Start11 is a Windows 11 customization tool designed to bring back the classic Start menu and enhance users' desktop experience. It offers a range of features and options that allow users to personalize their Start menu and taskbar to suit their preferences. Make Your Desktop Yours Take complete control of your desktop with Start11. With Windows 11, Microsoft chose form over functionality and removed many different features that were available in Windows 10. With Start11, you can customize the experience to fit your personality. Features You Expect Windows 11 removed many features that were present in Windows 10, Start11 brings them back. From the basics like returning the right-click menu on the taskbar to ungrouping of windows on the taskbar. You can also choose to have your icons centered on the taskbar with your Start menu left aligned. One Desktop to Rule Them All When working with multiple devices across various versions of Windows, Start11 can help you create a common desktop experience. Make Windows 10 look like Windows 11, or 11 look like Windows 10. Or how about making both Windows 10 and 11 look like Windows 7? The choice is yours. Remove Unwanted Content Windows 11 brings with it a new design language but also more advertisements and content that you can’t remove. Take back complete control with Start11 and remove unwanted outside content and sections of the Start menu that you don’t want to see. Start11 v2.5.3.1 changelog: All the changes from 2.52 that were went to beta but never was not released Resolves issue with not always releasing reserved space when closing an app which reserved space on the side such as Multiplicity KVM switch bar. Resolved issue with enhanced taskbar not showing status indicators correctly for some running apps Tweaks to start button sizing with vertical taskbars on Windows 11 especially when using small icon mode Tweaks to drag & drop in Win10/Win11/App/Pro/Launcher menus to make creating folders easier and less like playing chase the item around :) Resolved issue with dragging out of a group in Win11/App/Pro/Launcher menus where you couldn't always drag out of a folder to a group below Resolved issue with taskbar texture not refreshing when the OS accent colour changes. Resolved issue with on top taskbar not in enhanced mode and clicking on the taskbar search field which would make the search window appear off the top of the screen incorrectly Apps flagged as 'new' in Win10/11/App/Pro/Launcher menus will now not have the flag once run once or right clicked on Improved removal of 'new' indicator on newly installed apps so it goes away in a day or so. The apps will still be considered 'new' for the recently installed apps list Improved sorting of child items in sub folders in all apps list Start10 style search no longer shows control panel results which are duplicates of the results in the Control Panel section. Enabled sort A-Z option for Folders and Fences groups too on Win11/App/Pro/Launcher menus Small tweaks to icon & tile image loading for Universal apps on Windows 10/11/App/Pro/Launcher menus Fixes setting pins to only show on a secondary not working for some apps. Users will need to reset the show only on a secondary setting on the pins which were not working. Start11 is only $7.40 For more information about Start11, please visit Start11 website. Disclaimer: Neowin's relationship to Stardock. Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Brave 1.80.113 by Razvan Serea Brave Browser is a lightning-fast, secure web browser that stands out from the competition with its focus on privacy, security, and speed. With features like HTTPS Everywhere and built-in tracker blocking, Brave keeps your online activities safe from prying eyes. Brave is one of the safest browsers on the market today. It blocks third-party data storage. It protects from browser fingerprinting. And it does all this by default. Speed - Brave is built on Chromium, the same technology that powers Google Chrome, and is optimized for speed, providing a fast and responsive browsing experience. Brave Browser also features Brave Rewards, a system that rewards users with Basic Attention Tokens (BAT) for viewing opt-in ads. This innovative system provides an alternative revenue model for content creators and a way to support the Brave community. Brave 1.80.113 changelog: Web3 Implemented stricter wallet routing and added a 404 page for an invalid route. (#45684) Updated opt-in screen for Meld to fit on small screen sizes. (#44318) Removed the “Edit” gas button for Zcash transactions. (#45748) Fixed crash which occurred when trying to render Brave Wallet image in certain cases. (#46828) Fixed “Search” icon being cut off on the “Explore” page. (#44950) Leo Added support for automatic default model. (#45954) Added loading spinner to display when uploading image attachments. (#45889) Improved image attachment UI. (#45672) Removed Mixtral from the default Leo model list. (#46406) Fixed attachment thumbnail image not being displayed correctly. (#45916) Rewards Updated dark mode color theme for Rewards UI. (#45741) General Added the ability to open Progressive Web Apps (PWAs) in a tabbed window. (#45435) Updated extension import to warn the user to close Chrome if opened during import attempt. (#44945) Updated extension import to import both “IndexedDB” and “Local Extension Storage” when present for an extension. (#44946) Updated buttons on interstitial pages to use Brave theme. (#45666) Removed the password check box from brave://settings/importData dialog when importing from Chrome. (#46206) Fixed crash which occurred when moving a tab across monitors. (#46066) Fixed issue with “:matches-path” being used at the beginning of a filter rule. (#46220) Fixed display of long keyboard shortcuts on brave://settings/system/shortcuts. (#41873) Fixed “Toggle Vertical Tabs Expanded” keyboard shortcut not working when “Expand Vertical Tabs Independently per Window” is enabled. (#41074) Upgraded Chromium to 138.0.7204.49. (#47094) Download: Brave Browser 64-bit | 1.2 MB (Freeware) Download: Brave Browser 32-bit View: Brave Homepage | Offline Installers | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Google releases Gemma 3n, a new AI model built for mobile devices by David Uzondu Google has announced Gemma 3n, the next generation of its open AI models, and it is a significant step up from what we saw before. After a preview last month at Google I/O, the full version is now here and ready to run directly on your hardware. For those of you who are not aware, Gemma is a family of open AI models. It is different from Gemini in that it is designed for developers to download and modify, whereas Gemini is Google's closed, proprietary powerhouse. The model can now natively process inputs like images, audio, and video to generate text, a leap from just being a text-based model. It can also run on hardware with as little as 2GB of memory, and is supposedly better at tasks like coding and reasoning. Here's the full list of improvements as outlined by Google: Multimodal by design: Gemma 3n natively supports image, audio, video, and text inputs and text outputs. Optimized for on-device: Engineered with a focus on efficiency, Gemma 3n models are available in two sizes based on effective parameters: E2B and E4B. While their raw parameter count is 5B and 8B respectively, architectural innovations allow them to run with a memory footprint comparable to traditional 2B and 4B models, operating with as little as 2GB (E2B) and 3GB (E4B) of memory. Groundbreaking architecture: At its core, Gemma 3n features novel components like the MatFormer architecture for compute flexibility, Per Layer Embeddings (PLE) for memory efficiency, and new audio and MobileNet-v5 based vision encoders optimized for on-device use cases. Enhanced quality: Gemma 3n delivers quality improvements across multilinguality (supporting 140 languages for text and multimodal understanding of 35 languages), math, coding, and reasoning. The core of its efficiency is a new architecture Google calls MatFormer. Google uses the analogy of a Russian Matryoshka doll to describe it: a larger model contains a smaller, fully functional version inside. This allows a single model to run at different sizes for different tasks. And as for benchmarks, the larger E4B model is the first model under 10B parameters to break a LMArena score of 1300. The model's audio capabilities now support on-device speech-to-text and translation, using an encoder that can process speech in fine detail. The vision side of things is powered by a new encoder called MobileNet-V5, which is much faster and more efficient than its predecessor. It can process video at up to 60FPS on a Google Pixel device. If you're interested, you can start playing with it immediately as the models are available through familiar platforms like Hugging Face and Kaggle, and you can even experiment with them directly in Google AI Studio. More details can be found in the official announcement post.
    • Bitdefender Antivirus Free 27.0.53.265 by Razvan Serea Bitdefender Antivirus Free is a free antivirus software especially designed to protect your Windows PC. Quick to install and light on computer resources, it is good for gaming, image and video editing, and resource-intensive applications. Once you have installed Bitdefender Antivirus Free, your device is protected against all kinds of threats (such as malware, spyware, ransomware, exploits, botnets and trojans) and internet threats (such as hackers, phishing and spam). The app uses the Photon technology to enhance the speed and performance of the threat scanning process. It works by learning the usage patterns of your system apps to know what and when to scan, thus minimizing the impact on system performance. Many free antivirus solutions are as intrusive and resource-heavy as the viruses they’re supposed to stop. Only Bitdefender Antivirus Free is designed from the ground up to keep you safe without disrupting your workflow and focus. Free antivirus protection that stops even the fastest-evolving attacks Runs silently in the background and stays out of your way Impossibly light on CPU (will not slow down your computer) Live customer support included (unlike other free antivirus software) Bitdefender Antivirus 27.0.53.265 changelog: Updated Safepay version Fixed blank page issue when loading www.chewy.com in Safepay Fixed login errors on www.pcfinancial.ca in Safepay Fixed issue where websites failed to load with Encrypted Web Scan enabled Fixed issue where Search Advisor checkmarks appeared upside down Fixed duplicate notifications from Alert Mode Operating systems: Windows 7 with Service Pack 1, Windows 8.1, Windows 10 and Windows 11 Download: Bitdefender Antivirus Free 27.0.53.265 | 18.0 MB (Freeware) View: Bitdefender Antivirus Free Homepage | Release Notes | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • i built my own, all ya need is a pc with two network cards and i used operwrt as the os
  • Recent Achievements

    • One Month Later
      jfam earned a badge
      One Month Later
    • First Post
      TheRingmaster earned a badge
      First Post
    • Conversation Starter
      Kavin25 earned a badge
      Conversation Starter
    • One Month Later
      Leonard grant earned a badge
      One Month Later
    • Week One Done
      pcdoctorsnet earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      542
    2. 2
      ATLien_0
      200
    3. 3
      +FloatingFatMan
      176
    4. 4
      Michael Scrip
      145
    5. 5
      snowy owl
      113
  • Tell a friend

    Love Neowin? Tell a friend!