|
Postada em 12/11/2008 16:33 hs
pessoal, preciso multiplicar um valor dentro de um "text" quando der enter: ex: no no text1 (vou digitar( 5*5) e quando der enter e multiplique obrigado
|
|
|
|
PH1959
|
SÃO JOSÉ DOS CAMPOS SP - BRASIL
|
|
ENUNCIADA !
|
|
|
Postada em 12/11/2008 16:56 hs
tá indo pelo jeito mais dificil.. muito mais simples é usar 2 text box né? mas ...dá para fazer private sub text1_keypres(KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0 text1.text= a * b Else 'estou levando em consideração q somente numeros e/ou o * será digitado 'o ideal é fazer uma função para verificar isso i= len(text1.text) if i=1 then b=1 else if mid$(i, 1)= "*" then b=0 else if b=1 then a= a & mid$(i, 1) else b= b & mid$(i, 1) endif endif endif endif
|
|
|
|
Postada em 12/11/2008 16:58 hs
Private Sub Text1_KeyPress(KeyAscii As Integer) Dim Resultado As Double Dim Valor1 As Double Dim Valor2 As Double ' If KeyAscii = 13 Then Valor1 = CDbl(Val(Mid(Text1.Text, 1, InStr(1, Text1.Text, "*") - 1))) Valor2 = CDbl(Val(Mid(Text1.Text, InStr(1, Text1.Text, "*") + 1, Len(Text1.Text)))) Text1.Text = Valor1 * Valor2 End If End Sub
__________________
"It is the way of men to make monsters...and it is the nature of monsters to destroy their makers."
-F.E.A.R. (First Encounter Assault Recon )
|
|
|
Treze
|
SÃO VICENTE SP - BRASIL
|
|
ENUNCIADA !
|
|
|
Postada em 12/11/2008 18:13 hs
ou uma forma bem mais fácil que acho super legar Vá Em Project / Components... e selecione Microsoft Script Control 1.0 agora acrecente este objeto em seu form bom coloque sua textbox e cole este código no evento keypress Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = vbKeyReturn Then MsgBox ScriptControl1.Eval(Text1.Text) ' o segredo está aqui nesta linha End If End Sub digite sua formula matemática no textbox e pressione enter para ver o resultado: seja lá qual for a formula 10+10 3*30 (10+10)*7+38-5 3^3 e por ai vai não é legal, segredos do visual basic até
|
TÓPICO EDITADO
|
|
|
|
|
Postada em 12/11/2008 18:28 hs
VALEU PESSOAL, DEU TUDO OK.. OBRIGADO...
|
|
|
|
Postada em 13/11/2008 09:48 hs
@Treze: usar o Microsoft Script Control é partir pra ignorância...
__________________
"It is the way of men to make monsters...and it is the nature of monsters to destroy their makers."
-F.E.A.R. (First Encounter Assault Recon )
|
|
|