I know this seems like a very noobish question and has probably been asked many times before, I'm trying to write a lottery program in which the numbers are generated, then you can check your numbers. There is a command button on the first form which says "Check Numbers" and this would take you onto the second form. Can anyone help me by telling me how to bring this up by clicking the command button? Thanks.

Dani AI

Generated

As , and pointed out, the button-click is the right place to trigger the second form. The following expands on that simple answer with practical checks and small design tips so the form appears reliably and can receive the generated numbers.

If the form does not show when you click the button, confirm the click handler is actually running (double‑click the button in the designer to create the event and set a breakpoint or a simple debug message). Make sure the second form is included in the project and its name in the Project Explorer matches what you intend to call. Also check runtime issues: the form might be created but immediately closed, hidden off-screen, or not visible because of a property setting or an exception thrown before display.

To pass the lottery numbers from the main form to the checker form, avoid tight coupling. Give the checker form simple public properties or a public method that accepts the numbers, set those values before showing the form, then display it. Decide whether you want the checker modal (user must close it before returning) or modeless (both windows usable); modal dialogs are useful if you want the user to complete the check before changing numbers on the main form. Note that VB6 and VB.NET handle form instances differently—VB6 has default form instances by name, while in VB.NET it is more common to create a new instance explicitly—so adapt the pattern to the version you are using.

Small practical tips: use clear form/control names (for example frmMain, frmCheckNumbers) to avoid name collisions; check StartUpPosition if the form appears off-screen; and dispose/Unload forms appropriately after use to avoid resource leaks. These steps should make the behavior dependable and make it easy to hand data from the generator to the checker.

Recommended Answers

All 4 Replies

type this code in your command button click event:

Form2.Show

Private Sub Command1_Click()
    Form2.Show
End Sub

If you press the Command1 button it will automatically show the another form..

Great guys, thanks a lot! I appreciate it!

To do what you want do the following
Private Sub Command1_Click()
Form2.Show
End Sub
NB: if you have given your second form a name write that name instead of form2
Hope i've helped.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.