Question from a noob

sunnyboyj

Member
Can someone help me starting with basic4ppc.
I have used the starting program number-guessing. I want to make a second screen with other questions but I can not start it. It stops after the original program. How do I close the form1 and start up the form2?

Sub Globals
'Declare the global variables here.
Dim number
End Sub

Sub App_Start
Form1.Show
number = Rnd (1,3)
End Sub

Sub btnGuess_Click
If Not (IsNumber(txtnumber.Text)) Then
Msgbox("Een juist nummer invoeren svp")
Return
End If
If txtnumber.Text > number Then
Msgbox("Een kleiner nummer")
Else If txtnumber.Text < number Then
Msgbox ("Mijn nummer is groter")
Else
If Msgbox ("Het juiste nummer!" & crlf & "Opnieuw?","",cmsgboxYesNo) = cYes Then
number = Rnd(1,3)
Else
form1.Close
End If
End If
txtnumber.Focus
txtnumber.SelectionStart = 0
txtnumber.SelectionLength = StrLength(txtnumber.Text)

End Sub

Sub key_Click
Form2.Show
number = Rnd (1,3)
End Sub
 

specci48

Well-Known Member
Licensed User
Longtime User
Hi sunnyboyj,

welcome to basic4ppc :)

The first form shown in basic4ppc is always the "main" form. This form cannot be closed because closing the "main" form exits the program.
The trick ist to show a second form, and the hide the "main" form from the taskbar so that you cannot switch between both forms. This is done by setting the form.text to space.
When closing the second form, you should reset the text of the "main" to it's original value.

I attached a modified sample of "GuessMyNumber", calling a second form with a button click (while hiding the "main" form), and showing the "main" form again after closung form2.


specci48


oops... i should type faster not to miss any posts... ;)
 

Attachments

  • GuessMyNumber2.sbp
    2 KB · Views: 201

Rioven

Active Member
Licensed User
Longtime User
Off topic, just suggestion

Hi sunnyboyj
You may use 'Select-Case' method in your code which is easier to follow during debugging compare to series of 'IF-Then' statements. Combinations of these two methods will do as well.:)

Welcome!

Regards,
 
Top