Author Topic: The Great Escape..  (Read 5161 times)

0 Members and 1 Guest are viewing this topic.

hardwired

  • Guest
The Great Escape..
« on: December 09, 2008, 10:49:11 AM »
Hi,

Is there any way of coding a program so that the user can escape out of the running vba program?

I have created a suit of cad tools for our office and some of the comment the managers have had is that there is no way to escape a program if you accidently click go or fill in the info incorrectly and click go. Is there a way to add this functionality, whilst keeping everything in the drawing intact, so that the drawing is taken back to its state before the program was run?

Any Ideas?

pkohut

  • Guest
Re: The Great Escape..
« Reply #1 on: December 09, 2008, 11:00:16 AM »
How about setting an undo mark when the routine is started.  Then the user can
use the undo command if need be.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: The Great Escape..
« Reply #2 on: December 09, 2008, 11:17:30 AM »
Any Ideas?
I guess, for starters... what is it that your program does (in a nutshell)?
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

hardwired

  • Guest
Re: The Great Escape..
« Reply #3 on: December 09, 2008, 11:26:38 AM »
Thery are many and varied, but by example, one of them plots all selected layouts, using the saved plot-settings in each layout. Its a bit primitive but haven't had time to sort out proper coding yet, but basically it cycles through each layout and using the SendCommand to plot the layout..

Now sometimes this might take ages of course and the user might click the wrong layout in the list or forget one or two or just click the button accidently, so an escape option would be great, not just an undo once the pogram has finished, which i do need for certain other programs but not this one..

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: The Great Escape..
« Reply #4 on: December 09, 2008, 11:34:19 AM »
...cycles through each layout and using the SendCommand to plot the layout...
*GASP*  SendCommand??  To plot??

For shame!!!




Since you're looping through the layouts, performing the same code over and over, I suppose you could display a form with a cancel button on it.  You could have a global variable that would be used to indicate whether or not the user pressed the cancel button - maybe a boolean?  At the begining of each loop, check the True/False value of the global variable.  If the user pressed the cancel button, the variable would set and the program would respond accordingly.

Make any sense?
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Bob Wahr

  • Guest
Re: The Great Escape..
« Reply #5 on: December 09, 2008, 12:13:05 PM »
Two words for you for the function you mentioned...

pub
lish

You might give something like this a shot though.  I popped it together with the sample timer for demo purposes.
Code: [Select]
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Const VK_ESCAPE = &H1B

Sub Test()
Dim intCnt As Integer
Dim PauseTime, Start, Finish, TotalTime

GetAsyncKeyState VK_ESCAPE
For intCnt = 1 To 10
If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then
    PauseTime = 5    ' Set duration.
    Start = Timer    ' Set start time.
    Do While Timer < Start + PauseTime
        DoEvents    ' Yield to other processes.
        If GetAsyncKeyState(VK_ESCAPE) Then
         Exit For
        End If
   
    Loop
    Finish = Timer    ' Set end time.
    TotalTime = Finish - Start    ' Calculate total time.
    MsgBox "Paused for " & TotalTime & " seconds"
Else
    End
End If
Next intCnt
End Sub

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: The Great Escape..
« Reply #6 on: December 09, 2008, 12:14:52 PM »
Two words for you for the function you mentioned...

pub
lish
:-D
True dat!
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Bryco

  • Water Moccasin
  • Posts: 1883
Re: The Great Escape..
« Reply #7 on: December 10, 2008, 12:31:33 AM »
I use a printalllayouts function rather than publish because I like it better than publish.
I've never thought about an escape sequence, could be handy with 20 layouts. Can you stop a publish command midstream?

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: The Great Escape..
« Reply #8 on: December 10, 2008, 08:18:22 AM »
Can you stop a publish command midstream?
Yup!
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Bryco

  • Water Moccasin
  • Posts: 1883
Re: The Great Escape..
« Reply #9 on: December 10, 2008, 09:53:54 AM »
Oh. Maybe a modeless form could do that, I haven't messed with those .

rogue

  • Guest
Re: The Great Escape..
« Reply #10 on: December 11, 2008, 07:31:01 PM »
Can you stop a publish command midstream?
Yup!

amazing - you did it - Ive been staring at that dialog box you posted for HOURS now, and it hasnt moved! Nice work!

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: The Great Escape..
« Reply #11 on: December 12, 2008, 08:20:51 AM »
Can you stop a publish command midstream?
Yup!

amazing - you did it - Ive been staring at that dialog box you posted for HOURS now, and it hasnt moved! Nice work!
:wink:   :kewl:
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io