Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Removing else in this statements How?

Removing else in this statements How?

Scheduled Pinned Locked Moved C / C++ / MFC
questionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    monsieur_jj
    wrote on last edited by
    #1

    Hi all, I had my code reviewed and I had a comment that its best to remove the else in this statements:

    LRESULT CMainDlg::OnInstall(WORD, WORD wID, HWND, BOOL& )
    {
    string LaunchInstaller;
    string InstallFolder;
    InstallClass installclass;

    TCHAR tcItemText\[MAXBYTES\];
    
    if(UpdateList.GetItemText(Select, tcItemText, MAXBYTES))
    {
    InstallFolder = tcItemText;
    LaunchInstaller = installclass.ConstructInstallerKey(IDS\_MANAGEKEY, InstallFolder);
    	if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
    	{
    		return 0;
    	}
    	else 
    	{
    		LaunchInstaller = installclass.ConstructInstallerKey(IDS\_RERITEKEY, InstallFolder);
    		if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
    		{
    			return 0;
    		}
    		else
    		{
    			LaunchInstaller = installclass.ConstructInstallerKey(IDS\_RERITEASIANKEY, InstallFolder);
    			if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
    			{
    				return 0;
    			}
    			else
    			{
    			LaunchInstaller = installclass.ConstructInstallerKey(IDS\_RERITECHINAKEY, InstallFolder);
    				if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
    				{
    					return 0;
    				}
    			}
    		}
    	}
    }
    else
    {
    MessageBox ( \_T("Please choose an item to install"), \_T("Redmap Update Manager"), MB\_ICONWARNING );
    }
    return 0;
    

    }

    Any suggestions on how the code should look like? Thanks, Jayjay

    D 1 Reply Last reply
    0
    • M monsieur_jj

      Hi all, I had my code reviewed and I had a comment that its best to remove the else in this statements:

      LRESULT CMainDlg::OnInstall(WORD, WORD wID, HWND, BOOL& )
      {
      string LaunchInstaller;
      string InstallFolder;
      InstallClass installclass;

      TCHAR tcItemText\[MAXBYTES\];
      
      if(UpdateList.GetItemText(Select, tcItemText, MAXBYTES))
      {
      InstallFolder = tcItemText;
      LaunchInstaller = installclass.ConstructInstallerKey(IDS\_MANAGEKEY, InstallFolder);
      	if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
      	{
      		return 0;
      	}
      	else 
      	{
      		LaunchInstaller = installclass.ConstructInstallerKey(IDS\_RERITEKEY, InstallFolder);
      		if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
      		{
      			return 0;
      		}
      		else
      		{
      			LaunchInstaller = installclass.ConstructInstallerKey(IDS\_RERITEASIANKEY, InstallFolder);
      			if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
      			{
      				return 0;
      			}
      			else
      			{
      			LaunchInstaller = installclass.ConstructInstallerKey(IDS\_RERITECHINAKEY, InstallFolder);
      				if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
      				{
      					return 0;
      				}
      			}
      		}
      	}
      }
      else
      {
      MessageBox ( \_T("Please choose an item to install"), \_T("Redmap Update Manager"), MB\_ICONWARNING );
      }
      return 0;
      

      }

      Any suggestions on how the code should look like? Thanks, Jayjay

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      LRESULT CMainDlg::OnInstall(WORD, WORD wID, HWND, BOOL& )
      {
      string LaunchInstaller;
      string InstallFolder;
      InstallClass installclass;
      TCHAR tcItemText[MAXBYTES];

      if(UpdateList.GetItemText(Select, tcItemText, MAXBYTES))
      {
          InstallFolder = tcItemText;
      
          LaunchInstaller = installclass.ConstructInstallerKey(IDS\_MANAGEKEY, InstallFolder);
          if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
              return 0;
      
          LaunchInstaller = installclass.ConstructInstallerKey(IDS\_RERITEKEY, InstallFolder);
          if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
              return 0;
      
          LaunchInstaller = installclass.ConstructInstallerKey(IDS\_RERITEASIANKEY, InstallFolder);
          if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
              return 0;
      
          LaunchInstaller = installclass.ConstructInstallerKey(IDS\_RERITECHINAKEY, InstallFolder);
          if (installclass.InstallUpdate(LaunchInstaller.c\_str())) 
              return 0;
      }
      else
      {
          MessageBox(\_T("Please choose an item to install"), \_T("Redmap Update Manager"), MB\_ICONWARNING);
      }
      
      return 0;
      

      }

      "Love people and use things, not love things and use people." - Unknown

      "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups