If Auwahl mit Combobox
- VB.NET
Sie verwenden einen veralteten Browser (%browser%) mit Sicherheitsschwachstellen und können nicht alle Funktionen dieser Webseite nutzen.
Hier erfahren Sie, wie einfach Sie Ihren Browser aktualisieren können.
Hier erfahren Sie, wie einfach Sie Ihren Browser aktualisieren können.
Es gibt 35 Antworten in diesem Thema. Der letzte Beitrag () ist von RodFromGermany.
-
-
brembo00 schrieb:
jedoch schritt für schritt und schaue wann das Programm aussteigt .
Kannst du inzwischen damit umgehen? - hast du inzwischen das Lokal-Fenster gefunden (oder was immer du mit "da unten im Video" gemeint hast)? -
Hallo,
Also derzeit klappt es wunderbar wenn ich in der Combobox eine auswahl treffe !
WIe gesagt suche ich gerade eine lösung zum löschen aller Textboxen und Label.
Dan sehe ich es noch besser.
Haltepunkt muß ich noc mehr zeit verbringen .
Habe ihn an verschieden stellen gesetzt ,medlung Haltepunkt erreicht:Combobox1
Derzeit habe ich das so gemacht .
Visual Basic-Quellcode
- Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
- Dim Auswahl As String = ComboBox1.Text
- If Auswahl = "111" Then : TextBox1.Text = "37" : TextBox2.Text = "9"
- TextBox3.Text = "28" : TextBox4.Text = "8"
- TextBox5.Text = "34" : TextBox6.Text = "18"
- TextBox7.Text = "33" : TextBox8.Text = "25"
- TextBox9.Text = "30" : TextBox10.Text = "29"
- TextBox11.Text = "29" : TextBox12.Text = "36"
- TextBox13.Text = "26" : TextBox14.Text = "38"
- TextBox15.Text = "38" : TextBox16.Text = "11"
- End If
- If Auswahl = "222" Then : TextBox1.Text = "6" : TextBox2.Text = "7"
- TextBox3.Text = "28" : TextBox4.Text = "8"
- TextBox5.Text = "34" : TextBox6.Text = "18"
- TextBox7.Text = "33" : TextBox8.Text = "25"
- TextBox9.Text = "30" : TextBox10.Text = "29"
- TextBox11.Text = "29" : TextBox12.Text = "36"
- TextBox13.Text = "26" : TextBox14.Text = "38"
- TextBox15.Text = "38" : TextBox16.Text = "11"
- End If
- Dim a = Double.Parse(TextBox1.Text)
- Dim b = Double.Parse(TextBox2.Text)
- Dim c = Double.Parse(TextBox3.Text)
- Dim d = Double.Parse(TextBox4.Text)
- Dim h = Double.Parse(TextBox5.Text)
- Dim f = Double.Parse(TextBox6.Text)
- Dim g = Double.Parse(TextBox7.Text)
- Dim i = Double.Parse(TextBox8.Text)
- Dim j = Double.Parse(TextBox9.Text)
- Dim k = Double.Parse(TextBox10.Text)
- Dim l = Double.Parse(TextBox11.Text)
- Dim m = Double.Parse(TextBox12.Text)
- Dim n = Double.Parse(TextBox13.Text)
- Dim o = Double.Parse(TextBox14.Text)
- Dim p = Double.Parse(TextBox15.Text)
- Dim q = Double.Parse(TextBox16.Text)
- Dim res1 = a / b
- Dim res2 = c / d
- Dim res3 = h / f
- Dim res4 = g / i
- Dim res5 = j / k
- Dim res6 = l / m
- Dim res7 = n / o
- Dim res8 = p / q
- Dim res10 = res1 * res2
- Dim res11 = res1 * res3
- Label9.Text = res1.ToString("0.###")
- Label10.Text = res10.ToString("0.###")
- Label11.Text = res11.ToString("0.###")
- Label12.Text = CStr(CDbl(res1.ToString) * CDbl(res4.ToString("0.#")))
- Label13.Text = CStr(CDbl(res1.ToString) * CDbl(res5.ToString("0.###")))
- Label14.Text = CStr(CDbl(res1.ToString) * CDbl(res6.ToString("0.###")))
- Label15.Text = CStr(CDbl(res1.ToString) * CDbl(res7.ToString("0.###")))
- Label16.Text = CStr(CDbl(res1.ToString) * CDbl(res8.ToString("0.###")))
- End Sub
- End Class
-
brembo00 schrieb:
VB.NET-Quellcode
- Label11.Text = res11.ToString("0.###")
- Label12.Text = CStr(CDbl(res1.ToString) * CDbl(res4.ToString("0.#")))
- Label13.Text = CStr(CDbl(res1.ToString) * CDbl(res5.ToString("0.###")))
- Label14.Text = CStr(CDbl(res1.ToString) * CDbl(res6.ToString("0.###")))
- Label15.Text = CStr(CDbl(res1.ToString) * CDbl(res7.ToString("0.###")))
- Label16.Text = CStr(CDbl(res1.ToString) * CDbl(res8.ToString("0.###")))
Die Einzel-Resultate liegen Dir doch als Double-Werte vor.
Rechne gefälligst mit ihnen
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! -
Wird nur noch übertroffen von der Grauenhaftigkeit seiner Kommunikation hier im Forum:
brembo00 schrieb:
Habe ihn an verschieden stellen gesetzt ,medlung Haltepunkt erreicht:Combobox1
(Was immer es bedeutet - Sieht mir zumindest nicht so aus, als hätte er inzwischen gelernt, einen Haltepunkt zu setzen, und seinen Code durchzusteppen.)
-
-
Das ganze klappt jetzt.
Nun habe ich noch ein Problem !
Ich will wenn in Textbox2 ein wert der höher als 0 ist das eine andere Formel vewerwendet wird !
geht um res5 /res6 / res7
Was mache ich da falsch ?
VB.NET-Quellcode
- Public Class Form1
- Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
- Dim Auswahl As String = ComboBox1.Text
- If Auswahl = "VW Golf VII 1.2TSI 86PS/ Schalt" Then : TextBox1.Text = "4,056" : TextBox2.Text = "4"
- TextBox3.Text = "3,769" 'Gang1
- TextBox4.Text = "1,955" 'Gang2
- TextBox5.Text = "1,281" 'Gang3
- TextBox6.Text = "0,881" 'Gang4
- TextBox7.Text = "0,673" 'Gang5
- TextBox8.Text = "0" 'Gang6
- TextBox9.Text = "0" 'Gang7
- End If
- If Auswahl = "VW Golf VII 1.2TSI 105PS/Schalt" Then : TextBox1.Text = "4,056" : TextBox2.Text = "0"
- TextBox3.Text = "3,615" 'Gang1
- TextBox4.Text = "1,947" 'Gang2
- TextBox5.Text = "1,281" 'Gang3
- TextBox6.Text = "0,973" 'Gang4
- TextBox7.Text = "0,778" 'Gang5
- TextBox8.Text = "0,646" 'Gang6
- TextBox9.Text = "0" 'Gang7
- End If
- If Auswahl = "VW Golf VII 1.2TSI 110PS/Schalt" Then : TextBox1.Text = "4,056" : TextBox2.Text = "0"
- TextBox3.Text = "3,615" 'Gang1
- TextBox4.Text = "1,947" 'Gang2
- TextBox5.Text = "1,281" 'Gang3
- TextBox6.Text = "0,973" 'Gang4
- TextBox7.Text = "0,778" 'Gang5
- TextBox8.Text = "0,646" 'Gang6
- TextBox9.Text = "0" 'Gang7
- End If
- If Auswahl = "VW Golf VII 1.4TSI 122PS/Schalt" Then : TextBox1.Text = "3,647" : TextBox2.Text = "0"
- TextBox3.Text = "3,778" 'Gang1
- TextBox4.Text = "2,063" 'Gang2
- TextBox5.Text = "1,455" 'Gang3
- TextBox6.Text = "1,1073" 'Gang4
- TextBox7.Text = "0,875" 'Gang5
- TextBox8.Text = "0,733" 'Gang6
- TextBox9.Text = "0" 'Gang7
- End If
- If Auswahl = "VW Golf VII 1.4TSI 125PS/Schalt" Then : TextBox1.Text = "3,647" : TextBox2.Text = "0"
- TextBox3.Text = "3,778" 'Gang1
- TextBox4.Text = "2,063" 'Gang2
- TextBox5.Text = "1,455" 'Gang3
- TextBox6.Text = "1,1073" 'Gang4
- TextBox7.Text = "0,875" 'Gang5
- TextBox8.Text = "0,733" 'Gang6
- TextBox9.Text = "0" 'Gang7
- End If
- '###############################################################################################
- '###############################################################################################
- Dim a = Double.Parse(TextBox1.Text) 'Achsantrieb1
- Dim b = Double.Parse(TextBox2.Text) 'Achsantrieb2
- Dim c = Double.Parse(TextBox3.Text) 'Gang1
- Dim d = Double.Parse(TextBox4.Text) 'Gang2
- Dim h = Double.Parse(TextBox5.Text)
- Dim f = Double.Parse(TextBox6.Text)
- Dim g = Double.Parse(TextBox7.Text)
- Dim i = Double.Parse(TextBox8.Text)
- Dim j = Double.Parse(TextBox9.Text)
- If TextBox2.Text <= "0" Then
- Dim res1 = a * c
- Dim res2 = a * d
- Dim res3 = a * h
- Dim res4 = a * f
- Dim res5 = a * g '2 Achsübersetzung
- Dim res6 = a * i '2 Achsübersetzung
- Dim res7 = a * j '2 Achsübersetzung
- If TextBox2.Text >= "0" Then
- Dim res1 = a * c
- Dim res2 = a * d
- Dim res3 = a * h
- Dim res4 = a * f
- Dim res5 = b * g '2 Achsübersetzung
- Dim res6 = b * i '2 Achsübersetzung
- Dim res7 = b * j '2 Achsübersetzung
- End If
- TextBox17.Text = res1.ToString(CInt("0.###"))
- TextBox16.Text = res2.ToString("0.###")
- TextBox15.Text = res3.ToString("0.###")
- TextBox14.Text = res4.ToString("0.###")
- TextBox13.Text = res5.ToString("0.###")
- TextBox12.Text = res6.ToString("0.###")
- TextBox11.Text = res7.ToString("0.###")
- End Sub
- End Class
-
ganz klappt es leider noch nicht,weis einer warum ?
Visual Basic-Quellcode
- If TextBox2.Text <= "0" Then
- Dim res1 = a * c
- Dim res2 = a * d
- Dim res3 = a * h
- Dim res4 = a * f
- Dim res5 = a * g '2 Achsübersetzung
- Dim res6 = a * i '2 Achsübersetzung
- Dim res7 = a * j '2 Achsübersetzung
- ElseIf TextBox2.Text >= "0" Then
- Dim res1 = a * c
- Dim res2 = a * d
- Dim res3 = a * h
- Dim res4 = a * f
- Dim res5 = b * g '2 Achsübersetzung
- Dim res6 = b * i '2 Achsübersetzung
- Dim res7 = b * j '2 Achsübersetzung
- TextBox17.Text = res1.ToString("0.###")
- TextBox16.Text = res2.ToString("0.###")
- TextBox15.Text = res3.ToString("0.###")
- TextBox14.Text = res4.ToString("0.###")
- TextBox13.Text = res5.ToString("0.###")
- TextBox12.Text = res6.ToString("0.###")
- TextBox11.Text = res7.ToString("0.###")
- TextBox19.Text = res3.ToString("0.###")
- End If
-
Schalt mal Option Strict On!
-
Warum rechnet der nicht richtig in einem Code ?
Mit sage ich ihm doch wenn der Wert in Textbox 2 kleiner als "1" ist soll er anwenden
ist der wert höher als "1" soll er anders rechnen .
So währe es logisch für mich.
Zeigt keinen Fehler an ,aber rechnet falsch -
Zeigt keine Fehler an weil Option Strict auf Off steht. Und ein String kann niemals kleiner oder gleich ein anderer String sein.
Integer.Parse(TextBox2.Text) <= 1
Und für deine "Ich will alle Leeren"-Funktion, wäre eine Schleife hilfreich.
Siehe auch Me.Controls in dem Zusammenhang. -
Ich habe das versucht kam nicht ganz zurecht,
was haltest du von dem code
Visual Basic-Quellcode
-
ichduersie schrieb:
Schalt mal Option Strict On!
Allein das späte binden
verschlechtert die Lesbarkeit um ein Vielfaches und kann Fehler verursachen. Echt nur ein gut gemeinter Tipp auch wenn die Hälfte deines Quellcodes dann erstmal voll mit Fehlern ist. Option Strict On verhindert viele (deiner) Fehler schon während der Entstehung und meckert sofort rum, sodass viele (dumme) Fehler richtig einfach vermieden werden können.
Hier nochmal 'ne echt gute Website von @ErfinderDesRades: home.arcor.de/eckardahlers/Pro…/Blogs/WarumStrictOn.html
LG -
So ,
ich habe derzeit über 100 Azwahlmöglichkeiten in das Programm eingefplegt und ist wählbar über die Combobox.
Da das einpflegen der werte sehr müsam ist habe ich eine Frage an euch !
Kann man die ganzen werte über eine Excel Datei einlesen ?
In der Spalte A solte sich dann die If Auswahl für die Combpbox befinde.
Z.b. A2 = Auswahl
C2 Textbox1
D2 Textbox2
E2 Textbox4 usw....
Nächste Combobox auswahl währe dann eine Zeile tiefer also A3
C3 wieder Textbox1
D3 wieder Textbox2 usw....
Kann man dann die Datenquelle also das Excel File diekt in die exe miteinbauen ?
Derzeit starte ich das wie gehabt über die Auswahl
Hat das schon mal wer gemacht ?!
Danke im vorraus.
VB.NET-Quellcode
- Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
- Dim Auswahl As String = ComboBox1.Text
- If Auswahl = "111" Then : TextBox1.Text = "37" : TextBox2.Text = "9"
- TextBox3.Text = "28" : TextBox4.Text = "8"
- TextBox5.Text = "34" : TextBox6.Text = "18"
- TextBox7.Text = "33" : TextBox8.Text = "25"
- TextBox9.Text = "30" : TextBox10.Text = "29"
- TextBox11.Text = "29" : TextBox12.Text = "36"
- TextBox13.Text = "26" : TextBox14.Text = "38"
- TextBox15.Text = "38" : TextBox16.Text = "11"
- End If
- If Auswahl = "222" Then : TextBox1.Text = "6" : TextBox2.Text = "7"
- TextBox3.Text = "28" : TextBox4.Text = "8"
- TextBox5.Text = "34" : TextBox6.Text = "18"
- TextBox7.Text = "33" : TextBox8.Text = "25"
- TextBox9.Text = "30" : TextBox10.Text = "29"
- TextBox11.Text = "29" : TextBox12.Text = "36"
- TextBox13.Text = "26" : TextBox14.Text = "38"
- TextBox15.Text = "38" : TextBox16.Text = "11"
- End If
-
Dazu brauch man kein Excelfile, man kann es auch über ein xml File lösen. Das was du vor hast. Bei einem Excelfile hast du das Problem, wenn es jemand löscht und niemand hat ein BU davon sind die Daten weg. Wenn du aber her gehst und Codeseitig das xml-File erstellst mit inhalt und eine Vorhanden überprüfung einbaust kann es nach dem Kompilieren nie verschwinden, da du es immer wenn es nicht das ist Codeseitig erstellst. Der Nachteil ist, das du eine Methode finden musst, um sicher weitere Werte dem File hinzuzfügen ohne erneut das Programm zu Kompilieren müssen.
-
brembo00 schrieb:
über die Auswahl
2 Ansatzpunkte:- keine TextBoxen mehr, sondern ein
DataGridView
, da lassen sich auch ganz easy Tabellen dran binden. - numerische Controls statt Texteingabe.
FallsTextBox
, dannNumericUpDown
oder eine eigeneNumericTextBox
, gugst Du hier.
fallsDataGridView
, dann eine numerische DGV-Column, gugst Du hier.
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! - keine TextBoxen mehr, sondern ein
-
Ähnliche Themen
-
SMarioMasterX - - Sonstige Problemstellungen
-
8 Benutzer haben hier geschrieben
- brembo00 (16)
- RodFromGermany (6)
- ichduersie (5)
- ErfinderDesRades (5)
- Vainamo (1)
- torf160 (1)
- Lord C (1)
- Hobbl (1)