Is there anyway to automatically close a message box which has been activated by the line
MessageBox.Show("Message", "Title") after a set period of time? I just want the box to be displayed for a few seconds without the user having to click "ok" or "done" etc.
Solved! Go to Solution.
Solved by MjDeck. Go to Solution.
Solved by WCrihfield. Go to Solution.
Solved by MjDeck. Go to Solution.
Solved by vulic. Go to Solution.
Solved by MjDeck. Go to Solution.
Sorry but doesn't time out. I gather the last set of numbers in brackets controls the message type and what buttons are displayed. The number 2 seems to not do anything. I've tried various numbers in there from small to large and still no time out.
Sorry, it works for me Try
DimWshShell
BtnCodeWshShell=CreateObject("WScript.Shell")
BtnCode=WshShell.Popup("This Message will close in 3 seconds", 3, "Wait for it", 0+16)
With the latest code I just get "Object variable or With block variable not set".
With the original code you supplied the box just doesn't time out. Is it anything to do with rule behavior? My settings are as atatched.
Thanks.
Sorry that was a cut and paste error on my part on the second post,,, i checked i have the same option checked by default as well as the one below it "Fire Dependant........." . It does seem like it takes longer then 3 seconds to close but it does close.
Code should have been:
Dim WshShell, BtnCode WshShell = CreateObject("WScript.Shell") BtnCode = WshShell.Popup("This Message will close in 3 seconds", 3, "Wait for it", 0+16 )
Nope sorry still no time out. I'll have play as it may be a setting then that I need to look at.
Thanks for your help anyway.
Does anyone know the solution for time out message box ?
Here's a solution. It's based on code from https://stackoverflow.com/questions/14522540/close-a-messagebox-after-several-seconds
Imports System.Threading.Tasks
Dim timeout = 3 ' seconds Dim form As New Form() With { .Enabled = False } Task.Delay(TimeSpan.FromSeconds(timeout)).ContinueWith(Sub(t) form.Close() End Sub , TaskScheduler.FromCurrentSynchronizationContext()) MessageBox.Show(form, String.Format("Closing after {0} seconds...", timeout), "iLogic")
Using this code there is a screen flicker which was driving me crazy. So for everyone using this code to remove the flicker set {.Enabled = True}. The final code then looks like this:
Imports System.Threading.Tasks
Dim timeout = 3 ' seconds Dim form As New Form() With { .Enabled = True } Task.Delay(TimeSpan.FromSeconds(timeout)).ContinueWith(Sub(t) form.Close() End Sub , TaskScheduler.FromCurrentSynchronizationContext()) MessageBox.Show(form, String.Format("Closing after {0} seconds...", timeout), "iLogic")
Hi there,
Still flickering here, despite the 'True' setting.
Any other options?
@checkcheck_master and @vulic , here's a new version that, on my machine, stops the flashing of the Inventor window when the form closes. Please try it out.
This adds a significant amount of code. I'll keep looking for a way to do it with less.
Hi @engilic . I think I found a VBA equivalent you can use. It's done differently than the code posted above, but it worked for me when I tested it. I'm using Inventor Pro 2021.2.2 on a Windows 10 64bit system and MS Office 2019 (of it matters).
Here's what I've 'scavenged' from a few different websites.
https://www.extendoffice.com/documents/excel/3836-excel-message-box-timer-timeout.html#a1
https://www.pinvoke.net/default.aspx/user32/MessageBoxTimeout.html
VBA:
Private Declare PtrSafe Function MsgBoxTimeout _
Lib "user32" _
Alias "MessageBoxTimeoutA" ( _
ByVal hwnd As LongPtr, _
ByVal Message As String, _
ByVal Title As String, _
ByVal MsgBoxStyle As VbMsgBoxStyle, _
ByVal Language As Long, _
ByVal MillisecondsToWait As Long) _
As Long
Sub MsgWithTimeOut()
Dim oTimeOut As Long
oTimeOut = 3000
Call MsgBoxTimeout(0, "This message will self destruct after " & oTimeOut / 1000 & " seconds.", "Title", vbInformation, 0, oTimeOut)
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb:or you can Explore My CONTRIBUTIONS
Wesley Crihfield
Thanks @WCrihfield . That system function will also work in iLogic. See the attached rule.
Hello,
Works great with no flickering and does what it's supposed to do, great!
It would be absolutely perfect if it wasn't on light in the Taskbar, which makes it a bit unsettled.
So if anyone has a clear idea...