If in if



  • ich habe ne schöne if an weisung:

    CRegKey regKey1;
            HKEY hKey1 = HKEY_CURRENT_USER;
            LPCTSTR subKey1 = _T("Software\\DIR1");
            LONG error1;
            char dummy1[MAX_PATH];
            DWORD dwSize1 = MAX_PATH;
            regKey1.Open( hKey1, subKey1);
            error1 = regKey1.QueryValue( dummy1, _T("start"), &dwSize1);
    
            if (error1 == ERROR_FILE_NOT_FOUND)
            {
    
            }
            else
            {
            HKEY hKey;
            RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\DIR1", 0, NULL, REG_OPTION_NON_VOLATILE,
            KEY_ALL_ACCESS | KEY_WRITE, NULL, &hKey, NULL);
            char gamedir[200];
            unsigned long WertTyp;
            unsigned long nMaxLenge = 200;
            RegQueryValueEx(hKey, "gamedir", 0, &WertTyp, (unsigned char*)gamedir, &nMaxLenge);
            RegCloseKey(hKey);
            GetDlgItem(IDC_EDIT_DIR)->SetWindowText(gamedir);
    
            HKEY hKey1;
            RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\DIR1",0,NULL,REG_OPTION_NON_VOLATILE,
            KEY_ALL_ACCESS | KEY_WRITE,NULL,&hKey1,NULL);
            char parameter[200];
            unsigned long WertTyp1;
            unsigned long nMaxLenge1 = 200;
            RegQueryValueEx(hKey1, "para", 0, &WertTyp1, (unsigned char*)parameter, &nMaxLenge1);
            RegCloseKey(hKey1);
            GetDlgItem(IDC_EDIT_PARA)->SetWindowText(parameter);
            }
    

    Jetzt möchte ich aber folgen den code als if verwenden:

    CRegKey regKey;
            HKEY hKey = HKEY_CURRENT_USER;
            LPCTSTR subKey = _T("Software\\dir1");
            LONG error;
            char dummy[MAX_PATH];
            DWORD dwSize = MAX_PATH;
            regKey.Open( hKey, subKey);
            error = regKey.QueryValue( dummy, _T("InstallPath"), &dwSize);
    
            if( error == ERROR_FILE_NOT_FOUND)
            {
            HKEY hKey1;
            RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Dir3", 0, NULL, REG_OPTION_NON_VOLATILE,
            KEY_ALL_ACCESS | KEY_WRITE, NULL, &hKey1, NULL);
            char auslesen[200];
            unsigned long WertTyp;
            unsigned long nMaxLenge = 200;
            RegQueryValueEx(hKey1, "InstallPath", 0, &WertTyp, (unsigned char*)auslesen, &nMaxLenge);
            RegCloseKey(hKey1);
            }
            else
            {
            HKEY hKey;
            RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\DIR1", 0, NULL, REG_OPTION_NON_VOLATILE,
            KEY_ALL_ACCESS | KEY_WRITE, NULL, &hKey, NULL);
            char auslesen[200];
            unsigned long WertTyp;
            unsigned long nMaxLenge = 200;
            RegQueryValueEx(hKey, "InstallPath", 0, &WertTyp, (unsigned char*)auslesen, &nMaxLenge);
            RegCloseKey(hKey);
    

    zusammen:

    CRegKey regKey1;
            HKEY hKey1 = HKEY_CURRENT_USER;
            LPCTSTR subKey1 = _T("Software\\DIR1");
            LONG error1;
            char dummy1[MAX_PATH];
            DWORD dwSize1 = MAX_PATH;
            regKey1.Open( hKey1, subKey1);
            error1 = regKey1.QueryValue( dummy1, _T("start"), &dwSize1);
    
            if (error1 == ERROR_FILE_NOT_FOUND)
            {
             CRegKey regKey;
            HKEY hKey = HKEY_CURRENT_USER;
            LPCTSTR subKey = _T("Software\\dir1");
            LONG error;
            char dummy[MAX_PATH];
            DWORD dwSize = MAX_PATH;
            regKey.Open( hKey, subKey);
            error = regKey.QueryValue( dummy, _T("InstallPath"), &dwSize);
    
            if( error == ERROR_FILE_NOT_FOUND)
            {
            HKEY hKey1;
            RegCreateKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Dir3", 0, NULL, REG_OPTION_NON_VOLATILE,
            KEY_ALL_ACCESS | KEY_WRITE, NULL, &hKey1, NULL);
            char auslesen[200];
            unsigned long WertTyp;
            unsigned long nMaxLenge = 200;
            RegQueryValueEx(hKey1, "InstallPath", 0, &WertTyp, (unsigned char*)auslesen, &nMaxLenge);
            RegCloseKey(hKey1);
            }
            else
            {
            HKEY hKey;
            RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\DIR1", 0, NULL, REG_OPTION_NON_VOLATILE,
            KEY_ALL_ACCESS | KEY_WRITE, NULL, &hKey, NULL);
            char auslesen[200];
            unsigned long WertTyp;
            unsigned long nMaxLenge = 200;
            RegQueryValueEx(hKey, "InstallPath", 0, &WertTyp, (unsigned char*)auslesen, &nMaxLenge);
            RegCloseKey(hKey);
            }
            else
            {
            HKEY hKey;
            RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\DIR1", 0, NULL, REG_OPTION_NON_VOLATILE,
            KEY_ALL_ACCESS | KEY_WRITE, NULL, &hKey, NULL);
            char gamedir[200];
            unsigned long WertTyp;
            unsigned long nMaxLenge = 200;
            RegQueryValueEx(hKey, "gamedir", 0, &WertTyp, (unsigned char*)gamedir, &nMaxLenge);
            RegCloseKey(hKey);
            GetDlgItem(IDC_EDIT_DIR)->SetWindowText(gamedir);
    
            HKEY hKey1;
            RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\DIR1",0,NULL,REG_OPTION_NON_VOLATILE,
            KEY_ALL_ACCESS | KEY_WRITE,NULL,&hKey1,NULL);
            char parameter[200];
            unsigned long WertTyp1;
            unsigned long nMaxLenge1 = 200;
            RegQueryValueEx(hKey1, "para", 0, &WertTyp1, (unsigned char*)parameter, &nMaxLenge1);
            RegCloseKey(hKey1);
            GetDlgItem(IDC_EDIT_PARA)->SetWindowText(parameter);
            }  
    }
    

    so bekomme ich einen fehler :Ungueltiges 'else' ohne zugehoeriges 'if'



  • if(error == FILE...)
    {}
    else
    {}
    if(error1 == FILE...)
    {}
    else
    {}
    

    Devil



  • error1 is aber das "Haubt" if.Kannst du mir mal sagen wi in etwa der fehler im code liegt



  • schreib mal vor das zweite else ein {

    also so

    { else



  • ich mach das immer mit zählen wenn ich auf anhieb nicht draufkomme

    4 mal { aber nur 3 mal }



  • so ?

    if (error1 == ERROR_FILE_NOT_FOUND)
            {
    
            if( error == ERROR_FILE_NOT_FOUND)
            {
            //Code
            }
            else
            {
             //Code
            }
    }
            else
            {
                     //Code
            }
    
    }
    


  • Bei solchen Sachen hilft einrücken.

    if (error1 == ERROR_FILE_NOT_FOUND)
            {
    
                if( error == ERROR_FILE_NOT_FOUND)
                {
                //Code
                }
                else
                {
                //Code
                }
            }
            else
            {
                     //Code
            }
    

    [ Dieser Beitrag wurde am 19.09.2002 um 17:33 Uhr von Tobiking editiert. ]


Log in to reply