• 0

Exitting a vbscript based on msgbox result


Question

folks;

I'm really new at vbscripting for windows but have managed to work out some of my issues.

I'm stuck on closing the script early if a user clicks the cancel button in a msgbox.

I can get the result code but even using wscript.quit the script continues to run when I click cancel in the msgbox box.

Here's a snippet of the script I am working on

On error resume next

MsgBox "This utility will close ALL instances of Microsoft Access.", 1+32

If result = 2 then wscript.quit

For each Process in GetObject("winmgmts:").InstancesOf ("win32_process")

If ucase(Process.name) = ucase("msaccess.exe") Then

Process.Terminate

End IF

Next

Msgbox "Time to continue with other steps"

The idea is to close the script if the Cancel button is pressed or continue if OK is pressed.

Appologies for the rookie question but I can't find any guidance on this .

Thanks

5 answers to this question

Recommended Posts

  • 0

like this...

result = MsgBox("This utility will close ALL instances of Microsoft Access.", vbOkCancel) 
if(result=vbCancel)Then ' or result=2
		  wscript.echo "you chose 'cancel'.  exiting script."
		  wscript.quit
else
		  WScript.Echo "you chose 'ok'."
end If

you either add your constant values together for the display icon or you use the intrinsic name (vbOkCancel, etc.)

for instance, your "1+32" displays the ok\cancel options with the question mark image in the dialog box. not sure if that's what you were aiming for...

here's a list of the contants...

msgbox constants

  • 0

Thanks pacifica. That helps a ton.

More assistance if possible.

Once I have determined if the user wants to continue, there are a few additional steps that will follow. Each step has the potential to error, present an error message, user clicks OK and the script quits.

What's the best way to structure this.

Here is some more of the script.

'Check to see if USERFOLDER exists

'if not then create the folder

'yes then delete all files in the folder

If NOT objFSO.FolderExists(strUSERFOLDER) then objFSO.CreateFolder(strUSERFOLDER) else objFSO.DeleteFile(strUSERFOLDER & strALLFILES)

numerr = Err.number

abouterr = Err.description

If numerr <> 0 Then MsgBox "Please contact HELPDESK and provide the following information" &vbCRLF&vbCRLF& "Error number: " &numerr&vbCRLF& "Description: " &abouterr&vbCRLF& "data: " &strUSERFOLDER, 0+16, "ERROR with User folder"

Err.Clear

'COPY CHIP.MDE to local system

objFSO.CopyFile strSRCFOLDER&strCHIPMDE, strUSERFOLDER

numerr = Err.number

abouterr = Err.description

If numerr <> 0 Then MsgBox "Please contact HELPDESK and provide the following information" &vbCRLF&vbCRLF& "Error number: " &numerr&vbCRLF& "Description: " &abouterr&vbCRLF& "Data: " &vbCRLF& " " &strSRCFOLDER&strCHIPMDE &vbCRLF& " " &strUSERFOLDER&strCHIPMDE, 0+16, "ERROR copying CHIP.MDE"

Err.clear

If the first section fails, I want the script to exit when the user presses OK, ditto with the second section. there are 3 more sections after this.

thanks again

  • 0

you could do this instead for your if statements (sorta the samething pacifica posted)

If numerr &lt;&gt; 0 then
	MsgBox "Please contact HELPDESK and provide the following information" &amp;vbCRLF&amp;vbCRLF&amp; "Error number: " &amp;numerr&amp;vbCRLF&amp; "Description: " &amp;abouterr&amp;vbCRLF&amp; "data: " &amp;strUSERFOLDER, 0+16, "ERROR with User folder"
	wscript.quit
End if

Edited by primortal
  • 0

Thanks.

Everything works the way i had originally envisioned it.

Any recommendations for learning vbScripting for Windows...good books or programs...editors (I'm using Context - it is pretty basic)

One other question, Is it possible to compile .vbs files into exe's or is it worth it?

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

    • No registered users viewing this page.
  • Posts

    • Wouldn’t it be better to disable global c states to improve latency at the cost of marginally higher heat and power usage?
    • I recently bought a brand new Intel 200 series laptop with 16GB, 512GB NVME (now 2TB) with 14 inch OLED screen for $450. Not the fastest laptop in the world, but the screen is great and laptop is small, just what I needed.
    • They forgot to include this slide: "If I get a Mac I won't be able to play games, therefore I will have more time for my studies."
    • It’s not desperation, it’s marketing. Companies do that…
    • Some AMD Ryzen users can get free Windows performance boost with this simple system tweak by Sayan Sen AMD understands that there is a lot of demand for its X3D processors and for good reason too, since they offer some of the best gaming experiences. As such, the company plans to launch a new 6-core Ryzen 5 9600X3D for those who may not want to spend top dollar on a 9800X3D. What makes X3D special is the densely packed last level cache (LLC) wherein the L3 (level 3) cache is 3D die-stacked such that there is a whole lot of it that the cores can access on demand all within the smallest footprint. This is said to help with latency especially, and games happen to be quite sensitive to it since they are a mixed workload and so there is a lot of to-and-fro. However, despite that fact, users have noticed micro-stuttering and freezes on Ryzen X3D CPUs. Although there is no official fix, some of the affected users have managed to resolve the issues by tweaking a motherboard setting. The tweak is related to a setting called "GLOBAL C-STATE CONTROL" (it may be called something else by your motherboard vendor) and changing it to 'Enabled' from 'Auto' could fix stuttering and lag-related issues in games. If you are not familiar with them, Processor Power Management is done through Advanced Configuration and Power Interface (ACPI) P-states or C-states. While P-states or performance states handle CPU voltage-frequency scaling, C-states deal with CPU sleep states so that some of the CPU functions, which are not necessary at that moment, are disabled. The P-states and C-states work together to make the processor run more efficiently. It helps the OS and apps determine which cores can be parked. The Global C-state control setting helps users manage not only the DF and CPU core C-states but also the I/O C-states too. For those wondering, DF here refers to Data Fabric or AMD's high bandwidth Infinity Fabric interconnect between CPUs, GPUs, and more, on AMD systems. By default, this is set to "Auto" which also means that it is "Enabled" by default. However, in the case of X3D parts, Auto may set this setting to "Disabled" and thus manually toggling it to "Enabled" may be necessary. X3D processors, the dual CCD (core complex die) ones especially, have their V-cache on a single CCD. If the CPPC (Collaborative Processor Performance Control), which lets an OS like Windows control the "preferred core" and clock speed boost, isn't working optimally to assign the correct gaming CCD, then this fix could well work. Global C-State Auto: Global C-State Enabled: We ran a benchmark on our Ryzen 9 9950X3D to see if toggling the settings would make a difference, and well, it didn't in the case of AIDA64. However, since this is a synthetic test that measures cache and memory exclusively, we can't definitively conclude that the fix will also not make a difference in the case of games. Another remedy for stuttering is to disable the monitoring of the "Power percent" metric on MSI Afterburner if you have it on. This has been a long-known issue and in fact can help you even if you are not using an X3D CPU. Source: Reddit (link1, link2) via YouTube
  • Recent Achievements

    • One Month Later
      DecaffKnight94 earned a badge
      One Month Later
    • Dedicated
      S.P earned a badge
      Dedicated
    • One Month Later
      adxnksd42031 earned a badge
      One Month Later
    • Rising Star
      aphanic went up a rank
      Rising Star
    • Contributor
      GravityDead went up a rank
      Contributor
  • Popular Contributors

    1. 1
      +primortal
      663
    2. 2
      ATLien_0
      260
    3. 3
      Michael Scrip
      234
    4. 4
      Steven P.
      157
    5. 5
      +FloatingFatMan
      151
  • Tell a friend

    Love Neowin? Tell a friend!