Program Flow and Buttons

H

Hank Youngerman

This should be a simple one - I'm drawing a blank, haven't worked with
VBA in a while.

I have a command button on a spreadsheet that calls a user form. That
form allows the user to enter program parameters. Basically, the code
in the command button says:

load UserForm
Userform.Show

There are two buttons on the user form, "Continue" and "Exit." The
Continue button is attached to code that merely says "Userform.hide."

The main program code - the code after "Userform.show" - does not
execute while the userform is visible. When the continue button is
clicked, execution resumes. This is fine, although I'm a bit fuzzy as
to how or why this is working (even though it's doing what I want.)
However, the Exit button lets the program continue also.

Am I supposed to use the subroutine ExitButton_Click to define a
variable, then pass that variable to the main code and use it to go to
the "Exit Sub" program command? I'm not even sure how to pass
variables, although I could put a control on the userform, hide it, and
give it a value, I guess.

This probably oughta be simpler than I'm making it.
 
J

JLGWhiz

Hank, you need to copy the code for both of the controls and paste it under
this posting so we can see what the code actually calls for.

From what you described, it sounds like your main program code is initiated
with an event procedure, but that is only a guess. The exit button was
probably put there as an escape mechanism if you did not want to run the
program. Again, only a guess. Need to see the code to be sure.
 
H

Hank Youngerman

Omitting some superfluous code:

The worksheet has a button called PML. There is code on that worksheet
(not in a separate module):

Private Sub PML_Click()
Load UserForm1
UserForm1.Radius.AddItem 2
UserForm1.Interval.AddItem 100
UserForm1.UseLoss = True
UserForm1.Show

eventcode = UserForm1.Interval.ListIndex + 1
{and more}


Userform1 has listboxes Radius and Interval, radio buttons UseLoss and
UseDamage, and command buttons ExitMacro and RunPML. The code in
userform1 is:


Private Sub ExitMacro_Click()
Stop
End Sub

Private Sub RunPML_Click()
UserForm1.Hide
End Sub


So......................

Clicking the PML command button on the main sheet activates the code
PML_Click. It populates the listboxes, sets the initial value for the
radio button, and loads userform1. It then waits until I click one of
the command buttons. If I click ExitMacro it triggers the stop
statement (else it would just continue the code in PML); If I click
RunPML it hides the userform and continues running the PML code with
the statement

eventcode = UserForm1.Interval.ListIndex + 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top