Good Day, how can i put a username and password in form? in Visual Basic 2008

Recommended Answers

All 8 Replies

here i am telling the way what i used for it (you can also use predefined forms for this purpose).

just create two label and textboxes and one button .

on button you can now check for login as follow:

if(Txtusername.text="Admin" and Txtpassword.text="Password")
msgbox("login successful")
else
msgbox("Password Invalid")
End if

right now you should write above code but later (when you understand DB concept) then you can retrieve data from DB and then check for login.

hope this helps.

commented: correct answer +2

what should i do if this happen
If TextBox1.Text = "asdf" Then

            If TextBox2.Text = ("qwerty") Then


            MsgBox("correct")

            Me.Hide()
            Form2.Show()

            Me.Close()
        End If
    Else
        MsgBox("wrong")

    End If

it doesnt go into form 2? why is it like this?

Maybe If TextBox2.Text = "qwerty" Then

why is it not connecting to form 2?

get rid of me.close because it exits your application

Change Me.Close() to Me.Hide()

ok,
Here are some alternatives for you,
What you can do is Remove me.close()
OR
go to solution explorer → My Project → on application tab.
you will notice at the bottom: shutdown mode.
change it to "when last from closing". (check the attachment)

fd06dc9b8a72d1ed5cfcbcf84d0c196b

commented: nice explanation +0

the reason is:
When you are using me.close on the form 1
and at the time by default the application setting is as
shutdown mode: When startup form closes.
so When your First form is going to close at the time all else form which are linked with it will closed. So for your situation you can not close it. (you can hide it)

But on the Form 2 Closes you should also need to close first form.
On form2 => formclosing event will be:
application.exit()
or form1.close()

but I will prefered you to change the setting. as shown in previous details.

Reason: You can close any form, but the application will not end untill the last form is opened.

Thank you - Deep Modi

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.