Hilfe Endlosschleife



  • Der code funktioniert soweit, nur das menue macht Probleme, denn beim 1. click passiert nix. Beim 2. click läuft die Endlosschleife!
    Warum 😞 😞 😞

    // Declarations added here will be included at the top of the .HPP file

    class __Form1_declspec Form1 : public __Form1_Base
    {
    
        public:
            // add your public instance data here
    
        private:
             WBool _Set_Text(void); // add your private instance data here
             WInt _text_nr;
             WInt _DeuEng;
             WInt _um1;
              WInt i;
        protected:
            // add your protected instance data here
    
    };
    
    // Code added here will be included at the top of the .CPP file
     WBool Form1::_Set_Text(void)
     {
    
        _um1=(_um1+1)%4;
    
      switch (_um1)
        {
         case 0:
               label_1->SetText( "1 Text Position" );
               label_2->SetText( " " );
               label_3->SetText( " " );
               label_4->SetText( " " );
           break;
           case 1:
    
                label_1->SetText( "" );
                label_2->SetText( "2 Text Position " );
                label_3->SetText( "" );
                label_4->SetText( " " );
    
           break;
          case 2:
    
               label_1->SetText( "" );
               label_2->SetText( "" );
               label_3->SetText( "  3 Text Position " );
               label_4->SetText( "  " );
    
          break;
           case 3:
    
                label_1->SetText( " " );
                label_2->SetText( " " );
                label_3->SetText( " " );
                label_4->SetText( "4 Text Position " );
    
          break; 
    
        }
      return FALSE;
       }
    
    //  Include definitions for resources.
    #include "WRes.h"
    
    Form1::Form1()
    {
     _text_nr = 0;          
     _DeuEng  = 0;
     i = 0;
    }
    
    Form1::~Form1()
    {
    
    }
    
    WBool Form1::menu_1_ErstePosition_Click(
        WObject *           source,
        WEventData *        event )
    {
               label_1->SetText( "1 Text Position " );
               label_2->SetText( " " );
               label_3->SetText( " " );
               label_4->SetText( " " );
                 if (_text_nr == 0 & _DeuEng == 0)
    { _um1 = 0;}
        return FALSE;
    }
    
    WBool Form1::menu_1_ZweitePosition_Click(
        WObject *           source,
        WEventData *        event )
    {
                label_1->SetText( " " );
                label_2->SetText( "2 Text Position " );
                label_3->SetText( " " );
                label_4->SetText( " " );
            if (_text_nr == 0 & _DeuEng == 0)
    { _um1 = 1;}
        return FALSE;
    }
    
    WBool Form1::menu_1_DrittePosition_Click(
        WObject *           source,
        WEventData *        event )
    {
                label_1->SetText( " " );
                label_2->SetText( " " );
                label_3->SetText( " 3 Text Position" );
                label_4->SetText( " " );
            if (_text_nr == 0 & _DeuEng == 0)
    { _um1 = 2;}
        return FALSE;
    }
    
    WBool Form1::menu_1_ViertePosition_Click(
        WObject *           source,
        WEventData *        event )
    {
                label_1->SetText( " " );
                label_2->SetText( " " );
                label_3->SetText( " " );
                label_4->SetText( " 4 Text Position" ); 
            if (_text_nr == 0 & _DeuEng == 0)
    {_um1 = 3; }
        return FALSE;
    }
    
    WBool Form1::menu_1_Start_Click(
        WObject *           source,
        WEventData *        event )
    {
    do // ---->ENDLOSSCHLEIFE :rage:  :rage:  :rage:  :rage: 
    {
        if (_text_nr == 1)
    _text_nr =0;
    
     else  
     _text_nr = 1;
    
    _text_nr ++;
    _Set_Text();
    _Set_Text();
    
    }
    
    while (_um1 > 0);
    {
    _DeuEng ++;
    
     _Set_Text();
     if(_um1>=3)
     _Set_Text();
    
    }
    return FALSE;
    
    }
    
    WBool Form1::cb_1_Click(
        WObject *           source,
        WEventData *        event )
    {
        if (_text_nr == 0)
    _text_nr = 0;
    
     else  
     _text_nr = 1;
    
    _Set_Text();
    
     return FALSE;
    }
    


  • hast dir schonmal _uml im debugger angeschaut?

    weiß jetzt bei deiner IDE nicht, aber du arbeitest mit _uml, ohne das sie jemans initialisiert wurde (oder ich habs übersehen), und hat somit einen zufallswert (der mit +1 und % 4 wohl trotzdem immer größer 0 sein wird)



  • ser1al schrieb:

    hast dir schonmal _uml im debugger angeschaut?

    weiß jetzt bei deiner IDE nicht, aber du arbeitest mit _uml, ohne das sie jemans initialisiert wurde (oder ich habs übersehen), und hat somit einen zufallswert (der mit +1 und % 4 wohl trotzdem immer größer 0 sein wird)

    Die Variable heißt: _um1(1=die Ziffer eins)
    GrußRenate 🙂



  • Keine Ahnung was dabei rauskommt du verwendest den falschen & operator auf jeden Fall ist es unschön. Es sollte

    if (_text_nr == 0 && _DeuEng == 0) 
        { _um1 = 0;}
    

    sein.
    Kurt



  • Die Endlosschleife:

    do // ---->ENDLOSSCHLEIFE :rage:  :rage:  :rage:  :rage: 
    {
        if (_text_nr == 1)
    _text_nr =0;
    
     else  
     _text_nr = 1;
    
    _text_nr ++;
    _Set_Text();
    _Set_Text();
    
    }
    
    while (_um1 > 0);
    

    Schleife läuft also solange bis _um1 0 oder kleiner wird. Was passiert nun in _Set_Text()?

    _um1=(_um1+1)%4;
    

    So, zu was führt das nun, wenn _um1 beim Eintritt in die Schleife den Wert 1 hat? Richtig:

    do
    -> _Set_Text (_um1 wird 2)
    -> _Set_Text (_um1 wird 3)
    -> Bedingung (3 ist > 0)

    -> _Set_Text (_um1 wird 0)
    -> _Set_Text (_um1 wird 1)
    -> Bedingung (1 ist > 0)

    -> goto do 😉

    ........ die Bedingung wird niemals false sein.



  • ZuK schrieb:

    Keine Ahnung was dabei rauskommt du verwendest den falschen & operator auf jeden Fall ist es unschön. Es sollte

    if (_text_nr == 0 && _DeuEng == 0) 
        { _um1 = 0;}
    

    sein.
    Kurt

    Hallo Kurt 🙂 ,
    ich habe meinen code kräftig überarbeitet und nun ist er "schöner", oder???
    Nur noch 2 Variablen und alles ist weg, was nicht nötig war.
    Die wichtige Stelle ist mit /********************/ gekennzeichnet und hier ist sie nochmal:

    // Declarations added here will be included at the top of the .HPP file

    class __Form1_declspec Form1 : public __Form1_Base
    {
    
        public:
            // add your public instance data here
    
        private:
             WBool _Set_Text(void); // add your private instance data here
             WInt _text_nr;
             WInt _um1;
    
        protected:
            // add your protected instance data here
    
    };
    
    // Code added here will be included at the top of the .CPP file
     WBool Form1::_Set_Text(void)
     {
    
        _um1=(_um1+1)%4;
    
      switch (_um1)
        {
         case 0:
               label_1->SetText( "1 Text Position" );
               label_2->SetText( " " );
               label_3->SetText( " " );
               label_4->SetText( " " );
           break;
           case 1:
    
                label_1->SetText( "" );
                label_2->SetText( "2 Text Position " );
                label_3->SetText( "" );
                label_4->SetText( " " );
    
           break;
          case 2:
    
               label_1->SetText( "" );
               label_2->SetText( "" );
               label_3->SetText( "  3 Text Position " );
               label_4->SetText( "  " );
    
          break;
           case 3:
    
                label_1->SetText( " " );
                label_2->SetText( " " );
                label_3->SetText( " " );
                label_4->SetText( "4 Text Position " );
    
          break; 
    
        }
      return FALSE;
       }
    
    //  Include definitions for resources.
    #include "WRes.h"
    
    Form1::Form1()
    {
     _text_nr = 0;
    
    }
    
    Form1::~Form1()
    {
    
    }
    
    WBool Form1::menu_1_ErstePosition_Click(
        WObject *           source,
        WEventData *        event )
    {
               label_1->SetText( "1 Text Position " );
               label_2->SetText( " " );
               label_3->SetText( " " );
               label_4->SetText( " " );
                 if (_text_nr == 0 ) 
    { _um1 = 0;}
        return FALSE;
    }
    
    WBool Form1::menu_1_ZweitePosition_Click(
        WObject *           source,
        WEventData *        event )
    {
                label_1->SetText( " " );
                label_2->SetText( "2 Text Position " );
                label_3->SetText( " " );
                label_4->SetText( " " );
            if (_text_nr == 0  ) 
    { _um1 = 1;}
        return FALSE;
    }
    
    WBool Form1::menu_1_DrittePosition_Click(
        WObject *           source,
        WEventData *        event )
    {
                label_1->SetText( " " );
                label_2->SetText( " " );
                label_3->SetText( " 3 Text Position" );
                label_4->SetText( " " );
            if (_text_nr == 0 )  
    { _um1 = 2;}
        return FALSE;
    }
    
    WBool Form1::menu_1_ViertePosition_Click(
        WObject *           source,
        WEventData *        event )
    {
                label_1->SetText( " " );
                label_2->SetText( " " );
                label_3->SetText( " " );
                label_4->SetText( " 4 Text Position" ); 
            if (_text_nr == 0 ) 
                 {_um1 = 3; }
        return FALSE;
    }
    /* ************************************ */
    
    WBool Form1::menu_1_Start_Click(
        WObject *           source,
        WEventData *        event )
    {
    
    if (_text_nr == 1)
        _text_nr =0;
        _Set_Text();
    return FALSE;
    
    }
    /* *********************************  */
    
    WBool Form1::cb_1_Click(
        WObject *           source,
        WEventData *        event )
    {
    
     if (_text_nr == 1)
         _text_nr = 0;
         _Set_Text();
    
     return FALSE;
    }
    


  • LordJaxom schrieb:

    Die Endlosschleife:

    do // ---->ENDLOSSCHLEIFE :rage:  :rage:  :rage:  :rage: 
    {
        if (_text_nr == 1)
    _text_nr =0;
    
     else  
     _text_nr = 1;
    
    _text_nr ++;
    _Set_Text();
    _Set_Text();
    
    }
    
    while (_um1 > 0);
    

    Schleife läuft also solange bis _um1 0 oder kleiner wird. Was passiert nun in _Set_Text()?

    _um1=(_um1+1)%4;
    

    So, zu was führt das nun, wenn _um1 beim Eintritt in die Schleife den Wert 1 hat? Richtig:

    do
    -> _Set_Text (_um1 wird 2)
    -> _Set_Text (_um1 wird 3)
    -> Bedingung (3 ist > 0)

    -> _Set_Text (_um1 wird 0)
    -> _Set_Text (_um1 wird 1)
    -> Bedingung (1 ist > 0)

    -> goto do 😉

    ........ die Bedingung wird niemals false sein.

    /* ************************************ */

    WBool Form1::menu_1_Start_Click(
    WObject * source,
    WEventData * event )
    {

    if (_text_nr == 1)
    _text_nr =0;
    _Set_Text();
    return FALSE;

    }
    /* ********************************* */

    LordJaxom schrieb:

    Die Endlosschleife:

    do // ---->ENDLOSSCHLEIFE :rage:  :rage:  :rage:  :rage: 
    {
        if (_text_nr == 1)
    _text_nr =0;
    
     else  
     _text_nr = 1;
    
    _text_nr ++;
    _Set_Text();
    _Set_Text();
    
    }
    
    while (_um1 > 0);
    

    Schleife läuft also solange bis _um1 0 oder kleiner wird. Was passiert nun in _Set_Text()?

    _um1=(_um1+1)%4;
    

    So, zu was führt das nun, wenn _um1 beim Eintritt in die Schleife den Wert 1 hat? Richtig:

    do
    -> _Set_Text (_um1 wird 2)
    -> _Set_Text (_um1 wird 3)
    -> Bedingung (3 ist > 0)

    -> _Set_Text (_um1 wird 0)
    -> _Set_Text (_um1 wird 1)
    -> Bedingung (1 ist > 0)

    -> goto do 😉

    ........ die Bedingung wird niemals false sein.

    Hallo ,
    ich habe meinen code kräftig überarbeitet und nun ist er "schöner", oder???
    Nur noch 2 Variablen und alles ist weg, was nicht nötig war.
    Die wichtige Stelle ist mit /********************/ gekennzeichnet und hier ist sie nochmal:

    // Declarations added here will be included at the top of the .HPP file

    class __Form1_declspec Form1 : public __Form1_Base
    {
    
        public:
            // add your public instance data here
    
        private:
             WBool _Set_Text(void); // add your private instance data here
             WInt _text_nr;
             WInt _um1;
    
        protected:
            // add your protected instance data here
    
    };
    
    // Code added here will be included at the top of the .CPP file
     WBool Form1::_Set_Text(void)
     {
    
        _um1=(_um1+1)%4;
    
      switch (_um1)
        {
         case 0:
               label_1->SetText( "1 Text Position" );
               label_2->SetText( " " );
               label_3->SetText( " " );
               label_4->SetText( " " );
           break;
           case 1:
    
                label_1->SetText( "" );
                label_2->SetText( "2 Text Position " );
                label_3->SetText( "" );
                label_4->SetText( " " );
    
           break;
          case 2:
    
               label_1->SetText( "" );
               label_2->SetText( "" );
               label_3->SetText( "  3 Text Position " );
               label_4->SetText( "  " );
    
          break;
           case 3:
    
                label_1->SetText( " " );
                label_2->SetText( " " );
                label_3->SetText( " " );
                label_4->SetText( "4 Text Position " );
    
          break; 
    
        }
      return FALSE;
       }
    
    //  Include definitions for resources.
    #include "WRes.h"
    
    Form1::Form1()
    {
     _text_nr = 0;
    
    }
    
    Form1::~Form1()
    {
    
    }
    
    WBool Form1::menu_1_ErstePosition_Click(
        WObject *           source,
        WEventData *        event )
    {
               label_1->SetText( "1 Text Position " );
               label_2->SetText( " " );
               label_3->SetText( " " );
               label_4->SetText( " " );
                 if (_text_nr == 0 ) 
    { _um1 = 0;}
        return FALSE;
    }
    
    WBool Form1::menu_1_ZweitePosition_Click(
        WObject *           source,
        WEventData *        event )
    {
                label_1->SetText( " " );
                label_2->SetText( "2 Text Position " );
                label_3->SetText( " " );
                label_4->SetText( " " );
            if (_text_nr == 0  ) 
    { _um1 = 1;}
        return FALSE;
    }
    
    WBool Form1::menu_1_DrittePosition_Click(
        WObject *           source,
        WEventData *        event )
    {
                label_1->SetText( " " );
                label_2->SetText( " " );
                label_3->SetText( " 3 Text Position" );
                label_4->SetText( " " );
            if (_text_nr == 0 )  
    { _um1 = 2;}
        return FALSE;
    }
    
    WBool Form1::menu_1_ViertePosition_Click(
        WObject *           source,
        WEventData *        event )
    {
                label_1->SetText( " " );
                label_2->SetText( " " );
                label_3->SetText( " " );
                label_4->SetText( " 4 Text Position" ); 
            if (_text_nr == 0 ) 
                 {_um1 = 3; }
        return FALSE;
    }
    /* ************************************ */
    
    WBool Form1::menu_1_Start_Click(
        WObject *           source,
        WEventData *        event )
    {
    
    if (_text_nr == 1)
        _text_nr =0;
        _Set_Text();
    return FALSE;
    
    }
    /* *********************************  */
    
    WBool Form1::cb_1_Click(
        WObject *           source,
        WEventData *        event )
    {
    
     if (_text_nr == 1)
         _text_nr = 0;
         _Set_Text();
    
     return FALSE;
    }
    

Anmelden zum Antworten