Announcement

Collapse
No announcement yet.

Adding text values in Template Wizard

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding text values in Template Wizard

    Hello All,

    I was wondering if it is possible to combine 2 or more text fields in template wizard to get a result. For example, 10 + 20 = 30. I saw an example in the documentation but it adds the values when you exit the field every time. I tried OnChange but got an error. Thanks in advance.

    Shotski

    This is the script i used:

    Dim globalTotalValue1

    Sub addValue(Sender)

    calculate(CInt(Sender.Text))

    End sub

    Function calculate(value)

    globalTotalValue1 = globalTotalValue1 + Value

    C1_TOTAL.Text = globalTotalValue1

    End Function

    Sub clearClick(Sender)

    globalTotalValue1 = 0

    C1_GOLD.Text = ""

    C1_SILVER.Text = ""

    C1_BRONZE.Text = ""

    C1_TOTAL.Text = ""

    End sub

  • #2
    You have to check if Sender.Text is a numeric value before trying to convert it to Integer. And if it's empty, set it to 0

    Comment


    • #3
      Do you know what the syntax for that would be?

      Comment


      • #4
        Code:
        Dim globalTotalValue1
        
        Sub addValue(Sender)
        
        If Sender.Text = "" Then
        
                  Sender.Text = 0
        
        End If
        
        If IsNumeric(Sender.Text) Then
          
             calculate(CInt(Sender.Text))
        
        End If
        
        End sub
        
        Function calculate(value)
        
        globalTotalValue1 = globalTotalValue1 + Value
        
        C1_TOTAL.Text = globalTotalValue1
        
        End Function
        
        Sub clearClick(Sender)
        
        globalTotalValue1 = 0
        
        C1_GOLD.Text = ""
        
        C1_SILVER.Text = ""
        
        C1_BRONZE.Text = ""
        
        C1_TOTAL.Text = ""
        
        End sub

        Comment


        • #5
          Thanks Lisandro,

          Is there a way to have the total recalculate if a value changes? For example, if i have 1+1+1 = 3. If i change one of the values to another number let's say i have 1+2+1 the value should be 4 but it displays 5. It seems to be holding on to the last value and adding it on. Is there a way clear that value so that it is not added on.

          shotski

          Comment


          • #6
            Yes, I was going to ask you about that. But I thought you wanted it like that.

            Is simple, forget about the globalTotalValue1. Just add up all values on change.

            Code:
            Sub addValue(Sender)
            If IsNumeric(Sender.Text) Then
                calculate()
            End If
            End sub
            
            
            Sub calculate()
            Dim G,S,B,T
            
            If C1_GOLD.Text = ""  Then
                G = 0
            End If
            
            if IsNumeric(C1_GOLD.Text) Then
                G = CInt(C1_GOLD.Text)
            End If
            
            If C1_SILVER.Text = "" Then
                S = 0
            End If
            
            if IsNumeric(C1_SILVER.Text) Then
                S = CInt(C1_SILVER.Text)
            End If
            
            If C1_BRONZE.Text = "" Then
                B = 0
            End If
            
            if IsNumeric(C1_BRONZE.Text) Then
                B = CInt(C1_BRONZE.Text)
            End If
            
            T = G + S + B
            
            C1_TOTAL.Text = T
            
            End Sub
            
            
            Sub clearClick(Sender)
            C1_GOLD.Text = ""
            C1_SILVER.Text = ""
            C1_BRONZE.Text = ""
            C1_TOTAL.Text = ""
            End sub
            Last edited by Lisandro Tapia; 12-04-2017, 04:20 AM.

            Comment


            • #7
              Thanks so much Lisandro!! Works like a charm!!!

              Comment

              Working...
              X