Jump to content
Sign in to follow this  
Pedro

Primeiro Code

Recommended Posts

Pedro    1
Pedro

Public Class Calc
   Dim Calc(0 To 2) As String
   Private Function Somar(ByVal x As Long, ByVal y As Long) As Long
       Somar = x + y
   End Function
   Private Function Subtrair(ByVal x As Long, ByVal y As Long) As Long
       Subtrair = x - y
   End Function
   Private Function Multiplicar(ByVal x As Long, ByVal y As Long) As Long
       Multiplicar = x * y
   End Function
   Private Function Dividir(ByVal x As Long, ByVal y As Long) As Long
       Dividir = x / y
   End Function

   Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
       TextBoxCalc.Text = TextBoxCalc.Text & 7
   End Sub

   Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
       TextBoxCalc.Text = TextBoxCalc.Text & 8
   End Sub
   Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
       TextBoxCalc.Text = TextBoxCalc.Text & 9
   End Sub
   Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
       TextBoxCalc.Text = TextBoxCalc.Text & 6
   End Sub
   Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
       TextBoxCalc.Text = TextBoxCalc.Text & 5
   End Sub
   Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
       TextBoxCalc.Text = TextBoxCalc.Text & 4
   End Sub
   Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
       TextBoxCalc.Text = TextBoxCalc.Text & 3
   End Sub
   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
       TextBoxCalc.Text = TextBoxCalc.Text & 2
   End Sub
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       TextBoxCalc.Text = TextBoxCalc.Text & 1
   End Sub

   Public Sub ButtonAdicao_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAdicao.Click
       If Len(TextBoxCalc.Text) >= 1 Then
           Calc(0) = TextBoxCalc.Text
           Calc(1) = "1"
           TextBoxCalc.Text = ""
       End If
   End Sub
   Private Sub ButtonSubtracao_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSubtracao.Click
       If Len(TextBoxCalc.Text) >= 1 Then
           Calc(0) = TextBoxCalc.Text
           Calc(1) = "2"
           TextBoxCalc.Text = ""
       End If
   End Sub
   Private Sub ButtonMultiplicacao_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonMultiplicacao.Click
       If Len(TextBoxCalc.Text) >= 1 Then
           Calc(0) = TextBoxCalc.Text
           Calc(1) = "3"
           TextBoxCalc.Text = ""
       End If
   End Sub
   Private Sub ButtonDivisao_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDivisao.Click
       If Len(TextBoxCalc.Text) >= 1 Then
           Calc(0) = TextBoxCalc.Text
           Calc(1) = "4"
           TextBoxCalc.Text = ""
       End If
   End Sub

   Private Sub ButtonIgual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonIgual.Click
       If Len(TextBoxCalc.Text) >= 1 Then
           Calc(2) = TextBoxCalc.Text
           If Calc(0) And Calc(1) And Calc(2) Then
               Select Case Calc(1)
                   Case "1"
                       TextBoxCalc.Text = Somar(Calc(0), Calc(2))
                   Case "2"
                       TextBoxCalc.Text = Subtrair(Calc(0), Calc(2))
                   Case "3"
                       TextBoxCalc.Text = Multiplicar(Calc(0), Calc(2))
                   Case "4"
                       TextBoxCalc.Text = Dividir(Calc(0), Calc(2))
               End Select
           End If
       End If
   End Sub

   Private Sub ButtonC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonC.Click
       Calc(0) = ""
       Calc(1) = ""
       Calc(2) = ""
       TextBoxCalc.Text = ""

   End Sub
End Class

Eu tava programando C++, porém VB atende mais o que quero (programas "bonitos") e ai mudei pra ele. Acho que não dá pra copilar isso porque falta o design, mais vejam ai o code, se tá bem estruturado, se usei as funções certas. Agora resta saber se eu vou conseguir mexer com XML e .ini ;P

Share this post


Link to post
Share on other sites
Raphael Carnaúba    1
Raphael Carnaúba

Interessante pedro, poderia postar uma screenshot de como ficou seu programa ? :)

 

Parabens aí, mais não seria segundo code ? o primeiro foi em C++ :D:D:D

Share this post


Link to post
Share on other sites
Deragon    25
Deragon

pedro

acho que copila sim, pq o VB já interpreta Button_x como um botão...

olhando não vejo nenhum problema

lendo o código percebi que tem os botões de números de 1 a 9, onde foi parar o 0 ? xD

ficou legal seu código...

já tentei VB, êta coisa difícil sô

Share this post


Link to post
Share on other sites
Raphael Carnaúba    1
Raphael Carnaúba

Deragon, 0 é 0, pra que usar-lo? :P vai somar 1 + 0? xD

Share this post


Link to post
Share on other sites
Deragon    25
Deragon

mas tipo, e se o cara quer fazer 10+10 ? nessa calculadora teria que fazer 9+9+2

Share this post


Link to post
Share on other sites
Boleta    1
Boleta

Hehe, muito bom para um primeiro code.

Quando aprofundar mais um pouco, aconselho você a começar a usar Programação Orientada a Objetos, nesta calculadora mesmo. Além disso, você pode implementar um pouco mais, colocando funções como uso do teclado e de outras operações :).

 

Abraços.

Share this post


Link to post
Share on other sites
Sayfor    0
Sayfor

É isso aí! Aqui vai uma dica, nomeie as variáveis com nomes significantes e sempre faça seu código estruturado, pois se houver erros é mil vezes mais fácil de achar ^.-

Share this post


Link to post
Share on other sites
Pedro    1
Pedro

lol, eu fucking esqueci o número 0 XD

 

Quando aprofundar mais um pouco, aconselho você a começar a usar Programação Orientada a Objetos, nesta calculadora mesmo. Além disso, você pode implementar um pouco mais, colocando funções como uso do teclado e de outras operações

Tenho que agradecer MUIITO você, porque eu aprendi tudo isso ai nas suas aulas, gostei demais :*

 

Vou tentar melhorar a calculadora em geral, enquanto vou aprendendo.

Parabens aí, mais não seria segundo code ? o primeiro foi em C++

mais é o primeiro em vb xD

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×