VISUAL BASIC 6 , DUVIDAS TEXTBOX

GBR960416 30/07/2012 09:29:02
#406814
[txt-color=#e80000]Olá pessoal meu primeiro tópico , estou fazendo um programa de cadastro e talz básico para iniciantes .
Mas tenho 2 duvidas que procurei na net e não achei a solução .

1° Tenho uma text box , Quantidade de filhos - quero limitar ela de números de 0 a 40 .
uma pessoa não pode te 100 filhos ai queria limitar ela , não sei se tem esse código queria a ajuda de vocês .

2° Queria saber como bloquear botoes e text box e desbloquear só quando a pessoa preencher um text box no caso que era o [Ô]cod id[Ô] para q seja feita a busca no banco de dados , mais primeiro ela tem q preencher text box ai quando ela preencher desbloqueia outras opções para ela .
[/txt-color]
DONCORLEONE 30/07/2012 09:48:14
#406816
Resposta escolhida
Citação:

:
[txt-color=#e80000]Olá pessoal meu primeiro tópico , estou fazendo um programa de cadastro e talz básico para iniciantes .
Mas tenho 2 duvidas que procurei na net e não achei a solução .

1° Tenho uma text box , Quantidade de filhos - quero limitar ela de números de 0 a 40 .
uma pessoa não pode te 100 filhos ai queria limitar ela , não sei se tem esse código queria a ajuda de vocês .

2° Queria saber como bloquear botoes e text box e desbloquear só quando a pessoa preencher um text box no caso que era o [Ô]cod id[Ô] para q seja feita a busca no banco de dados , mais primeiro ela tem q preencher text box ai quando ela preencher desbloqueia outras opções para ela .
[/txt-color]



1° você pode fazer a verificação no lost focus do campo ex:
If val(txtQtde) > 40 then
txtQtde = [Ô][Ô]
msgbox [Ô]A QUANTIDADE... ETC ETC[Ô]
end if

ou pode utilizar o evento textchanged onde você verifica sempre se o número do campo é maior que 40 com o mesmo if acima.


para bloquear os botões voce deve utilizar a propriedade [Ô]enabled[Ô]
aconselho a utilizar um botão chamado [Ô]alterar[Ô]

no lost focus do txtId você habilita o alterar, quando o alterar é clicado, os botões gravar e excluir são habilitados e o botão alterar é desbilitado.
GBR960416 30/07/2012 10:41:59
#406829
vou tentar caro amigo jaja entro com contato .

GBR960416 30/07/2012 10:47:51
#406831
Tentei o codigo que você me passo mais o mesmo não deu .
DONCORLEONE 30/07/2012 10:51:36
#406832
Poste o código do seu projeto, assim fica mais fácil definirmos uma linha de programação.
GBR960416 30/07/2012 10:57:49
#406834
Vou postar tudo os comandos selecionar oq estou tendi dificuldade .


[ô]-------------------------------------------------------------------------------------------------------------
[ô]AQUI COMEÇA A CONEXÃO COM O BANCO DE DADOS POSTGRES . linna_ruim
Public Sub Conexao()
AccessConnect = [Ô]driver={PostgreSQL}; server=10.0.0.236; database=linna_ruim; uid=postgres; pwd=;[Ô]
Set Conex = New ADODB.Connection
Conex.IsolationLevel = adXactReadCommitted
Conex.ConnectionString = AccessConnect
Conex.CommandTimeout = 50
Conex.CursorLocation = adUseServer
Conex.Open
End Sub

[ô]-------------------------------------------------------------------------------------------------------------
[ô]DADOS PARA BOTÃO ADICIONAR ,
Private Sub btnadicionar_Click()
Dim I As Integer
[ô]Dim rstConsulta As New ADODB.Recordset
Dim rstTestaCx As New ADODB.Recordset
Dim intContaRegistro As Integer
Dim strSQL As String

If txtCodigo = [Ô][Ô] Then
MsgBox [Ô]Preencha o campo com o codigo que deseja consultar, para que a busca seja realizada.[Ô]
Exit Sub
End If


strSQL = [Ô] INSERT INTO clientis(cod_id, nome, telefone, email, endereco, cpf, pais, cidade, idade,quantfilhos)[Ô]
strSQL = strSQL & [Ô] Values ([Ô] & txtCodigo.Text & [Ô] , [ô][Ô] & txtNome & [Ô][ô] , [ô][Ô] & txtTelefone.Text & [Ô][ô] , [ô][Ô] & txtEmail.Text & [Ô][ô] , [ô][Ô] & txtEndereco.Text & [Ô][ô] , [ô][Ô] & txtCpf.Text & [Ô][ô] , [ô][Ô] & txtPais.Text & [Ô][ô] ,[ô][Ô] & txtCidade.Text & [Ô][ô] , [ô][Ô] & txtIdade.Text & [Ô][ô] ,[ô][Ô] & txtquantfilhos.Text & [Ô][ô] )[Ô]


[ô]CONEXÃO COM O BANCO
Set rstTestaCx.ActiveConnection = Conex
rstTestaCx.Open strSQL
[ô] TERMINA CONEXÃO COM O BANCO
Debug.Print strSQL
btnlimpar_Click

End Sub

Private Sub btnconsultar_Click()
Dim I As Integer
[ô]Dim rstConsulta As New ADODB.Recordset
Dim rstTestaCx As New ADODB.Recordset
Dim intContaRegistro As Integer
consultando = True

If txtCodigo = [Ô][Ô] Then
MsgBox [Ô]Preencha o campo com o codigo que deseja consultar, para que a busca seja realizada.[Ô]
Exit Sub
End If

strSQL = [Ô] SELECT cod_id, nome, telefone, email, endereco, cpf, pais, cidade, idade, quantfilhos [Ô]
strSQL = strSQL & [Ô] FROM [Ô][Ô]clientis[Ô][Ô][Ô]
strSQL = strSQL & [Ô] WHERE Cod_ID = [Ô] & txtCodigo
Debug.Print strSQL
Set rstTestaCx.ActiveConnection = Conex
rstTestaCx.Open strSQL


If rstTestaCx.EOF = False Then
txtNome = rstTestaCx([Ô]nome[Ô])
txtTelefone = rstTestaCx([Ô]telefone[Ô])
txtEmail = rstTestaCx([Ô]email[Ô])
txtEndereco = rstTestaCx([Ô]endereco[Ô])
txtCpf = rstTestaCx([Ô]cpf[Ô])
txtPais = rstTestaCx([Ô]pais[Ô])
txtCidade = rstTestaCx([Ô]cidade[Ô])
txtIdade = rstTestaCx([Ô]idade[Ô])
txtquantfilhos = rstTestaCx([Ô]quantfilhos[Ô])
End If
rstTestaCx.Close

End Sub

Private Sub btngravar_Click()

End Sub

Private Sub cmdFechar_Click()

End Sub

Private Sub btndeletar_Click()
Dim rstTestaCx As New ADODB.Recordset
Dim strSQL As String

If txtCodigo = [Ô][Ô] Then
MsgBox [Ô]Preencha o campo com o codigo, para excluir algum registro.[Ô]
Exit Sub
End If

strSQL = [Ô] delete from clientis where cod_id = [Ô] & txtCodigo
Debug.Print strSQL
[ô]gCN.BeginTrans

Set rstTestaCx.ActiveConnection = Conex
rstTestaCx.Open strSQL

txtCodigo.SetFocus
btnlimpar_Click
End Sub

Private Sub btnfechar_Click()
Unload Me
End Sub

Private Sub btnlimpar_Click()
txtNome.Text = [Ô][Ô]
txtTelefone.Text = [Ô][Ô]
txtPais.Text = [Ô][Ô]
txtCidade.Text = [Ô][Ô]
txtIdade.Text = [Ô][Ô]
txtCpf.Text = [Ô][Ô]
txtEndereco.Text = [Ô][Ô]
txtCodigo.Text = [Ô][Ô]
txtEmail.Text = [Ô][Ô]
txtquantfilhos = [Ô][Ô]


End Sub



Private Sub Form_KeyPress(KeyAscii As Integer)
Limitar KeyAscii
End Sub

Private Sub Form_Load()
MsgBox [Ô]Bem Vindo![Ô]
Conexao
End Sub

Private Sub lblEndereco_Click(index As Integer)

End Sub

Private Sub Image1_Click()

End Sub

Private Sub txtCodigo_KeyPress(KeyAscii As Integer)
If KeyAscii = 46 Then KeyAscii = 44
If KeyAscii = 44 And InStr(txtCodigo.Text, [Ô],[Ô]) <> 0 Then
KeyAscii = 0
Exit Sub
End If
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 44 Then
KeyAscii = 0
End If
End Sub


Private Sub txtCpf_KeyPress(KeyAscii As Integer)
If KeyAscii = 46 Then KeyAscii = 44
If KeyAscii = 44 And InStr(txtCpf.Text, [Ô],[Ô]) <> 0 Then
KeyAscii = 0
Exit Sub
End If
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 44 Then
KeyAscii = 0
End If
End Sub

Private Sub txtIdade_KeyPress(KeyAscii As Integer)
If KeyAscii = 46 Then KeyAscii = 44
If KeyAscii = 44 And InStr(txtIdade.Text, [Ô],[Ô]) <> 0 Then
KeyAscii = 0
Exit Sub
End If
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 44 Then
KeyAscii = 0
End If
End Sub

Private Sub txtquantfilhos_KeyPress(KeyAscii As Integer)
If val(txtquantfilhos) > 40 then
txtquantfilhos = [Ô][Ô]
msgbox [Ô]A QUANTIDADE... ETC ETC[Ô]
end if
If KeyAscii = 46 Then KeyAscii = 44
If KeyAscii = 44 And InStr(txtquantfilhos.Text, [Ô],[Ô]) <> 0 Then
KeyAscii = 0
Exit Sub
End If
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 44 Then
KeyAscii = 0
End If
End Sub

Private Sub txtTelefone_KeyPress(KeyAscii As Integer)
If KeyAscii = 46 Then KeyAscii = 44
If KeyAscii = 44 And InStr(txtTelefone.Text, [Ô],[Ô]) <> 0 Then
KeyAscii = 0
Exit Sub
End If
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 44 Then
KeyAscii = 0
End If
End Sub
[txt-color=#e80000] [/txt-color]
DONCORLEONE 30/07/2012 11:02:12
#406835
Citação:

Private Sub txtquantfilhos_KeyPress(KeyAscii As Integer)
If val(txtquantfilhos) > 40 then
txtquantfilhos = [Ô][Ô]
msgbox [Ô]A QUANTIDADE... ETC ETC[Ô]
end if
If KeyAscii = 46 Then KeyAscii = 44
If KeyAscii = 44 And InStr(txtquantfilhos.Text, [Ô],[Ô]) <> 0 Then
KeyAscii = 0
Exit Sub
End If
If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 And KeyAscii <> 44 Then
KeyAscii = 0
End If
End Sub



para verificar se é maior que 40, não utilize o evento keypress... tente utilizar o evento [Ô]text_changed[Ô]
GBR960416 30/07/2012 11:07:04
#406836
como assim amigo text change ?
GBR960416 30/07/2012 11:10:55
#406837
pode me mostar como ficaria o codigo com esse text_change ?
DONCORLEONE 30/07/2012 11:12:52
#406839
Desculpe por não especificar, é o primeiro evento do text box, [Ô]Change[Ô]... ele é acionado cada vez que há uma alteração no txt
GBR960416 30/07/2012 11:16:50
#406842
Amigo muito obrigado pela dica funcionou direitinho , vo deixar o codigo aqui caso alguem tivesse essa duvida .


Private Sub txt_Change()
If Val(nome do text box) > 40 Then
nome do text box = [Ô][Ô]
MsgBox [Ô]bla bla bla[Ô]
End If
End Sub
Tópico encerrado , respostas não são mais permitidas