Label.Text com novos resultados

Marcelo Quintanilha

Member
Licensed User
Bom dia.

Após entrar com dados e clicando no BUTTON, o sistema realiza os cálculos mostrando numa Label o valor. Se eu alterar alguma entrada de dados, clicando em BUTTON ele deveria refazer os cálculos e mostrar o novo valor na Label, entretanto, preciso clicar 2 vezes no BUTTON para que ele faça isso... alguém sabe dizer como solucionar?
Obrigado.
 

Cableguy

Expert
Licensed User
Longtime User
Ola Marcelo

podes postar o teu Button_Click?

obs. se tiveres ligado o valor da entrada de texto a uma variável, a variável so vai assumir o novo valor depois de perder o focus. ao clicares no button a entrada de texto perde o focus mas o calculo ainda é feito com os valores anteriores. a melhor solução é utilizar o evento ValueChanged de forma a actualizar o valor a cada alteração, ou em alternativa, utilizar o evento FocusChanged da entrada de dados
 

Marcelo Quintanilha

Member
Licensed User
B4X:
Sub EditText_FocusChanged (HasFocus As Boolean)
    Dim Send As EditText
    If HasFocus Then
        Send = Sender
    End If
End Sub

Sub Button1_Click
    'Entrada de dados
   
    bfl = EditText1.Text 'bfl
    hfl = EditText2.Text 'hfl
    bw = EditText3.Text 'bw
    dp = EditText4.Text 'dp
    ds = EditText5.Text 'ds
    cp = EditText6.Text 'CP 190
    GP1= EditText7.Text 'gp1
   fck= EditText8.Text 'fck
    Md= EditText9.Text 'Md
   
   
    If GP1=0 Then GP1=0.00001
    If GP1=100 Then GP1=99.99999
   
    If fck <= 35 Then BetaXLimite = 0.50
    If fck >  35 Then BetaXLimite = 0.40
   
    MdAjust = 100000*Md
    GP = GP1/100
    fckAjust = 6.07143*fck
    GS = 1/((1/GP)-1)
    d = ((GS*dp)+ds)/(GS+1)
     
    Mdfl = fckAjust*bfl*hfl*(d-0.5*hfl)
   
    If Mdfl > MdAjust Then
    MiD1 = MdAjust/(fckAjust*bfl*d*d)
    LN = 1-(2*MiD1)
    Wd = 1 - (Power (LN,(1/2)))
    Rcc1 = fckAjust*bfl*Ybloco
    AS2 = Rcc1/(4350*(1+GS))
    AP2 = (GS*AS2*4350)/(cp*78.2608)
    BetaX = 1.25*Wd
    Ybloco = Wd * d
        End If
   
   
    If Mdfl<MdAjust Then
    Rcc1 = fckAjust*(bfl-bw)*hfl    'Rc1
    Md1 = (d-0.5*hfl)*Rcc1 'Md1
    DeltaMd = MdAjust-Md1         'Md2
    MiD2 = DeltaMd/(fckAjust*bw*d*d) 'mi d2
    LN = 1-(2*MiD2)
    Wd = 1 - (Power (LN,(1/2)))  'Omega d2
    Rcc2 = Wd*d*bw*fckAjust  'Rc2
    AS2 = (Rcc1+Rcc2)/((1+GS)*4350)
    AP2 = GS*AS2*4350/(78.2608*cp)
    BetaX = 1.25*Wd
    Ybloco = Wd * d
    End If
       
   
    Label1.Text = NumberFormat (AS2,0,2)
    Label2.Text = NumberFormat (AP2,0,2)
    Label3.Text = NumberFormat (BetaX,0,3)
    Label8.Text = NumberFormat (Ybloco,0,2)

    If BetaX < BetaXLimite Then Label10.TextColor=Colors.Green
    If BetaX > BetaXLimite Then Label10.TextColor=Colors.Red
    If BetaX < BetaXLimite Then Label10.Text = "Ok... Armadura simples"
    If BetaX > BetaXLimite Then Label10.Text = "ATENÇÃO - ALTERAR SEÇÃO"
   
   
    Label21.Visible=True
    Label22.Visible=True
    Label23.Visible=True
    Label24.Visible=True
    Label25.Visible=True
   
    Label21.Text= "βx Limite = " & NumberFormat (BetaXLimite,0,3)
    Label22.Text= "βx =" & NumberFormat (BetaX,0,3)
   
    If BetaX < BetaXLimite Then
        Label23.IsInitialized
        Label23.TextColor=Colors.Green
        Label23.Text = "OK... βx < βx Limite"
        Label24.Text= NumberFormat (AS2,0,2)
        Label25.Text= NumberFormat (AP2,0,2)
    Else
        Label23.IsInitialized
        Label23.TextColor=Colors.Red
        Label23.Text = "Erro... βx > βx Limite... Altere Seção"
    End If
   
    Label12.Text = NumberFormat (Mdfl,0,2)
    Label14.Text = NumberFormat (MiD1,0,6)
    Label15.Text = NumberFormat (Wd,0,6)
[code/]
 

Cableguy

Expert
Licensed User
Longtime User
B4X:
Sub EditText_FocusChanged (HasFocus As Boolean)
    bfl = EditText1.Text 'bfl
    hfl = EditText2.Text 'hfl
    bw = EditText3.Text 'bw
    dp = EditText4.Text 'dp
    ds = EditText5.Text 'ds
    cp = EditText6.Text 'CP 190
    GP1= EditText7.Text 'gp1
   fck= EditText8.Text 'fck
    Md= EditText9.Text 'Md
End Sub

Sub Button1_Click
 
    If GP1=0 Then GP1=0.00001
    If GP1=100 Then GP1=99.99999
 
    If fck <= 35 Then BetaXLimite = 0.50
    If fck >  35 Then BetaXLimite = 0.40
 
    MdAjust = 100000*Md
    GP = GP1/100
    fckAjust = 6.07143*fck
    GS = 1/((1/GP)-1)
    d = ((GS*dp)+ds)/(GS+1)
   
    Mdfl = fckAjust*bfl*hfl*(d-0.5*hfl)
 
    If Mdfl > MdAjust Then
    MiD1 = MdAjust/(fckAjust*bfl*d*d)
    LN = 1-(2*MiD1)
    Wd = 1 - (Power (LN,(1/2)))
    Rcc1 = fckAjust*bfl*Ybloco
    AS2 = Rcc1/(4350*(1+GS))
    AP2 = (GS*AS2*4350)/(cp*78.2608)
    BetaX = 1.25*Wd
    Ybloco = Wd * d
        End If
 
 
    If Mdfl<MdAjust Then
    Rcc1 = fckAjust*(bfl-bw)*hfl    'Rc1
    Md1 = (d-0.5*hfl)*Rcc1 'Md1
    DeltaMd = MdAjust-Md1         'Md2
    MiD2 = DeltaMd/(fckAjust*bw*d*d) 'mi d2
    LN = 1-(2*MiD2)
    Wd = 1 - (Power (LN,(1/2)))  'Omega d2
    Rcc2 = Wd*d*bw*fckAjust  'Rc2
    AS2 = (Rcc1+Rcc2)/((1+GS)*4350)
    AP2 = GS*AS2*4350/(78.2608*cp)
    BetaX = 1.25*Wd
    Ybloco = Wd * d
    End If
     
 
    Label1.Text = NumberFormat (AS2,0,2)
    Label2.Text = NumberFormat (AP2,0,2)
    Label3.Text = NumberFormat (BetaX,0,3)
    Label8.Text = NumberFormat (Ybloco,0,2)

    If BetaX < BetaXLimite Then Label10.TextColor=Colors.Green
    If BetaX > BetaXLimite Then Label10.TextColor=Colors.Red
    If BetaX < BetaXLimite Then Label10.Text = "Ok... Armadura simples"
    If BetaX > BetaXLimite Then Label10.Text = "ATENÇÃO - ALTERAR SEÇÃO"
 
 
    Label21.Visible=True
    Label22.Visible=True
    Label23.Visible=True
    Label24.Visible=True
    Label25.Visible=True
 
    Label21.Text= "βx Limite = " & NumberFormat (BetaXLimite,0,3)
    Label22.Text= "βx =" & NumberFormat (BetaX,0,3)
 
    If BetaX < BetaXLimite Then
        Label23.IsInitialized
        Label23.TextColor=Colors.Green
        Label23.Text = "OK... βx < βx Limite"
        Label24.Text= NumberFormat (AS2,0,2)
        Label25.Text= NumberFormat (AP2,0,2)
    Else
        Label23.IsInitialized
        Label23.TextColor=Colors.Red
        Label23.Text = "Erro... βx > βx Limite... Altere Seção"
    End If
 
    Label12.Text = NumberFormat (Mdfl,0,2)
    Label14.Text = NumberFormat (MiD1,0,6)
    Label15.Text = NumberFormat (Wd,0,6)
[code/]
[/QUOTE]
 

Cableguy

Expert
Licensed User
Longtime User
então muda o código do evento hasfocus para o evento textchanged
 

Cableguy

Expert
Licensed User
Longtime User
um pouco mais detalhado...
em cada edittext usa a propriedade Tag como:
edittext1.tag = "bfl"

depois no textchanged:

B4X:
Sub EditText_textChanged (oldtext as string, newtext as string)
dim edt as edittext=sender
select sender.tag
case bfl
bfl = newtext 'bfl
case hfl = newText 'hfl
....
end select

End Sub
 
Top