Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ilogic timed out message box

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
gazadder
3029 Views, 15 Replies

Ilogic timed out message box

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.

15 REPLIES 15
Message 2 of 16
Ktomberlin
in reply to: gazadder

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.  

Message 3 of 16
gazadder
in reply to: Ktomberlin

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.

Message 4 of 16
Ktomberlin
in reply to: gazadder

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)

Message 5 of 16
gazadder
in reply to: Ktomberlin

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.

 

 

 

 

Message 6 of 16
Ktomberlin
in reply to: gazadder

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
gazadder
in reply to: Ktomberlin

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.

Message 8 of 16
marcin_bargiel
in reply to: gazadder

Does anyone know the solution for time out message box ?

Vote for REPLACE VARIES !
REPLACE VARIES
Message 9 of 16
MjDeck
in reply to: marcin_bargiel

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
vulic
in reply to: MjDeck

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
in reply to: gazadder

Hi @vulic @MjDeck ,

 

Any chance for a VBA code?

 

Thank you

 

Have a lovely day

Message 12 of 16
checkcheck_master
in reply to: engilic

Hi there,

 

Still flickering here, despite the 'True' setting.

Any other options?

 

 

Message 13 of 16
MjDeck
in reply to: checkcheck_master

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


Mike Deck
Software Developer
Autodesk, Inc.

Message 14 of 16
WCrihfield
in reply to: engilic

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

 

Wesley Crihfield

EESignature

Message 15 of 16
MjDeck
in reply to: WCrihfield

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
in reply to: MjDeck

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

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report