Unconfigured Ad Widget

Collapse

Anúncio

Collapse
No announcement yet.

Somar valores no visual basic

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

  • Font Size
    #1

    Somar valores no visual basic

    Código:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If TextBox7.Enabled = True And TextBox10.Enabled = True Then
    TextBox14.Text = TextBox4.Text * TextBox1.Text
    TextBox16.Text = TextBox5.Text * TextBox2.Text
    TextBox17.Text = TextBox6.Text * TextBox3.Text
    TextBox15.Text = TextBox12.Text * TextBox9.Text
    TextBox18.Text = TextBox11.Text * TextBox8.Text

    TextBox13.Text = (TextBox14.Text) + (TextBox16.Text) + (TextBox17.Text) + (TextBox15.Text) + (TextBox18.Text) & " W"
    MsgBox("A potência real de sua fonte de alimentação é de " & TextBox13.Text)
    End If
    End Sub

    Problema: Se eu colocar 1 + 1 + 1 + 1 + 1 ele dá o resultado: 11111
    Como assim?? Alguem poderia me ajudar?
    "A 3ª guerra mundial está declarada, abra seu LOIC e mande ver "

  • Font Size
    #2
    Tá somando strings e não valores numéricos.
    Quando você soma strings ele só sufixa a segunda na primeira.
    "a"+"b"="ab"
    "1"+"1"="11"
    Faz a conversão pra número e depois converte de novo pra strings.

    Comment


    • Font Size
      #3
      @spiike // Me explica como faz issaê xD! Sou nivel intermediário sabe... fui aprendendo nos dedos(tentando codigos) de variaveis sei poka coisa
      "A 3ª guerra mundial está declarada, abra seu LOIC e mande ver "

      Comment


      • Font Size
        #4
        Cara,se não sabe fazer type-casting e se considera intermediário?Tá de zuera com minha cara?
        Cuidado com esses titulos auto-proclamados guri.
        Le um tutorial básico.Para de copiar código.

        Comment


        • Font Size
          #5
          Você pode fazer assim:
          Código:
          Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          If TextBox7.Enabled = True And TextBox10.Enabled = True Then
          TextBox14.Text = Val(TextBox4.Text) * Val(TextBox1.Text)
          TextBox16.Text = Val(TextBox5.Text) * Val(TextBox2.Text)
          TextBox17.Text = Val(TextBox6.Text) * Val(TextBox3.Text)
          TextBox15.Text = Val(TextBox12.Text) * Val(TextBox9.Text)
          TextBox18.Text = Val(TextBox11.Text) * Val(TextBox8.Text)
          
          TextBox13.Text = Val(TextBox14.Text) + Val(TextBox16.Text) + Val(TextBox17.Text) + Val(TextBox15.Text) + Val((TextBox18.Text) & " W"
          MsgBox("A potência real de sua fonte de alimentação é de " & TextBox13.Text)
          End If
          End Sub

          Comment

          X
          Working...
          X