Question vb Buttons help

StarKiller512

Member
Joined
Nov 15, 2012
Messages
13
Programming Experience
1-3
Hi. i'm been doing computing for almost two years and for my coursework i am doing a game for educational purposes but i've run across a problem

I have made a login screen for the users who can create a profile and logon to their profile. When they do login they will be greeted with a message box saying 'login successful'. What i want it to do is, when they click on ok i want it to take them to the start up screen but i dont know how to do that. i was think doing an If statement. something like 'If button.clicked= true then frm_startUp.show. is this the right way or is there a better way?
 
thanks. I dont suppose you know how to show a random form from a list of forms? as in i have 10 forms and i want to pick one at random and show it but i only want to show one at a time
 
Hi. i'm been doing computing for almost two years and for my coursework i am doing a game for educational purposes but i've run across a problem

I have made a login screen for the users who can create a profile and logon to their profile. When they do login they will be greeted with a message box saying 'login successful'. What i want it to do is, when they click on ok i want it to take them to the start up screen but i dont know how to do that. i was think doing an If statement. something like 'If button.clicked= true then frm_startUp.show. is this the right way or is there a better way?
You have some backwards logic going on here, I would recommend you showing the main game screen first, then in the Show event have it display the Login form and if the login is successful you simply close the login form and let the intro game form be used like normal, if they decide to cancel the login then when the login window is closed simply call Me.Close() and let the application exit. If they do not enter valid login credentials, keep the login window open but prompt them or notify them that they need to enter a valid login.
 
thanks. I dont suppose you know how to show a random form from a list of forms? as in i have 10 forms and i want to pick one at random and show it but i only want to show one at a time

us the random class and a simple if statement

Random Class (System)


Edit::

Another way is to publicly declare your 9 forms and initialize at startup

Public myForms(9) As Form


' Initialize
myForms(0) = Form1
myForms(1) = Form2
myForms(2) = Form3
myForms(3) = Form4
myForms(4) = Form5
myForms(5) = Form6
myForms(6) = Form7
myForms(7) = Form8
myForms(8) = Form9
myForms(9) = Form10

and then use your random class so that you can call the random form like so:

myForms(rand.next(0,10)).show()
 
Last edited:
because i coudlnt find the create new thread button this will have to do. i have run into a problem. when i run the application it runs the start page and the login page. i have included a control that only lets them play the game if they have either registered or logged in. Heres the if statement i am using
If frm_login.Connsucc = True Then
    TextBox1.Hide()
    TextBox2.Show()
    TextBox2.Text = ("Hello " & frm_Start.TextBox1.Text)
    Btn_Start.Enabled = True
    Btn_Options.Enabled = True
    btn_Click.Enabled = True
    Me.Refresh()
ElseIf frm_login.Connsucc = False Then
    TextBox1.Show()
    TextBox1.Text = "You must register or login first before playing this game"
    TextBox2.Hide()
    Btn_Start.Enabled = True
    Btn_Options.Enabled = False
    btn_Click.Enabled = True
End If
 
Last edited by a moderator:
heres the rest of the code
Private Sub frm_StartUp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
    TextBox3.Text = frm_login.Connsucc
    If frm_login.Connsucc Then
        TextBox1.Hide()
        TextBox2.Show()
        TextBox2.Text = ("Hello " & frm_Start.TextBox1.Text)
        Btn_Start.Enabled = True
        Btn_Options.Enabled = True
        btn_Click.Enabled = True
        Me.Refresh()
    Else
        TextBox1.Show()
        TextBox1.Text = "You must register or login first before playing this game"
        TextBox2.Hide()
        Btn_Start.Enabled = True
        Btn_Options.Enabled = False
        btn_Click.Enabled = True
    End If
    frm_Start.Show()
End Sub

 
Last edited by a moderator:
heres the rest of the code
Private Sub frm_StartUp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
    TextBox3.Text = frm_login.Connsucc
    If frm_login.Connsucc Then
        TextBox1.Hide()
        TextBox2.Show()
        TextBox2.Text = ("Hello " & frm_Start.TextBox1.Text)
        Btn_Start.Enabled = True
        Btn_Options.Enabled = True
        btn_Click.Enabled = True
        Me.Refresh()
    Else
        TextBox1.Show()
        TextBox1.Text = "You must register or login first before playing this game"
        TextBox2.Hide()
        Btn_Start.Enabled = True
        Btn_Options.Enabled = False
        btn_Click.Enabled = True
    End If
    frm_Start.Show()
End Sub


ok... both myself and google have never heard of .Connsucc
I'm assuming it's a property of the login form that he's created, but since he has not posted all the code I cannot say for sure.
Connsucc is not a property of the form, so it's definitely something he created on his own on the login form.
 
.Connsucc is a shared variable that i created. Should have elaborated that bit, my bad. Also the textbox3.text was something i made to help me try and see what was going wrong. Is there a way to declare a variable in a certain amount of forms or would the Public Shared declaration suffice? Where i'm going with that question is: i have the randomizer working but i have a Variable named FormCount, should this reach 10 it will output the results screen. But.. i have 24 forms, all of them should have the FormCount variable, after a question has been answered there is a button that will take it to the next randomized form, once they answer the question the FormCount variable will increment by 1, but i have 24 forms that are random, so how would you increment the variable?
 
Last edited:
Crikey, 24 forms, each to serve only one question.. I guess a tab control was not an option?

Let me see if I understand this.

1. The educational game will ask the user 10 random questions from a selection of 24 yes?
2. Once a question has been answered by the user, the form that this question resided on closes and the next random question/form appears?
3. Repeat Step 2 until 10 questions have been asked?

In the effort of saving time I will assume that I am correct on the above.


The way I would manage this is to store my global variables (incrementer, result-data etc) in a separate module or class. For example:

Module Declarations

Public FormCount As Integer
Public Score As Integer

End Module


Then in the ButtonClick handler of each form, add to your score, add to your increment, and check if the increment = 10 and if yes, process the results, if not, randomize and get your next form.
 
Thanks that was a lot of help. Not sure if there is a way to solve but when i do randomize it works, but when i exit the game and go back on it comes up with the same random forms. is there a way to make sure different random forms open each time?
 
heres the code for the random form generation
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MyForms(0) = Form6
MyForms(1) = Form7
MyForms(2) = Form8
MyForms(3) = Form9
MyForms(4) = Form10
MyForms(5) = Form11
MyForms(6) = Form13
MyForms(7) = Form14
MyForms(8) = Form15
MyForms(9) = Form16
FormCount = FormCount + 1
If FormCount = 10 Then
Form17.Show()
Else
MyForms(CInt(Int((10 - 0 + 1) * Rnd() + 0))).Show()
End If
Me.Close()
End Sub
End
Class

the way i am exiting the game is with the use of a button on the ending page (for now) that when clicked will end the program
 
Back
Top