Rechnung

  • VB.NET

Es gibt 12 Antworten in diesem Thema. Der letzte Beitrag () ist von singu.

    hi

    ich will eine art rechnungsprogramm schreiben.
    nun habe ich aber in problem.
    wenn ich den inhalt der textboxen zusammen rechne kommt dann eine komma zahl raus
    und wenn ich damit dann weiter rechnen will mit einer weiteren komma zahl rechnet er nur das vor dem komma zusammen.
    Wie kann man das ändern?
    entweder das er es schafft mit dem komma zu rechnen oder das er mit dem punkt anstatt nem komma ausgibt?

    hier meine ganzer code

    VB.NET-Quellcode

    1. Public Class Form1
    2. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3. 'TODO: Diese Codezeile lädt Daten in die Tabelle "FirstDataBaseDataSet.Adressen". Sie können sie bei Bedarf verschieben oder entfernen.
    4. Me.AdressenTableAdapter.Fill(Me.FirstDataBaseDataSet.Adressen)
    5. End Sub
    6. Private Sub AdressenBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AdressenBindingNavigatorSaveItem.Click
    7. Me.Validate()
    8. Me.AdressenBindingSource.EndEdit()
    9. Me.TableAdapterManager.UpdateAll(Me.FirstDataBaseDataSet)
    10. End Sub
    11. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    12. TextBox2.Clear()
    13. Dim rnd As New Random
    14. For i As Integer = 0 To 15
    15. If i = 4 Or i = 8 Or i = 12 Then
    16. TextBox2.Text &= "-"
    17. End If
    18. TextBox2.Text &= rnd.Next(0, 9)
    19. Next
    20. End Sub
    21. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    22. TextBox8.Text = Val(TextBox6.Text) * Val(TextBox7.Text)
    23. End Sub
    24. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    25. TextBox12.Text = Val(TextBox10.Text) * Val(TextBox11.Text)
    26. End Sub
    27. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    28. TextBox16.Text = Val(TextBox14.Text) * Val(TextBox15.Text)
    29. End Sub
    30. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    31. TextBox20.Text = Val(TextBox18.Text) * Val(TextBox19.Text)
    32. End Sub
    33. Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    34. TextBox24.Text = Val(TextBox22.Text) * Val(TextBox23.Text)
    35. End Sub
    36. Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
    37. TextBox28.Text = Val(TextBox26.Text) * Val(TextBox27.Text)
    38. End Sub
    39. Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
    40. TextBox32.Text = Val(TextBox30.Text) * Val(TextBox31.Text)
    41. End Sub
    42. Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
    43. TextBox36.Text = Val(TextBox34.Text) * Val(TextBox35.Text)
    44. End Sub
    45. Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
    46. TextBox37.Text = (TextBox8.Text) + (TextBox12.Text) + Val(TextBox16.Text) + Val(TextBox20.Text) + Val(TextBox24.Text) + Val(TextBox28.Text) + Val(TextBox32.Text) + Val(TextBox36.Text)
    47. End Sub
    48. Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
    49. TabPage2.Show()
    50. End Sub
    51. Private Sub BeendenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeendenToolStripMenuItem.Click
    52. Me.Close()
    53. End Sub
    54. Private Sub DruckenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DruckenToolStripMenuItem.Click
    55. End Sub
    56. End Class
    ja hab ich

    VB.NET-Quellcode

    1. Public Class Form1
    2. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3. 'TODO: Diese Codezeile lädt Daten in die Tabelle "FirstDataBaseDataSet.Adressen". Sie können sie bei Bedarf verschieben oder entfernen.
    4. Me.AdressenTableAdapter.Fill(Me.FirstDataBaseDataSet.Adressen)
    5. End Sub
    6. Private Sub AdressenBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AdressenBindingNavigatorSaveItem.Click
    7. Me.Validate()
    8. Me.AdressenBindingSource.EndEdit()
    9. Me.TableAdapterManager.UpdateAll(Me.FirstDataBaseDataSet)
    10. End Sub
    11. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    12. TextBox2.Clear()
    13. Dim rnd As New Random
    14. For i As Integer = 0 To 15
    15. If i = 4 Or i = 8 Or i = 12 Then
    16. TextBox2.Text &= "-"
    17. End If
    18. TextBox2.Text &= rnd.Next(0, 9)
    19. Next
    20. End Sub
    21. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    22. TextBox8.Text = CDbl(TextBox6.Text) * CDbl(TextBox7.Text)
    23. End Sub
    24. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    25. TextBox12.Text = CDbl(TextBox10.Text) * CDbl(TextBox11.Text)
    26. End Sub
    27. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    28. TextBox16.Text = CDbl(TextBox14.Text) * CDbl(TextBox15.Text)
    29. End Sub
    30. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    31. TextBox20.Text = CDbl(TextBox18.Text) * CDbl(TextBox19.Text)
    32. End Sub
    33. Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    34. TextBox24.Text = CDbl(TextBox22.Text) * CDbl(TextBox23.Text)
    35. End Sub
    36. Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
    37. TextBox28.Text = CDbl(TextBox26.Text) * CDbl(TextBox27.Text)
    38. End Sub
    39. Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
    40. TextBox32.Text = CDbl(TextBox30.Text) * CDbl(TextBox31.Text)
    41. End Sub
    42. Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
    43. TextBox36.Text = CDbl(TextBox34.Text) * CDbl(TextBox35.Text)
    44. End Sub
    45. Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
    46. TextBox37.Text = CDbl(TextBox8.Text) + CDbl(TextBox12.Text) + CDbl(TextBox16.Text) + CDbl(TextBox20.Text) + CDbl(TextBox24.Text) + CDbl(TextBox28.Text) + CDbl(TextBox32.Text) + CDbl(TextBox36.Text)
    47. End Sub
    48. Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
    49. TabPage2.Show()
    50. End Sub
    51. Private Sub BeendenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeendenToolStripMenuItem.Click
    52. Me.Close()
    53. End Sub
    54. Private Sub DruckenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DruckenToolStripMenuItem.Click
    55. End Sub
    56. End Class



    die textboxen sind doch leer
    Bau mal folgendes ein. Du musst es noch an die Anzahl der TextBoxes anpassen.

    VB.NET-Quellcode

    1. Public Class Form1
    2. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3. Dim value1 As Double = 0
    4. Dim value2 As Double = 0
    5. Double.TryParse(Me.TextBox1.Text, value1)
    6. Double.TryParse(Me.TextBox2.Text, value2)
    7. Me.TextBox3.Text = CStr(value1 + value2)
    8. End Sub
    9. End Class
    okay danke jetzt gehts

    so sieht jetzt mein ganzer code aus

    VB.NET-Quellcode

    1. Public Class Form1
    2. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3. 'TODO: Diese Codezeile lädt Daten in die Tabelle "FirstDataBaseDataSet.Adressen". Sie können sie bei Bedarf verschieben oder entfernen.
    4. Me.AdressenTableAdapter.Fill(Me.FirstDataBaseDataSet.Adressen)
    5. End Sub
    6. Private Sub AdressenBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AdressenBindingNavigatorSaveItem.Click
    7. Me.Validate()
    8. Me.AdressenBindingSource.EndEdit()
    9. Me.TableAdapterManager.UpdateAll(Me.FirstDataBaseDataSet)
    10. End Sub
    11. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    12. TextBox2.Clear()
    13. Dim rnd As New Random
    14. For i As Integer = 0 To 15
    15. If i = 4 Or i = 8 Or i = 12 Then
    16. TextBox2.Text &= "-"
    17. End If
    18. TextBox2.Text &= rnd.Next(0, 9)
    19. Next
    20. End Sub
    21. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    22. TextBox8.Text = CDbl(TextBox6.Text) * CDbl(TextBox7.Text)
    23. End Sub
    24. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    25. TextBox12.Text = CDbl(TextBox10.Text) * CDbl(TextBox11.Text)
    26. End Sub
    27. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    28. TextBox16.Text = CDbl(TextBox14.Text) * CDbl(TextBox15.Text)
    29. End Sub
    30. Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    31. TextBox20.Text = CDbl(TextBox18.Text) * CDbl(TextBox19.Text)
    32. End Sub
    33. Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    34. TextBox24.Text = CDbl(TextBox22.Text) * CDbl(TextBox23.Text)
    35. End Sub
    36. Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
    37. TextBox28.Text = CDbl(TextBox26.Text) * CDbl(TextBox27.Text)
    38. End Sub
    39. Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
    40. TextBox32.Text = CDbl(TextBox30.Text) * CDbl(TextBox31.Text)
    41. End Sub
    42. Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
    43. TextBox36.Text = CDbl(TextBox34.Text) * CDbl(TextBox35.Text)
    44. End Sub
    45. Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
    46. Dim value1 As Double = 0
    47. Dim value2 As Double = 0
    48. Dim value3 As Double = 0
    49. Dim value4 As Double = 0
    50. Dim value5 As Double = 0
    51. Dim value6 As Double = 0
    52. Dim value7 As Double = 0
    53. Dim value8 As Double = 0
    54. Double.TryParse(Me.TextBox8.Text, value1)
    55. Double.TryParse(Me.TextBox12.Text, value2)
    56. Double.TryParse(Me.TextBox16.Text, value3)
    57. Double.TryParse(Me.TextBox20.Text, value4)
    58. Double.TryParse(Me.TextBox24.Text, value5)
    59. Double.TryParse(Me.TextBox28.Text, value6)
    60. Double.TryParse(Me.TextBox32.Text, value7)
    61. Double.TryParse(Me.TextBox36.Text, value8)
    62. Me.TextBox37.Text = CStr(value1 + value2 + value3 + value4 + value5 + value6 + value7 + value8)
    63. End Sub
    64. Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
    65. TabPage2.Show()
    66. End Sub
    67. Private Sub BeendenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BeendenToolStripMenuItem.Click
    68. Me.Close()
    69. End Sub
    70. Private Sub DruckenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DruckenToolStripMenuItem.Click
    71. End Sub
    72. End Class



    und nochmal danke schön!
    Ich würde das ganze mit Double.TryParse auch in den anderen Button-Click Events machen. Und stell am besten die Option Strict auf On, das machst du über die Projekteigenschaften -> Kompilieren, weil so wird dir in deinem Code gezeigt wo du konvertieren musst