none
How can i alternate two buttons, to send a value to the same textbox? if one button not made the math of the value, then receive the value from the math of the other button? RRS feed

  • Question

  • So, i make this script, that calculates time of concentration of one area, but, the user can user two methods tu calculate, will depende on the informations that he have, if he calculate by one math and click the button to make the math, than send the value to my textbox, but i wanna put a conditional option that, if button1 don't realize the procedure, and the other does, than the value of the math made by button2 can fill the textbox, in other words, i wanna put value receive by textboxes = Value from the button1 or value from the button 2, but the OR doesn't work for this things. This is my script( the script works, but just for button 1):

    Private Sub CALCULAR(sender As Object, e As EventArgs) Handles CALCULAR1.Click, CALCULAR2.Click
    
    
            'Concentration time calculation from button1
            Precip24 = P24.Text
            Compr1 = L1.Text
            Decliv1 = S1.Text
            Manning1 = N1.Text
            Operacao1 = 5.474 * ((Manning1 * Compr1) ^ 0.8) / (Precip24 ^ 0.5 * Decliv1 ^ 0.4)
    
            'textbox receives the value of operacao1
    
            'next time that someone press the button, the value of operacao1 goes to tc2.text and so on
    
            count += 1
            If count >= 11 Then MsgBox("O Limite foi alcançado")
            CType((Resultados.Controls("tc" & count.ToString())), TextBox).Text = Operacao1
    
            If MsgBox("Cálculo realizado com sucesso") Then
                P24.Text = 0
                L1.Text = 0
                S1.Text = 0
                N1.Text = 0
            End If
            'Concetration time calculation from button 2
            RaioH = RH.Text
            Compr2 = L2.Text
            Decliv2 = S2.Text
            Manning2 = N2.Text
            Vel = V.Text
            If V.Text = 0 Then
                Operacao2 = (RaioH ^ (2 / 3) * System.Math.Sqrt(Decliv2)) / Manning2
    
            Else Operacao2 = Compr2 / Vel
    
            End If
    
            If MsgBox("Cálculo realizado com sucesso") Then
                RH.Text = 0
                L2.Text = 0
                S2.Text = 0
                N2.Text = 0
                V.Text = 0
            End If

    Wednesday, June 20, 2018 4:59 PM

Answers

  • if he calculate by one math and click the button to make the math, than send the value to my textbox, but i wanna put a conditional option that, if button1 don't realize the procedure, and the other does, than the value of the math made by button2 can fill the textbox

    Put your textboxes into a collection, such as a List.  Create a Sub that takes one value, the value to be updated into the text box.  In that Sub create a static variable that can be used as a counter to indicate which text box needs to be updated.  Each time the text box is updated, increment the counter.  Call that sub from any place (eg, the button click events) that you want to update the text box.

    Public Class Form1
    
        Public TextBoxes As New List(Of TextBox)
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            TextBoxes.Add(TextBox1)
            TextBoxes.Add(TextBox2)
            TextBoxes.Add(TextBox3)
        End Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ' Do Something
            UpdateText("Result1")
        End Sub
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            ' Do Something
            UpdateText("Result2")
        End Sub
    
        Public Sub UpdateText(NewValue As String)
            Static Counter As Integer = 0
            TextBoxes(Counter).Text = NewValue
            Counter += 1
            If Counter = 3 Then Counter = 0
        End Sub
    
    End Class

    Wednesday, June 20, 2018 10:15 PM

All replies

  • a detail, i have 10 textboxes, then i made a little loop to fill the textboxes by each time that someones click in the button and generates Operacao1, so i need that when Operacao1 isn't made Operacao2 takes over as the value to the textboxes!
    Wednesday, June 20, 2018 5:10 PM
  • if he calculate by one math and click the button to make the math, than send the value to my textbox, but i wanna put a conditional option that, if button1 don't realize the procedure, and the other does, than the value of the math made by button2 can fill the textbox

    Put your textboxes into a collection, such as a List.  Create a Sub that takes one value, the value to be updated into the text box.  In that Sub create a static variable that can be used as a counter to indicate which text box needs to be updated.  Each time the text box is updated, increment the counter.  Call that sub from any place (eg, the button click events) that you want to update the text box.

    Public Class Form1
    
        Public TextBoxes As New List(Of TextBox)
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            TextBoxes.Add(TextBox1)
            TextBoxes.Add(TextBox2)
            TextBoxes.Add(TextBox3)
        End Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            ' Do Something
            UpdateText("Result1")
        End Sub
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            ' Do Something
            UpdateText("Result2")
        End Sub
    
        Public Sub UpdateText(NewValue As String)
            Static Counter As Integer = 0
            TextBoxes(Counter).Text = NewValue
            Counter += 1
            If Counter = 3 Then Counter = 0
        End Sub
    
    End Class

    Wednesday, June 20, 2018 10:15 PM