Code hindern vom Ausführen

  • VB.NET
  • .NET (FX) 4.5–4.8

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

    Code hindern vom Ausführen

    Gibt es eine möglichkeit Code vom ausführen zu verhindern wenn eine If-Abfrage gelungen ist?
    Wenn nicht habe ich ein kleines Problem:

    Quellcode

    1. If ListBox1.Items(ListBox1.SelectedIndex).ToString.Contains("canceled") Then
    2. ListBox1.Items(ListBox1.SelectedIndex) = ListBox1.Items(ListBox1.SelectedIndex).ToString.Replace("canceled", "soon")
    3. End If
    4. If ListBox1.Items(ListBox1.SelectedIndex).ToString.Contains("done") Then
    5. ListBox1.Items(ListBox1.SelectedIndex) = ListBox1.Items(ListBox1.SelectedIndex).ToString.Replace("done", "canceled")
    6. End If
    7. If ListBox1.Items(ListBox1.SelectedIndex).ToString.Contains("live") Then
    8. ListBox1.Items(ListBox1.SelectedIndex) = ListBox1.Items(ListBox1.SelectedIndex).ToString.Replace("live", "done")
    9. End If
    10. If ListBox1.Items(ListBox1.SelectedIndex).ToString.Contains("soon") Then
    11. ListBox1.Items(ListBox1.SelectedIndex) = ListBox1.Items(ListBox1.SelectedIndex).ToString.Replace("soon", "live")
    12. End If



    Theoretisch soll bei jedem Doppelklick ein Teil des Textes eines Items in einer Listbox geändert werden: von soon auf live, von live auf done, von done auf canceled und von canceled wieder auf soon.
    Jedoch wird bei dem Beispiel oben nie soon da stehen weil es direkt wieder von der letzten If-Abfrage geändert wird. Bitte hilft mir, bin am verzweifeln..
    Schonmal was von ElseIf gehört?

    VB.NET-Quellcode

    1. If ListBox1.Items(ListBox1.SelectedIndex).ToString.Contains("canceled") Then
    2. ListBox1.Items(ListBox1.SelectedIndex) = ListBox1.Items(ListBox1.SelectedIndex).ToString.Replace("canceled", "soon")
    3. ElseIf ListBox1.Items(ListBox1.SelectedIndex).ToString.Contains("done") Then
    4. ListBox1.Items(ListBox1.SelectedIndex) = ListBox1.Items(ListBox1.SelectedIndex).ToString.Replace("done", "canceled")
    5. ElseIf ListBox1.Items(ListBox1.SelectedIndex).ToString.Contains("live") Then
    6. ListBox1.Items(ListBox1.SelectedIndex) = ListBox1.Items(ListBox1.SelectedIndex).ToString.Replace("live", "done")
    7. ElseIf ListBox1.Items(ListBox1.SelectedIndex).ToString.Contains("soon") Then
    8. ListBox1.Items(ListBox1.SelectedIndex) = ListBox1.Items(ListBox1.SelectedIndex).ToString.Replace("soon", "live")
    9. End If

    Pi77Bull schrieb:

    VB.NET-Quellcode

    1. ListBox1.Items(ListBox1.SelectedIndex).ToString
    und pack dies in eine separate String-Variable und arbeite mit dieser.

    VB.NET-Quellcode

    1. Dim sel = ListBox1.Items(ListBox1.SelectedIndex).ToString
    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!