Ilogic timed out message box

Ilogic timed out message box

Anonymous
Not applicable
3,653 Views
15 Replies
Message 1 of 16

Ilogic timed out message box

Anonymous
Not applicable

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.

0 Likes
3,654 Views
15 Replies
Replies (15)
Message 2 of 16

Ktomberlin
Advocate
Advocate
Dim WshShell, BtnCode
WshShell = CreateObject("WScript.Shell")
BtnCode = WshShell.Popup("Message", 2, "Title", 1 + 48)

This should work for a 2 second message window.  More info Here.  

0 Likes
Message 3 of 16

Anonymous
Not applicable

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.

0 Likes
Message 4 of 16

Ktomberlin
Advocate
Advocate

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)

0 Likes
Message 5 of 16

Anonymous
Not applicable

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.

 

 

 

 

0 Likes
Message 6 of 16

Ktomberlin
Advocate
Advocate

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 )

 

 

 

Message 7 of 16

Anonymous
Not applicable

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.

0 Likes
Message 8 of 16

marcin_bargiel
Advocate
Advocate

Does anyone know the solution for time out message box ?

Vote for REPLACE VARIES !
REPLACE VARIES
0 Likes
Message 9 of 16

MjDeck
Autodesk
Autodesk
Accepted solution

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")

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 10 of 16

Anonymous
Not applicable
Accepted solution

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")

 

Message 11 of 16

engilic
Advocate
Advocate

Hi @Anonymous @MjDeck ,

 

Any chance for a VBA code?

 

Thank you

 

Have a lovely day

0 Likes
Message 12 of 16

checkcheck_master
Advocate
Advocate

Hi there,

 

Still flickering here, despite the 'True' setting.

Any other options?

 

 

0 Likes
Message 13 of 16

MjDeck
Autodesk
Autodesk
Accepted solution

@checkcheck_master and @Anonymous , 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.


Mike Deck
Software Developer
Autodesk, Inc.

Message 14 of 16

WCrihfield
Mentor
Mentor
Accepted solution

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 

https://stackoverflow.com/questions/55430579/how-to-open-a-timed-message-box-in-ms-acces-without-cre... 

 

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 💡or you can Explore My CONTRIBUTIONS

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 15 of 16

MjDeck
Autodesk
Autodesk
Accepted solution

Thanks @WCrihfield . That system function will also work in iLogic. See the attached rule.


Mike Deck
Software Developer
Autodesk, Inc.

Message 16 of 16

checkcheck_master
Advocate
Advocate

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...

 

 

0 Likes