Good day
Can you please help me with my codes. My teacher tasked us to make a program that will accept a password from the input box then will show form1. Otherwise, it will repeat on asking for the correct password. the program will stop asking if you gave the correct password or if incorrect password is given three times.
I tried to make this program using loop because our lesson was looping but it did not worked. So i tried to use if statement. but it worked the other way around. so instead of accepting rc as the password (which set as the password), it was rejected instead.
Here is the code i used

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim x As String = InputBox("Password")
    Dim y As String = InputBox("Incorrect")

    Dim frm As New Form1
    If x = "rc" Then
        frm.Show()
    Else
        If y = "rc" Then
            frm.Show()
        Else
            If y = "rc" Then
                frm.Show()
            Else
                If y = "rc" Then
                    frm.Show()
                Else
                    frm.Close()
                End If
            End If
        End If
    End If
End Sub

End Class

Please help me with this.

'You better read up on the inputbox methods.
'Declare all the values and variables
Dim message as string="Enter the password"
Dim title as string = "InputBox Demo"
Dim defaultValue As String = "Me"
' this code set up your inputbox
' You are supposed to use a loop
'The loop is meant to count to 3 on three different entries
'You need to declare an Integer outside the loop and increase it inside the loop
Dim intCount as Integer=0

See if you can work it out from here

I fully appreciate your reply Minimalist. It helped me a lot. But I still have many problems making my codes. I had a hard time understanding on what

Dim defaultValue As String = "Me"

do. I followed what you told me to do. I've managed to understand a little bit the logic of the loop so i tried this

Dim frm1 As New Form1
    Do Until intcount = 3
                If title = message Then
                    frm1.Show()
                End If
                intcount = intcount + 1
            Loop

You might notice the frm1.show(). I used this because i need to open the Form1 upon entering the right password. Is the code i created correct or i need to revise it?
Anyways, thank you very much for replying my article man.

From the line 3 I can see that you didn't read up on inputbox - google it. Here is a link:
http://msdn.microsoft.com/en-us/library/6z0ak68w(v=vs.90).aspx
Do you know about functions, subroutines and about the scopes of variables -I am asking because I don't understand what you want to achieve in line 1.

More Information:
Here I declare the the retry as integer (you can set your own)
but at the top so that I don't need to type Dim retry as integer again...

you can do like this too:
cmdvalid_Click()

dim i as integer
if (txtpass.text = txtpass.tag) then
    message.show("correc pass")
Else
  if retry >= 3 then
     message.show("incorrect pass" & vbnewline & "No more retry. Sorry")
     cmdvalid.enabled = false
     'main as this will not let the user to click as we disabled valid button
  Else
     retry = retry + 1
     Message.show("Type the pass again." & vbnewline & "trial: " & retry &"/3")
  End if
End if
Form1_Load()

retry = 0
me.refresh()

Thank You

Not really. I'm still new in vb.net. I really want to make a program where an input box asking for the correct password will pop-out. And if correct, a new window which is the form1 will appear. If the password is not correct, then another input box will appea asking again. The program will stop asking for the correct password if the user already failed to input the correct password three times.

I really have low understanding about this, sorry
I'm really grateful for your help Minimalist and Deep Modi

Public Class Form1
    Dim counter As Integer = 1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        test() 'this is calling the sub named test
    End Sub
    Private Sub test()
        Dim myMessage As String
        Dim Prompt As String = "Input Password"
        Dim title As String = "Inputbox Test"
        Dim defaultText As String = ""
        Dim userpassw As String = "Me"
        myMessage = InputBox(Prompt, title, defaultText)
        If myMessage = "Me" Then
            MessageBox.Show("Password Correct")
        Else
            MessageBox.Show("Wrong Password or Cancel pressed")
            counter = counter + 1
            If counter > 2 Then
                MsgBox("Entry Failed, Good bye")
                End
            End If
            test()
        End If

    End Sub

End Class

You realy should google for the topics you are working with. The above code will do what you are supposed to be doing, try to understand it. Don't forget to close the thread and give credit.

hi, aaronernest.borres
there are thousands of approaches to this but for your case we make it so simple you understand it all OK?

        Dim pswd As String
        pswd = InputBox("Enter Password")
        If pswd <> "right" Then pswd = InputBox("Enter Password")
        If pswd <> "right" Then pswd = InputBox("Enter Password")
        If pswd <> "right" Then
            MsgBox("Time up", , "Trial Expired")
        Else
            MsgBox("Form 1 is Shown")
        End If

Just that.

I hope it helps, and you understand too.

Im sorry, that is to assume the right password is the word right.
And instead of a msgbox, you call your form1 straight away. = Userform1.show or whatever the name of the form

Thank you very much fourty for the additional help!

You're so great Minimalist, Deep Modi and fourty! You've made me learn much new things in this forum!

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.