Jump to content

Cases, ajuda(RESOLVIDO)


bioshock
 Share

Recommended Posts

Boas, antes de mais quero agradecer a quem me tentar ajudar.

É o seguinte: Eu estou com um problema, que é, quando carrego num botão [ Button1 ] quero que este vá verificar se o que está dentro da textbox1 está correcto, se estiver então entra noutro form..caso não esteja, essa pessoa vai ter mais duas tentativas para inserir correctamente a "Senha"..o problema é que não consigo fazer as tentativas..deixo aqui o meu código:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If TextBox1.Text = "1234" Then

            PictureBox2.Visible = False

            PictureBox1.Visible = True

form3.show

        Else

            Dim x As Integer

            Select Case x

                Case 0

                    If TextBox1.Text <> "1234" Then

                        PictureBox2.Visible = True

                        PictureBox1.Visible = False

                        MsgBox("Restam-te duas tentativas")

                    End If

                Case 1

                    If TextBox1.Text <> "Pinho" Then

                        PictureBox2.Visible = True

                        PictureBox1.Visible = False

                        MsgBox("Restam-te 1 tentativas")

                    End If

            End Select

    End if

End Sub

End Class

Desculpem mas sou novo nisto  😁

Cumps e obrigado.

Link to comment
Share on other sites

Boas, antes de mais quero agradecer a quem me tentar ajudar.

É o seguinte: Eu estou com um problema, que é, quando carrego num botão [ Button1 ] quero que este vá verificar se o que está dentro da textbox1 está correcto, se estiver então entra noutro form..caso não esteja, essa pessoa vai ter mais duas tentativas para inserir correctamente a "Senha"..o problema é que não consigo fazer as tentativas..deixo aqui o meu código:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If TextBox1.Text = "1234" Then

            PictureBox2.Visible = False

            PictureBox1.Visible = True

form3.show

        Else

            Dim x As Integer

            Select Case x

                Case 0

                    If TextBox1.Text <> "1234" Then

                        PictureBox2.Visible = True

                        PictureBox1.Visible = False

                        MsgBox("Restam-te duas tentativas")

                    End If

                Case 1

                    If TextBox1.Text <> "Pinho" Then

                        PictureBox2.Visible = True

                        PictureBox1.Visible = False

                        MsgBox("Restam-te 1 tentativas")

                    End If

            End Select

    End if

End Sub

End Class

Desculpem mas sou novo nisto 😁

Cumps e obrigado.

Pelo que eu percebi (se não for explica), tu quando acontecem os outros casos, (presumo que o x seja o número de tentativas) tens de adicionar/subtrair (não sei que tipo de programa (ou jogo) queres fazer... independentemente do caso.

Link to comment
Share on other sites

podes sempre fazer com 1 If e vais diminuindo as tentativas disponiveis.

por ex:

dim pass as string = "PASSWORD"
dim tentativas as integer = 3
if (me.textbox1.text <> pass) then
tentativas = tentativas - 1
'SE JÁ METEU 3 PASSES ERRADAS ENTAO SAI DO PROGRAMA
if (tentativas = "0") then
msgbox ("Excedeu o número máximo de tentativas!")
end
end if
'SE NAO METEU 3 ERRADAS, CONTINUA NISTO
msgbox("Password errada!" & vbcrlf & "restam-te " & tentativas & "tentativas")
exit sub 
else
form2.show()
me.hide()
end if
Link to comment
Share on other sites

tambem me ocorreu isso,mas como está dentro do mesmo ciclo pensei que nao fosse necessário. pronto o codigo entao é

Public Class Form1
   Public tentativas As Integer = 0
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim pass As String = "PASSWORD"

       If (Me.TextBox1.Text <> pass) Then
           tentativas = tentativas - 1
           'SE JÁ METEU 3 PASSES ERRADAS ENTAO SAI DO PROGRAMA
           If (tentativas = "0") Then
               MsgBox("Excedeu o número máximo de tentativas!")
               End
           End If
           'SE NAO METEU 3 ERRADAS, CONTINUA NISTO
           MsgBox("Password errada!" & vbCrLf & "restam-te " & tentativas & "tentativas")
           Exit Sub
       Else
           form2.show()
           Me.Hide()
       End If
   End Sub
End Class
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.