If Auwahl mit Combobox

  • VB.NET

Es gibt 35 Antworten in diesem Thema. Der letzte Beitrag () ist von RodFromGermany.

    If Auwahl mit Combobox

    Hallo,
    ich komme gerade nicht ganz weiter.
    Ich will vorgegebene Zahlen in eine Textbox schreiben.

    Das der Code zu länge wär für eine zeile habe ich mehrer ,gelsen wird aber immer nur genau die erste :(
    Schreibe ich den code in einer Zeile wird es klappen !!



    Visual Basic-Quellcode

    1. Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    2. Dim Auswahl As String = ComboBox1.Text
    3. If Auswahl = "Gang Getriebe : FDP" Then TextBox1.Text = "17" : TextBox2.Text = " 9"
    4. TextBox3.Text = "28" : TextBox4.Text = "8"
    5. TextBox5.Text = "34" : TextBox6.Text = "18"
    6. TextBox7.Text = "33" : TextBox8.Text = "25"
    7. TextBox9.Text = "30" : TextBox10.Text = "29"
    8. TextBox11.Text = "29" : TextBox12.Text = "36"
    9. TextBox13.Text = "26" : TextBox14.Text = "38"
    10. TextBox15.Text = "38" : TextBox16.Text = "11"
    11. If Auswahl = "Gang Getriebe : FRQ" Then TextBox1.Text = "27" : TextBox2.Text = " 9"
    12. TextBox3.Text = "28" : TextBox4.Text = "8"
    13. TextBox5.Text = "34" : TextBox6.Text = "18"
    14. TextBox7.Text = "32" : TextBox8.Text = "26"
    15. TextBox9.Text = "29" : TextBox10.Text = "30"
    16. TextBox11.Text = "29" : TextBox12.Text = "36"
    17. TextBox13.Text = "26" : TextBox14.Text = "38"
    18. TextBox15.Text = "38" : TextBox16.Text = "11"
    Mach doch einfach eine mehrzeilige If-Abfrage:

    VB.NET-Quellcode

    1. ​If Auswahl = "Gang Getriebe : FDP" Then
    2. TextBox1.Text = "17" : TextBox2.Text = " 9"
    3. TextBox3.Text = "28" : TextBox4.Text = "8"
    4. TextBox5.Text = "34" : TextBox6.Text = "18"
    5. TextBox7.Text = "33" : TextBox8.Text = "25"
    6. TextBox9.Text = "30" : TextBox10.Text = "29"
    7. TextBox11.Text = "29" : TextBox12.Text = "36"
    8. TextBox13.Text = "26" : TextBox14.Text = "38"
    9. TextBox15.Text = "38" : TextBox16.Text = "11"
    10. End If
    Habe nun alles geändert,
    Wähle ich das erste If klappt es ,versuche ich ein anderes bekomme ich einen Fehler .

    "Dim a = Double.Parse(TextBox1.Text)" genau hier.
    Ich vermute das hängt mit dem END IF zusammen oder?
    Hier unten habe die Berechnung hinterlegt der einzelnen werte.

    Visual Basic-Quellcode

    1. ublic Class Form1
    2. Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    3. Dim Auswahl As String = ComboBox1.Text
    4. If Auswahl = "Audi B5 S4 2.7T 265PS/6 Gang Schaltgetriebe DSY " Then
    5. TextBox1.Text = "37" : TextBox2.Text = " 9" 'Achsantrieb
    6. TextBox3.Text = "28" : TextBox4.Text = "8" 'Gang 1
    7. TextBox5.Text = "34" : TextBox6.Text = "18" 'Gang 2
    8. TextBox7.Text = "32" : TextBox8.Text = "26" 'Gang 3
    9. TextBox9.Text = "29" : TextBox10.Text = "30" 'Gang 4
    10. TextBox11.Text = "29" : TextBox12.Text = "36" 'Gang 5
    11. TextBox13.Text = "26" : TextBox14.Text = "38" 'Gang 6
    12. TextBox15.Text = "38" : TextBox16.Text = "11" 'Retour Gang
    13. End If
    14. If Auswahl = "Audi B5 S4 2.7T 265PS/6 Gang Schaltgetriebe EDU " Then
    15. TextBox1.Text = "37" : TextBox2.Text = " 9" 'Achsantrieb
    16. TextBox3.Text = "28" : TextBox4.Text = "8" 'Gang 1
    17. TextBox5.Text = "34" : TextBox6.Text = "18" 'Gang 2
    18. TextBox7.Text = "32" : TextBox8.Text = "26" 'Gang 3
    19. TextBox9.Text = "29" : TextBox10.Text = "30" 'Gang 4
    20. TextBox11.Text = "29" : TextBox12.Text = "36" 'Gang 5
    21. TextBox13.Text = "26" : TextBox14.Text = "38" 'Gang 6
    22. TextBox15.Text = "38" : TextBox16.Text = "11" 'Retour Gang
    23. End If
    24. If Auswahl = "Audi B5 S4 2.7T 265PS/6 Gang Schaltgetriebe FRQ " Then
    25. TextBox1.Text = "37" : TextBox2.Text = " 9" 'Achsantrieb
    26. TextBox3.Text = "28" : TextBox4.Text = "8" 'Gang 1
    27. TextBox5.Text = "34" : TextBox6.Text = "18" 'Gang 2
    28. TextBox7.Text = "32" : TextBox8.Text = "26" 'Gang 3
    29. TextBox9.Text = "29" : TextBox10.Text = "30" 'Gang 4
    30. TextBox11.Text = "29" : TextBox12.Text = "36" 'Gang 5
    31. TextBox13.Text = "26" : TextBox14.Text = "38" 'Gang 6
    32. TextBox15.Text = "38" : TextBox16.Text = "11" 'Retour Gang
    33. End If
    34. If Auswahl = "Audi B5 S4 2.7T 265PS/6 Gang Schaltgetriebe FTG " Then
    35. TextBox1.Text = "37" : TextBox2.Text = " 9" 'Achsantrieb
    36. TextBox3.Text = "28" : TextBox4.Text = "8" 'Gang 1
    37. TextBox5.Text = "34" : TextBox6.Text = "18" 'Gang 2
    38. TextBox7.Text = "32" : TextBox8.Text = "26" 'Gang 3
    39. TextBox9.Text = "29" : TextBox10.Text = "30" 'Gang 4
    40. TextBox11.Text = "29" : TextBox12.Text = "36" 'Gang 5
    41. TextBox13.Text = "26" : TextBox14.Text = "38" 'Gang 6
    42. TextBox15.Text = "38" : TextBox16.Text = "11" 'Retour Gang
    43. End If
    44. If Auswahl = "Audi B5 RS4 2.7T 380PS/6 Gang Schaltgetriebe FDP " Then
    45. TextBox1.Text = "37" : TextBox2.Text = " 9" 'Achsantrieb
    46. TextBox3.Text = "28" : TextBox4.Text = "8" 'Gang 1
    47. TextBox5.Text = "34" : TextBox6.Text = "18" 'Gang 2
    48. TextBox7.Text = "33" : TextBox8.Text = "25" 'Gang 3
    49. TextBox9.Text = "30" : TextBox10.Text = "29" 'Gang 4
    50. TextBox11.Text = "29" : TextBox12.Text = "36" 'Gang 5
    51. TextBox13.Text = "26" : TextBox14.Text = "38" 'Gang 6
    52. TextBox15.Text = "38" : TextBox16.Text = "11" 'Retour Gang
    53. End If
    54. If Auswahl = "Audi B5 RS4 2.7T 380PS/6 Gang Schaltgetriebe FTU " Then
    55. TextBox1.Text = "37" : TextBox2.Text = " 9" 'Achsantrieb
    56. TextBox3.Text = "28" : TextBox4.Text = "8" 'Gang 1
    57. TextBox5.Text = "34" : TextBox6.Text = "18" 'Gang 2
    58. TextBox7.Text = "33" : TextBox8.Text = "25" 'Gang 3
    59. TextBox9.Text = "30" : TextBox10.Text = "29" 'Gang 4
    60. TextBox11.Text = "29" : TextBox12.Text = "36" 'Gang 5
    61. TextBox13.Text = "26" : TextBox14.Text = "38" 'Gang 6
    62. TextBox15.Text = "38" : TextBox16.Text = "11" 'Retour Gang
    63. End If
    64. Dim a = Double.Parse(TextBox1.Text)
    65. Dim b = Double.Parse(TextBox2.Text)
    66. Dim c = Double.Parse(TextBox3.Text)
    67. Dim d = Double.Parse(TextBox4.Text)
    68. Dim h = Double.Parse(TextBox5.Text)
    69. Dim f = Double.Parse(TextBox6.Text)
    70. Dim g = Double.Parse(TextBox7.Text)
    71. Dim i = Double.Parse(TextBox8.Text)
    72. Dim j = Double.Parse(TextBox9.Text)
    73. Dim k = Double.Parse(TextBox10.Text)
    74. Dim l = Double.Parse(TextBox11.Text)
    75. Dim m = Double.Parse(TextBox12.Text)
    76. Dim n = Double.Parse(TextBox13.Text)
    77. Dim o = Double.Parse(TextBox14.Text)
    78. Dim p = Double.Parse(TextBox15.Text)
    79. Dim q = Double.Parse(TextBox16.Text)
    80. Dim res1 = a / b
    81. Dim res2 = c / d
    82. Dim res3 = h / f
    83. Dim res4 = g / i
    84. Dim res5 = j / k
    85. Dim res6 = l / m
    86. Dim res7 = n / o
    87. Dim res8 = p / q
    88. Label17.Text = res1.ToString("0.###")
    89. Label19.Text = res2.ToString("0.###")
    90. Label20.Text = res3.ToString("0.###")
    91. Label21.Text = res4.ToString("0.###")
    92. Label22.Text = res5.ToString("0.###")
    93. Label23.Text = res6.ToString("0.###")
    94. Label24.Text = res7.ToString("0.###")
    95. Label25.Text = res8.ToString("0.###")
    96. Dim res10 = (res1) * (res2)
    97. Dim res11 = (res1) * (res3)
    98. Dim res12 = (res1) * (res4)
    99. Dim res13 = (res1) * (res5)
    100. Dim res14 = (res1) * (res6)
    101. Dim res15 = (res1) * (res7)
    102. Dim res16 = (res1) * (res8)
    103. Label39.Text = res10.ToString("0.###")
    104. Label38.Text = res11.ToString("0.###")
    105. Label37.Text = res12.ToString("0.###")
    106. Label36.Text = res13.ToString("0.###")
    107. Label35.Text = res14.ToString("0.###")
    108. Label34.Text = res15.ToString("0.###")
    109. Label33.Text = res16.ToString("0.###")
    110. End Sub
    111. Private Function res10() As Object
    112. Throw New NotImplementedException
    113. End Function
    114. End Class

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „brembo00“ ()

    brembo00 schrieb:

    was ich falsch gemacht habe
    Du hast deutlich zu viele TextBoxen in Deinem Design.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!

    brembo00 schrieb:

    ich kapier echt nicht wo der Fehler steckt sprich was ich falsch gemacht habe !!!
    Wie bereits gesagt: Untersuche das Problem.
    Bist du die Geschichte mal mit einem Haltepunkt und dann im Einzelschritt durchgegangen?

    Bitte antworte - ich bin recht schnell beleidigt, wenn man mich ignoriert, und es ist auch zu deinem eigenen Schaden, wenn du dir die Haltepunkte entgehen lässt.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Also der Fehler steht genau auf Zeile 175 ,mit dem Fehler Text " Format Exception wurde nicht behandelt "

    Ich habe da die Textboxen zugewissen,kann es sein das er das jetzt durch das End IF nicht mehr fressen will ?
    Das mit dem Haltepunkt versuche ich dann gleich mal aus.
    So ich habe jetzt mal alles über Zeile 74 rausgenommen !
    Es werden die Textboxen nur gefüllt wenn ich die erste IF auswahl wähle.
    Schliesse ich das Debuggen und Starte es wieder dann mit der 2 If auswahl oder einer anderen passiert nichts.

    HAltepunkt setzte ich ,jedoch zeigt er mir da unten nichts an ,was im Video dargestellt ist.

    brembo00 schrieb:

    Zeile 175
    von 132 möglichen Zeilen?
    Hier gibt es kein Video.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!
    Upps sah es jetzt erst ,meinte ab zeile 75 :)

    VB.NET-Quellcode

    1. Public Class Form1
    2. Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    3. Dim Auswahl As String = ComboBox1.Text
    4. If Auswahl = "Audi B5 S4 2.7T 265PS/6 Gang Schaltgetriebe DSY " Then
    5. TextBox1.Text = "37" : TextBox2.Text = " 9" 'Achsantrieb
    6. TextBox3.Text = "28" : TextBox4.Text = "8" 'Gang 1
    7. TextBox5.Text = "34" : TextBox6.Text = "18" 'Gang 2
    8. TextBox7.Text = "32" : TextBox8.Text = "26" 'Gang 3
    9. TextBox9.Text = "29" : TextBox10.Text = "30" 'Gang 4
    10. TextBox11.Text = "29" : TextBox12.Text = "36" 'Gang 5
    11. TextBox13.Text = "26" : TextBox14.Text = "38" 'Gang 6
    12. TextBox15.Text = "38" : TextBox16.Text = "11" 'Retour Gang
    13. End If
    14. If Auswahl = "Audi B5 S4 2.7T 265PS/6 Gang Schaltgetriebe EDU " Then
    15. TextBox1.Text = "37" : TextBox2.Text = " 9" 'Achsantrieb
    16. TextBox3.Text = "28" : TextBox4.Text = "8" 'Gang 1
    17. TextBox5.Text = "34" : TextBox6.Text = "18" 'Gang 2
    18. TextBox7.Text = "32" : TextBox8.Text = "26" 'Gang 3
    19. TextBox9.Text = "29" : TextBox10.Text = "30" 'Gang 4
    20. TextBox11.Text = "29" : TextBox12.Text = "36" 'Gang 5
    21. TextBox13.Text = "26" : TextBox14.Text = "38" 'Gang 6
    22. TextBox15.Text = "38" : TextBox16.Text = "11" 'Retour Gang
    23. End If
    24. If Auswahl = "Audi B5 S4 2.7T 265PS/6 Gang Schaltgetriebe FRQ " Then
    25. TextBox1.Text = "37" : TextBox2.Text = " 9" 'Achsantrieb
    26. TextBox3.Text = "28" : TextBox4.Text = "8" 'Gang 1
    27. TextBox5.Text = "34" : TextBox6.Text = "18" 'Gang 2
    28. TextBox7.Text = "32" : TextBox8.Text = "26" 'Gang 3
    29. TextBox9.Text = "29" : TextBox10.Text = "30" 'Gang 4
    30. TextBox11.Text = "29" : TextBox12.Text = "36" 'Gang 5
    31. TextBox13.Text = "26" : TextBox14.Text = "38" 'Gang 6
    32. TextBox15.Text = "38" : TextBox16.Text = "11" 'Retour Gang
    33. End If
    34. If Auswahl = "Audi B5 S4 2.7T 265PS/6 Gang Schaltgetriebe FTG " Then
    35. TextBox1.Text = "37" : TextBox2.Text = " 9" 'Achsantrieb
    36. TextBox3.Text = "28" : TextBox4.Text = "8" 'Gang 1
    37. TextBox5.Text = "34" : TextBox6.Text = "18" 'Gang 2
    38. TextBox7.Text = "32" : TextBox8.Text = "26" 'Gang 3
    39. TextBox9.Text = "29" : TextBox10.Text = "30" 'Gang 4
    40. TextBox11.Text = "29" : TextBox12.Text = "36" 'Gang 5
    41. TextBox13.Text = "26" : TextBox14.Text = "38" 'Gang 6
    42. TextBox15.Text = "38" : TextBox16.Text = "11" 'Retour Gang
    43. End If
    44. If Auswahl = "Audi B5 RS4 2.7T 380PS/6 Gang Schaltgetriebe FDP " Then
    45. TextBox1.Text = "37" : TextBox2.Text = " 9" 'Achsantrieb
    46. TextBox3.Text = "28" : TextBox4.Text = "8" 'Gang 1
    47. TextBox5.Text = "34" : TextBox6.Text = "18" 'Gang 2
    48. TextBox7.Text = "33" : TextBox8.Text = "25" 'Gang 3
    49. TextBox9.Text = "30" : TextBox10.Text = "29" 'Gang 4
    50. TextBox11.Text = "29" : TextBox12.Text = "36" 'Gang 5
    51. TextBox13.Text = "26" : TextBox14.Text = "38" 'Gang 6
    52. TextBox15.Text = "38" : TextBox16.Text = "11" 'Retour Gang
    53. End If
    54. If Auswahl = "Audi B5 RS4 2.7T 380PS/6 Gang Schaltgetriebe FTU " Then
    55. TextBox1.Text = "37" : TextBox2.Text = " 9" 'Achsantrieb
    56. TextBox3.Text = "28" : TextBox4.Text = "8" 'Gang 1
    57. TextBox5.Text = "34" : TextBox6.Text = "18" 'Gang 2
    58. TextBox7.Text = "33" : TextBox8.Text = "25" 'Gang 3
    59. TextBox9.Text = "30" : TextBox10.Text = "29" 'Gang 4
    60. TextBox11.Text = "29" : TextBox12.Text = "36" 'Gang 5
    61. TextBox13.Text = "26" : TextBox14.Text = "38" 'Gang 6
    62. TextBox15.Text = "8" : TextBox16.Text = "11" 'Retour Gang
    63. End If
    64. Dim a = Double.Parse(TextBox1.Text)
    65. Dim b = Double.Parse(TextBox2.Text)
    66. Dim c = Double.Parse(TextBox3.Text)
    67. Dim d = Double.Parse(TextBox4.Text)
    68. Dim h = Double.Parse(TextBox5.Text)
    69. Dim f = Double.Parse(TextBox6.Text)
    70. Dim g = Double.Parse(TextBox7.Text)
    71. Dim i = Double.Parse(TextBox8.Text)
    72. Dim j = Double.Parse(TextBox9.Text)
    73. Dim k = Double.Parse(TextBox10.Text)
    74. Dim l = Double.Parse(TextBox11.Text)
    75. Dim m = Double.Parse(TextBox12.Text)
    76. Dim n = Double.Parse(TextBox13.Text)
    77. Dim o = Double.Parse(TextBox14.Text)
    78. Dim p = Double.Parse(TextBox15.Text)
    79. Dim q = Double.Parse(TextBox16.Text)
    80. Dim res1 = a / b
    81. Dim res2 = c / d
    82. Dim res3 = h / f
    83. Dim res4 = g / i
    84. Dim res5 = j / k
    85. Dim res6 = l / m
    86. Dim res7 = n / o
    87. Dim res8 = p / q
    88. Label17.Text = res1.ToString("0.###")
    89. Label19.Text = res2.ToString("0.###")
    90. Label20.Text = res3.ToString("0.###")
    91. Label21.Text = res4.ToString("0.###")
    92. Label22.Text = res5.ToString("0.###")
    93. Label23.Text = res6.ToString("0.###")
    94. Label24.Text = res7.ToString("0.###")
    95. Label25.Text = res8.ToString("0.###")
    96. Dim res10 = (res1) * (res2)
    97. Dim res11 = (res1) * (res3)
    98. Dim res12 = (res1) * (res4)
    99. Dim res13 = (res1) * (res5)
    100. Dim res14 = (res1) * (res6)
    101. Dim res15 = (res1) * (res7)
    102. Dim res16 = (res1) * (res8)
    103. Label39.Text = res10.ToString("0.###")
    104. Label38.Text = res11.ToString("0.###")
    105. Label37.Text = res12.ToString("0.###")
    106. Label36.Text = res13.ToString("0.###")
    107. Label35.Text = res14.ToString("0.###")
    108. Label34.Text = res15.ToString("0.###")
    109. Label33.Text = res16.ToString("0.###")
    110. End Sub
    111. Private Function res10() As Object
    112. Throw New NotImplementedException
    113. End Function
    114. End Class

    brembo00 schrieb:

    HAltepunkt setzte ich ,jedoch zeigt er mir da unten nichts an ,was im Video dargestellt ist.
    ich denke, du solltest eher dem nachgehen, als alles nochmal.

    Nun ist die Aussage "jedoch zeigt er mir da unten nichts an ,was im Video dargestellt ist" völlig unklar, aber deutet daraufhin, dass du nicht debuggen kannst.
    Und da hilft nicht, es neu anzufangen, sondern man musses halt lernen.

    Dazu musste das aber besser beschreiben, auf "zeigt unten nichts an, was im Video" kann man dir nichts antworten, was dem abhelfen könnte.

    brembo00 schrieb:

    VB.NET-Quellcode

    1. Dim a = Double.Parse(TextBox1.Text)
    Was ganz genau steht denn in TextBox1 drinn? "Roullade mit Klößen"?
    Mach aus den TextBoxen ==> NumericUpDowns, da stimmt der Typ und die Darstellung.
    Falls Du diesen Code kopierst, achte auf die C&P-Bremse.
    Jede einzelne Zeile Deines Programms, die Du nicht explizit getestet hast, ist falsch :!:
    Ein guter .NET-Snippetkonverter (der ist verfügbar).
    Programmierfragen über PN / Konversation werden ignoriert!