bioshock Posted May 13, 2008 at 05:48 PM Report Share #184852 Posted May 13, 2008 at 05:48 PM 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 More sharing options...
Ivo Pereira Posted May 13, 2008 at 06:46 PM Report Share #184865 Posted May 13, 2008 at 06:46 PM 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 More sharing options...
bioshock Posted May 13, 2008 at 08:14 PM Author Report Share #184886 Posted May 13, 2008 at 08:14 PM Boas Blood, isto é uma senha, do género..A pessoa insere a senha se estiver mal 3 vezes então sai do programa, caso contrário entra. Cumps e obrigado. Link to comment Share on other sites More sharing options...
psiico Posted May 13, 2008 at 08:32 PM Report Share #184888 Posted May 13, 2008 at 08:32 PM 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 Psiico // Portfolio Link to comment Share on other sites More sharing options...
bioshock Posted May 13, 2008 at 08:55 PM Author Report Share #184895 Posted May 13, 2008 at 08:55 PM Psico, não percebi algumas coisas. 1º o código não está todo feito, certo? é que se está dá-me erro. 2º eu tentei modificar, mas não consegui. 3º o que significa vbcrlf ? :o Muito obrigado psico pela ajuda. Link to comment Share on other sites More sharing options...
psiico Posted May 13, 2008 at 09:11 PM Report Share #184900 Posted May 13, 2008 at 09:11 PM 1º ele devia funcionar, deu erro em q? 2º nao conseguiste porque?:S 3º o vbcrlf faz quebra de paragrafo. vou testar. Psiico // Portfolio Link to comment Share on other sites More sharing options...
bioshock Posted May 13, 2008 at 09:15 PM Author Report Share #184902 Posted May 13, 2008 at 09:15 PM Fica sempre a dizer " Tens duas tentativas " Não sabia 😁 obrigado. Link to comment Share on other sites More sharing options...
psiico Posted May 13, 2008 at 09:17 PM Report Share #184904 Posted May 13, 2008 at 09:17 PM ya, ja constatei isso, vou tentar contornar a situação 😁 Psiico // Portfolio Link to comment Share on other sites More sharing options...
anolsi Posted May 13, 2008 at 09:18 PM Report Share #184905 Posted May 13, 2008 at 09:18 PM dim tentativas as integer = 3 Tem que ser colocado como variável global, e não dentro do evento. "Nós somos o que fazemos repetidamente, a excelência não é um feito, e sim, um hábito."Não respondo a questões por PM que possam ser colocadas no fórum! Link to comment Share on other sites More sharing options...
bioshock Posted May 13, 2008 at 09:25 PM Author Report Share #184908 Posted May 13, 2008 at 09:25 PM Muito obrigado Psico e Anolsi, já está resolvido, é como o anolsi disse. Obrigado a todos. Link to comment Share on other sites More sharing options...
psiico Posted May 13, 2008 at 09:26 PM Report Share #184909 Posted May 13, 2008 at 09:26 PM 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 Psiico // Portfolio Link to comment Share on other sites More sharing options...
psiico Posted May 13, 2008 at 09:27 PM Report Share #184910 Posted May 13, 2008 at 09:27 PM de nada. desculpem o 2nd post com o codigo, façam o favor de o remover, se assim o acharem. Psiico // Portfolio Link to comment Share on other sites More sharing options...
Ivo Pereira Posted May 13, 2008 at 10:27 PM Report Share #184935 Posted May 13, 2008 at 10:27 PM Muito obrigado Psico e Anolsi, já está resolvido, é como o anolsi disse. Obrigado a todos. De nada 😁 basicamente foi o que eu disse, só me esqueci foi de declarar a variável global 😛 já agora, antes do título acrescenta [RESOLVIDO] 😉 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now