Exit Sub on Event

  • Thread starter Thread starter Michael_R_Banks
  • Start date Start date
M

Michael_R_Banks

I have a program with a user input subroutine that I want to exit
after a specific amount of time. How do I exit the sub when the timer
elapsed event fires?

Regards,
Michael
 
Michael,

Can you explain this a little bit more, like you write it, it sounds a
little bit strange.

A user needs to input something, but as he does not, you simple go on.

Normally you would stop a program then in the timer with me.close.

Cor
 
That's not the way VB usually works.

When the timer ticks, you do what you want to do at that time. You wouldn't
need to exit the user input sub because that should not have been invoked
until the user had input whatever was required.

If you are looping around in the user input subroutine somehow, then you
should restructure your program.
 
Hello Michael,

I would use a boolean variable, which is public in the form (so the
timer can also access it). Your input routine, you would just have to
check if that variable is true and then exit.

Best regards,

Martin
 
Michael_R_Banks said:
I have a program with a user input subroutine that I want to exit
after a specific amount of time. How do I exit the sub when the timer
elapsed event fires?

Place the routine in a separate thread and check a flag you set from outside
the thread which indicates that the routine should exit.
 
Cor,

Here's a little bit more about the program -- it's for inventory
management -- admin scans their ID barcode, then scans all the
equipment being checked out, then scans the ID of the person receiving
the equipment. If for some reason all the scans aren't completed, I
want a function that will clear my temporary tables & require the
order to start over.

Michael
 
Cor,

Here's a little bit more about the program -- it's for inventory
management -- admin scans their ID barcode, then scans all the
equipment being checked out, then scans the ID of the person receiving
the equipment. If for some reason all the scans aren't completed, I
want a function that will clear my temporary tables & require the
order to start over.

Michael

Michael,
If i understood correct, you can use a try-catch block, and when an
exception is occured re-call the function or sub, reacting with a
error message as optional

Like That:

'---Begin
Public Sub CheckInventory()

Try
' Try to do the job

Catch ex As Exception
Msgbox("An error is occured, clearing temp")
' Here to clear temp
ClearTemp()
' And start again if you want(optional)
' Be careful that you really want to retry
' ...not to be in an endless loop
CheckInventory()

End Try

End Sub

Public Sub ClearTemp()
' Notify clearing job
MsgBox("Temp is being cleared")
' Do the clearing temp job here

End Sub
'---End---

I'm not sure, but i hope that may be what you're looking for.

Thanks,

Onur Güzel
 
You need a state machine. When the scan occurs, check the state and process
accordingly.

State 0. Timer is disabled. Confirm the scan was the admin id, change state
to 1 and enable timer. If scan is not an admin id then report an error and
stay at state 0 with timer disabled.

State 1. Timer is enabled. Confirm that the scan was an item and process
it, then remain at state 1 with timer time re-initialized. If it was the
last item, set the state to 2 and re-initialise timer time. If the scan was
a receiver id and not all items have been processed, or an invalid item,
report an error, clear your tables and set timer to disabled and state to
0.

State 2. Confirm the scan is a receiver id. If not, clear tables, report an
error and set state to 0, otherwise process checkout, disable timer and set
state to 0.

If a timer tick occurs report a timeout error, clear all variables and set
timer to disabled and state to 0.
 
Back
Top